简体   繁体   中英

How to add authorization (Authorize button) in swagger for ocelot

How can I add Authorize button in swagger, when I have ocelot api gateway?

在此处输入图像描述

I configure my service collection like that:

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();
});

but it doesn't make sense..

You have to add this configuration in all the downstream APIs of your Ocelot API Gateway.

Thus, the securitySchemes and security JSON objects will be included to each downstream API Open API Specification.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM