Reputation: 343
I noticed when I tried to create a custom policy provider for an API (documentation here), the SwaggerUI breaks, but it's fine if I add a policy directly into services configuration.
The API is still functional because I can successfully make calls to my API endpoints, but can anyone explain why the Swagger tool would no longer display? I get a 401 error when the browser tries to open the localhost:[port]/index.html page.
Upvotes: 2
Views: 398
Reputation: 343
Because my setup has multiple policies, when the Swagger UI extension attempted to run, it utilized the GetFallbackPolicyAsync() method in my implementation of IAuthorizationPolicyProvider, which according to the documentation is called when there are combined policies. While I am explicitly specifying authentication levels on each of the controller methods separately, it appears the Swagger UI is using the fallback policy to determine whether I have access, and since my policies are restricted to authentication, which isn't being passed upon startup, I had to set the fallback policy to null:
public Task<AuthorizationPolicy> GetFallbackPolicyAsync()
{
return Task.FromResult<AuthorizationPolicy>(null);
}
Upvotes: 3