SwaggerUI 中是否支持多个 oauth2 身份验证登录提供程序?

Pat*_*lan 6 oauth-2.0 swagger swagger-ui asp.net-core

我可以使用类似于以下的代码在 SwaggerUI 中显示多个登录选项

    services.AddSwaggerGen(c =>
    {
        c.AddSecurityDefinition("Google", new OAuth2Scheme
        {
            Description = "Google",
            Type = "oauth2",
            Flow = "implicit",
            TokenUrl = "https://www.googleapis.com/oauth2/v3/token",
            AuthorizationUrl = "https://accounts.google.com/o/oauth2/auth"
        });

        c.AddSecurityDefinition("Microsoft", new OAuth2Scheme
        {
            Description = "Microsoft",
            Type = "oauth2",
            Flow = "implicit",
            TokenUrl = "blah",
            AuthorizationUrl = "blah"
        });

        c.AddSecurityDefinition("Bearer", new ApiKeyScheme
        {
            Description = "Standard Authorization header using the Bearer scheme. Example: \"bearer {token}\"",
            In = "header",
            Name = "Authorization",
            Type = "apiKey"
        });

        c.OperationFilter<SecurityRequirementsOperationFilter>();
Run Code Online (Sandbox Code Playgroud)

和类似的东西

    app.UseSwaggerUI(c =>
    {
        c.OAuthClientId(this.Configuration["Authentication:Google:ClientId"]);
        c.OAuthClientSecret(this.Configuration["Authentication:Google:ClientSecret"]);
        c.OAuthAppName("blah");
        c.OAuthScopeSeparator(string.Empty);
        c.OAuthAdditionalQueryStringParams(new { audience = this.Configuration["Authentication:Google:ClientId"], scope = "openid profile email" });
        c.OAuthUseBasicAuthenticationWithAccessCodeGrant();
    });
Run Code Online (Sandbox Code Playgroud)

如果我只配置了一个 oauth 提供程序,它就可以正常工作。问题在于,Google 和 Microsoft 登录选项都将使用 UseSwaggerUI 方法中声明的默认 ClientId 和 ClientSecret 等。

有没有办法在 Swagger UI 中支持多个登录提供程序及其相关配置?