No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization

前端 未结 5 726
滥情空心
滥情空心 2020-12-05 01:35

I have a .NET Core 2.0 app and have a problem with authorization. I want to use custom authorization with special requests. Header and standard default authentication. First

5条回答
  •  甜味超标
    2020-12-05 02:23

    When I used policy before I set the default authentication scheme into it as well. I had modified the DefaultPolicy so it was slightly different. However the same should work for add policy as well.

    services.AddAuthorization(options =>
            {
                options.AddPolicy(DefaultAuthorizedPolicy, policy =>
                {
                    policy.Requirements.Add(new TokenAuthRequirement());
                    policy.AuthenticationSchemes = new List()
                                    {
                                        CookieAuthenticationDefaults.AuthenticationScheme
                                    }
                });
            });
    

    Do take into consideration that by Default AuthenticationSchemes property uses a read only list. I think it would be better to implement that instead of List as well.

提交回复
热议问题