[英]Swagger - Add more scopes to Authorize button
I have an API that uses Swagger.我有一个使用 Swagger 的 API。 Authentication and authorization are done with IdentityServer 4. In the swagger UI, there's an Authorize button.
身份验证和授权使用 IdentityServer 4 完成。在 swagger UI 中,有一个 Authorize 按钮。 If I press it I get this popup:
如果我按下它,我会得到这个弹出窗口:
I can select my scope, press the authorize button, and I'll be redirected to a login screen, which all works.我可以 select 我的 scope,按下授权按钮,我将被重定向到登录屏幕,一切正常。
My problem is that I need more scopes to be added to this list.我的问题是我需要将更多范围添加到此列表中。 Right now there is just one scope available here.
现在这里只有一个 scope 可用。 How can I add another scope to this list?
如何将另一个 scope 添加到此列表中?
If you are using Swashbuckle, at your OpenApiOAuthFlow
object you have to define the Scopes
Dictionary.如果您使用 Swashbuckle,则必须在您的
OpenApiOAuthFlow
object 中定义Scopes
字典。 Should look like this:应该是这样的:
services.AddSwaggerGen(c =>
{
// omitted code
c.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
{
Type = SecuritySchemeType.OAuth2,
Flows = new OpenApiOAuthFlows
{
Implicit = new OpenApiOAuthFlow
{
AuthorizationUrl = new Uri("..."),
TokenUrl = new Uri("..."),
// add your scopes here
Scopes = new Dictionary<string, string>
{
{ "scope1", "Optional friendly description." },
{ "scope2", string.Empty },
{ "scope3", string.Empty }
}
}
}
});
// omitted code
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.