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<string>()
{
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.