【问题标题】:How to add authorization (Authorize button) in swagger for ocelot如何在 swagger 中为 ocelot 添加授权(授权按钮)
【发布时间】:2021-08-21 13:29:29
【问题描述】:

当我有 ocelot api 网关时,如何在 swagger 中添加授权按钮?

我这样配置我的服务集合:

s.AddSwaggerForOcelot(configuration);

s.AddSwaggerGen(c =>
{
    c.SwaggerDoc("v1", new OpenApiInfo { Title = "ApiGateway" });

    c.AddSecurityDefinition("Bearer",
        new OpenApiSecurityScheme
        {
            In = ParameterLocation.Header,
            Description = "Please enter into field the word 'Bearer' following by space and JWT",
            Name = "Authorization",
            Type = SecuritySchemeType.ApiKey
        });

    c.AddSecurityRequirement(new OpenApiSecurityRequirement
    {
        {
            new OpenApiSecurityScheme
            {
                Reference = new OpenApiReference
                {
                    Type = ReferenceType.SecurityScheme,
                    Id = "Bearer"
                }
            },
            new string[] { }
        }
    });
    c.ExampleFilters();
});

但这没有意义..

【问题讨论】:

    标签: .net-core swagger openapi swashbuckle.aspnetcore ocelot


    【解决方案1】:

    您必须在 Ocelot API Gateway 的所有下游 API 中添加此配置。

    因此,securitySchemessecurity JSON 对象将包含在每个下游 API 开放 API 规范中。

    【讨论】:

      猜你喜欢
      • 2015-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 2019-11-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多