简体   繁体   English

Swagger - 将更多范围添加到授权按钮

[英]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.

相关问题 如何添加具有多个范围的授权策略? - How to add an authorization policy with multiple scopes? 如何通过jQuery或JavaScript在Gridview的列上添加“更多...”按钮 - how to add 'More…' button on a column of Gridview by jquery or javascript 限制数据列表中的数据行,并在页脚中添加更多加载按钮 - restrict data rows in datalist and add a load more button in the footer 添加更多阅读按钮以查看Gridview描述文本 - Add Read more button to view Gridview Description text 动态添加角色以授权控制器的属性 - Dynamically add roles to authorize attribute for controller 如何保护Swagger API UI仅允许使用ASP.NET Web API的授权用户使用? - How to secure Swagger API UI allow only to a authorize user using ASP.NET Web API? Aspx,C#和Authorize.Net付款表单-如何实施“授权”按钮? - Aspx, C#, and Authorize.Net Payment Form - How to implement Authorize button? 如何根据用户请求(单击添加更多按钮)动态创建相同的输入字段? - How to dynamically create the same input fields upon user request (clicking Add More button)? 向GridView添加更多列 - Add more columns to GridView 向网格视图添加更多行 - Add more rows to a gridview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM