首页 > 解决方案 > Authorization not working, It does not forbidden users to access my actions in asp.net core

问题描述

In start up

ConfigureServices function I add this

         services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
   .AddJwtBearer(jwtBearerOptions =>
   {
       jwtBearerOptions.TokenValidationParameters = new TokenValidationParameters()
       {
           ValidateIssuerSigningKey = true,

           ValidateIssuer = false,
           ValidateAudience = false
       };
   });

then in Configure function I added this

  app.UseAuthentication();

            app.UseAuthorization();

and I added this line to my API

[Authorize]

but it give user to allow that function, what is my mistake? which part of auth I forget to add my code?

标签: asp.net-coreasp.net-core-2.0jwt-auth

解决方案


推荐阅读