Ehsan Ghanbari

Experience, DotNet, Solutions

JWT token in swagger

In 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:


About Me

Ehsan Ghanbari

Hi! my name is Ehsan. I'm a developer, passionate technologist, and fan of clean code. I'm interested in enterprise and large-scale applications architecture and design patterns and I'm spending a lot of my time on architecture subject. Since 2008, I've been as a developer for companies and organizations and I've been focusing on Microsoft ecosystem all the time. During the&nb Read More

Post Tags
Pending Blog Posts
Strategic design
Factory Pattern
time out pattern in ajax
Selectors in Jquery
Peridic pattern
How to query over Icollection<> of a type with linq
How to use PagedList In MVC
Domain driven design VS model driven architecture
What's the DDD-lite?
Using Generic type for type casting in F#
comments powered by Disqus