asp.net-core - SwaggerUI 中是否支持多个 oauth2 身份验证登录提供程序?
问题描述
我可以让多个登录选项出现在 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>();
和类似的东西
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();
});
如果我只配置了一个 oauth 提供程序,它可以正常工作。问题是 Google 和 Microsoft 登录选项都将使用 UseSwaggerUI 方法中声明的默认 ClientId 和 ClientSecret 等。
有没有办法在 Swagger UI 中支持多个登录提供程序及其相关配置?
解决方案
推荐阅读
- numpy - 如何将多个 numpy 数组组合成一个用于 cython 的 memoryview?
- linux - 从 Docker 采购(“打点”)shell 脚本
- polymer - 聚合物 3“未捕获的参考错误:聚合物未定义”
- c# - 当我尝试制作自定义文本框时,密码字符不起作用
- python - Python将几个数据帧附加到一个内部函数中
- php - PHP Prepared 语句返回错误值
- laravel - 放入 laravel API
- javascript - Vue, how to pass function in props in JSX render?
- excel - Change Range of Numbers to be Negative in VBA
- sql - 为将行拉入列而不进行聚合而编写的查询将列混杂在一起,而不是按顺序列出它们