How to display IdentityServer endpoints in SwaggerUI with Swashbucke

688 views Asked by At

I have an ASPNET Core 6 service which uses Duende IdentityServer 6, which includes several endpoints such as /connect/token and /connect/authorize. I need these endpoints to show up in my Swagger UI page, however I cannot find a way to get them to show up.

Here is my 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[] { }
                }
            });
        });

And I am just using the basic app.AddSwagger() and app.AddSwaggerUI()

1

There are 1 answers

0
achill113 On BEST ANSWER

As far as my research has shown, CodingMytra is correct. IdentityServer endpoints must be added manually to the Swagger document.