Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4468

DenyAnonymousAuthorizationRequirement Error in Blazor WASM

$
0
0

I am working on a Blazor WebAssembly hosted app that use JWT authentication / authorization. When I run the project and try to register or login, I get the following information log indicating that the user is denied access because it is not authenticated:

Log message

How should I managed this error?

// ConfigureServices        services.AddIdentity<IdentityUser, IdentityRole>()            .AddEntityFrameworkStores<ApplicationDbContext>()            .AddDefaultTokenProviders();        services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)            .AddJwtBearer(options =>            options.TokenValidationParameters = new TokenValidationParameters            {                ValidateIssuer = false,                ValidateAudience = false,                ValidateLifetime = true,                ValidateIssuerSigningKey = true,                IssuerSigningKey = new SymmetricSecurityKey(                    Encoding.UTF8.GetBytes(Configuration["jwt:key"])),                ClockSkew = TimeSpan.Zero            }); ;

// Configure Method

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)        {            if (env.IsDevelopment())            {                app.UseDeveloperExceptionPage();                app.UseWebAssemblyDebugging();            }            else            {                app.UseExceptionHandler("/Error");                app.UseHsts();            }            app.UseHttpsRedirection();            app.UseBlazorFrameworkFiles();            app.UseStaticFiles();            app.UseRouting();            app.UseAuthentication();            app.UseAuthorization();            app.UseEndpoints(endpoints =>            {                endpoints.MapRazorPages().RequireAuthorization();                endpoints.MapControllers().RequireAuthorization();                endpoints.MapFallbackToFile("index.html");            });        }

Viewing all articles
Browse latest Browse all 4468

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>