Swashbuckle UI不显示安全方案说明OAuth2

问题描述 投票:0回答:1

我正在尝试将安全方案添加到我的招摇UI页面,并且成功添加了该安全方案,但是,我的描述没有呈现或完全不在UI页面上显示。我希望它能成功显示,因为我会将这段代码切换为IOperationFilter,并且描述因端点而异。但是,现在,这是我的AddSwaggerGen代码:

services.AddSwaggerGen(options =>
        {
            options.SwaggerDoc("v1", new OpenApiInfo
            {
                Title = "MyAPI",
                Version = "v1"
            });

            options.EnableAnnotations(true);
            options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
            {
                Description = "This is my description that's not showing", // I want this to display on the UI
                Type = SecuritySchemeType.OAuth2,
                Flows = new OpenApiOAuthFlows
                {
                    ClientCredentials = new OpenApiOAuthFlow
                    {
                        TokenUrl = new Uri("/token", UriKind.Relative)
                    }
                }
            });

            options.AddSecurityRequirement(new OpenApiSecurityRequirement
            {
                {
                    new OpenApiSecurityScheme
                    {
                        Reference = new OpenApiReference
                        {
                            Type = ReferenceType.SecurityScheme,
                            Id = "Bearer"
                        },
                        Scheme = "oauth2",
                        Name = "Bearer",
                        In = ParameterLocation.Header
                    },
                    new List<string>()
                }
            });
        });

这是我在用户界面中生成的可用授权:enter image description here

我以为我的描述应该像JWT那样去描述范围。我是否缺少配置?我正在使用Swashbuckle.AspNetCore 5.0.0

asp.net-core oauth-2.0 swagger-ui swashbuckle
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.