相关疑难解决方法(0)

如何设置 Swashbuckle 和 Swagger UI 以使用 Open ID Connect Discovery 进行授权,以便它可以提供正确的承载令牌?

如何设置 Swashbuckle 和 Swagger UI 以使用 Open ID Connect Discovery 进行授权(在我的例子中是 Azure AD)?

到目前为止,这是我的(未完全工作的)SwaggerGen 设置,基于/sf/answers/4630359751/

SwaggerGenOptions c => {
    OpenApiInfo apiInfo = new()  { /* ...snip... */ };
    c.SwaggerDoc("v1", apiInfo);
    IncludeXmlFileForSwagger(c);

    // Defines the Open ID Connect discovery scheme - see also /sf/answers/4630359751/
    OpenApiSecurityScheme mainScheme = new()
    {
        Type = SecuritySchemeType.OpenIdConnect,
        OpenIdConnectUrl = new Uri($"https://login.microsoftonline.com/{myTenantId}/.well-known/openid-configuration"),
    };
    c.AddSecurityDefinition("OpenIdConnect", mainScheme);

    // Adds a reference to the above scheme as required for every API action (we can get more nuanced later) …
Run Code Online (Sandbox Code Playgroud)

c# swagger swagger-ui openid-connect swashbuckle

7
推荐指数
1
解决办法
2842
查看次数

标签 统计

c# ×1

openid-connect ×1

swagger ×1

swagger-ui ×1

swashbuckle ×1