Blog

Filter posts by Category Or Tag of the Blog section!

JWT token in swagger

Monday, 13 November 2017

In asp.net Core, for authorized APIs you can easily pass the JWT token via PostMan like below: 

But swagger you don't have authentication by installing it, add the following configuration to services to enable the authentication in swagger  as well:

 services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
                options.AddSecurityDefinition("oauth2", new ApiKeyScheme
                {
                    Description = "Standard Authorization header using the Bearer scheme. Example: \"bearer {token}\"",
                    In = "header",
                    Name = "Authorization",
                    Type = "apiKey"
                });
            });

You will see the Authorize button on top right corner:

 

Category: Software

comments powered by Disqus