admin管理员组

文章数量:1406937

I have a Web API that produces two Swashbuckle (Swagger) documents, say Doc A and Doc B.
I want to use different scopes on each doc, like:

  • Doc A - scopeA
  • Doc B - scopeA, scopeB

Here is my code:

services.AddSwaggerGen(c =>
{
    var authorizationCode = new OpenApiOAuthFlow
    {
        AuthorizationUrl = new Uri("abc"),
        TokenUrl = new Uri("xyz"),

        // swaggerSettings.Scopes is Dictionary<string, string>, containing "scope-description" pairs
        Scopes = swaggerSettings.Scopes
    };

    c.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
    {
        Type = SecuritySchemeType.OAuth2,
        Flows = new OpenApiOAuthFlows { AuthorizationCode = authorizationCode }
    });
})

...

app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/swagger/swagger.json", "Doc A");
});

app.UseSwaggerUI(c =>
{
    c.RoutePrefix = "swagger/anotherDoc";
    c.SwaggerEndpoint("/swagger/another/swagger.json", "Doc B");
});

The specified scopes (, or SecurityDefinition) above are used by both docs and I don't see how I can specify different scopes for each doc.

Is there a way to do it?

本文标签: swashbuckleaspnetcoreChange authorization scopes on each Swashbuckle (swagger) pagesStack Overflow