如何使用Swashbucke在SwaggerUI中显示IdentityServer端点

pu3pd22g  于 2022-12-23  发布在  其他
关注(0)|答案(1)|浏览(140)

我有一个使用Duende IdentityServer 6的ASPNET Core 6服务,它包括几个端点,如/connect/token和/connect/authorize。我需要这些端点显示在我的Swagger UI页面中,但我找不到让它们显示的方法。
这是我的AddSwaggerGen

builder.Services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" });

            c.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
            {
                Type = SecuritySchemeType.OAuth2,
                Flows = new OpenApiOAuthFlows
                {
                    ClientCredentials = new OpenApiOAuthFlow
                    {
                        AuthorizationUrl =
                            new Uri($"{builder.Configuration.GetSection("BaseUri").Value}connect/authorize",
                                UriKind.RelativeOrAbsolute),
                        TokenUrl = new Uri($"{builder.Configuration.GetSection("BaseUri").Value}connect/token",
                            UriKind.RelativeOrAbsolute),
                        Scopes = new Dictionary<string, string>
                        {
                            { Constants.Api.ScopeName, "Base level access to API" }
                        }
                    }
                }
            });

            c.AddSecurityRequirement(new OpenApiSecurityRequirement
            {
                {
                    new OpenApiSecurityScheme
                    {
                        Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "oauth2" },
                        In = ParameterLocation.Cookie
                    },
                    new string[] { }
                }
            });
        });

我只是使用基本的app.AddSwagger()app.AddSwaggerUI()

jhdbpxl9

jhdbpxl91#

据我的研究表明,CodingMytra是正确的。必须手动将IdentityServer端点添加到Swagger文档中。

相关问题