【问题标题】:How to display IdentityServer endpoints in SwaggerUI with Swashbucke如何使用 Swashbuckle 在 Swagger UI 中显示身份服务器端点
【发布时间】:2022-12-21 05:24:12
【问题描述】:

我有一个使用 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()

【问题讨论】:

  • 您已将它们明确添加到您的 swagger 文档中。请参阅此 article 以添加其他端点。

标签: swagger swashbuckle swashbuckle.aspnetcore duende-identity-server duende


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-01
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多