ASP.NET Core 2.0 disable automatic challenge

前端 未结 8 913
萌比男神i
萌比男神i 2020-11-28 13:40

After upgrading my ASP.NET Core project to 2.0, attempts to access protected endpoints no longer returns 401, but redirects to an (non-existing) endpoint in an attempt to le

8条回答
  •  不知归路
    2020-11-28 14:15

    After some research, I found we can deal with this problem though the bellow approach:

    We can add two Authentication scheme both Identity and JWT; and use Identity scheme for authentication and use JWT schema for challenge, JWT will not redirect to any login route while challenge.

    services.AddIdentity().AddEntityFrameworkStores();
    
    services.AddAuthentication((cfg =>
    {
        cfg.DefaultScheme = IdentityConstants.ApplicationScheme;
        cfg.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
    })).AddJwtBearer();
    

提交回复
热议问题