1

I have a REST API service provider, written in PHP. I tested it successfully in Postman, and it works properly there.

Now I am going to prepare API documentation for it, and I am using Swagger UI 3. I set it up properly and I can process Authorization with the top Authorize button.

After a successful login, I expect the respective Bearer token being set and used by the endpoints. But this is not gonna happen, when I try any endpoint, the REST server complains about lack of Authorization Header. I tested the network traffic, and there is no token along with the HTTP request.

My question is, how can I send the Bearer token in the header in Swagger UI, after successfully login using the Authorize button on the top? Is there any steps/process I should take to accompany the endpoint request with the token?

Belkin
  • 199
  • 15

1 Answers1

-1

I used it in a .NET core project, and in the Startup file I had to put the following code part:

services.AddSwaggerGen(options =>
        {

            //authentication
            var security = new Dictionary<string, IEnumerable<string>>
            {
                {"Bearer", new string[] { }},
            };
            options.AddSecurityDefinition("Bearer", new ApiKeyScheme
            {
                In = "Header",
                Description = "Please insert JWT into field",
                Name = "Authorization",
                Type = "apiKey"
            });

            options.AddSecurityRequirement(security);
}
milanbalazs
  • 4,811
  • 4
  • 23
  • 45
Oksana King
  • 94
  • 1
  • 1
  • 8