• Skip to main content
  • Skip to footer
  • Home
  • Become An Aficionado (Join Our Mailing List)
BMA

BeMyAficionado

Inspire Affection

Ad example

SWAGGER UI – Enable Token-Based Authentication In Spring Boot

July 17, 2020 by varunshrivastava Leave a Comment

Swagger UI is the first choice of every developer and tester when it comes to documenting service APIs. It provides live documentation for the APIs where you can actually send the request and get the things done.

It really makes it easy for other people to understand your APIs as well.

Whenever you are working on a project that depends on stateless authentication (which is most of the applications) then you need a way to pass the authentication token (JWT or Custom) from your Swagger UI to the backend.

That feature doesn’t come automatically with the Swagger and that is because Swagger does not know how you are configuring your APIs security. You will have to manually enable it from the configuration.

This is how you will find the UI after configuring it –

Enable the UI for passing the Auth Token
Enable Authorize Button on the UI
Pass the auth token from swagger ui to the backend
Pass your Auth Token from the SWAGGER

The code for enabling the security in Swagger is really straight-forward. You need a configuration class (@Configuration). Enable the Swagger (@EnableSwagger2).

Now add the security schemes and security context info to the Docket. Here’s the code for the same.

Let me know your views on the same.

Articles that you would be interested in,

  • How To Mock SecurityContextHolder in Spring Security using Mockito?
  • Load Spring Beans Based On Different Profiles Via XML
  • How to Fix A Blunder and Get Squashed Commits Back (Git Undo)
  • Time Complexity Comparison Sheet Of Elementary Sorting Algorithms
  • Gitlab CI – SSH Into Virtual Private Server (VPS) Using Private Key From Gitlab CI Pipeline Job

Read more on programming here…

Related

Filed Under: Programming Tagged With: configuration, enable ui, security scheme, spring boot, swagger-ui, token=based authentication

Footer

Become an Aficionado

BeMyAficionado is all about helping you connect, grow, and make an impact—one idea at a time.

Join our mailing list for exclusive how-to guides, insider stories, and free e-books.

Get first access to new posts, tools and resources we only share with subscribers.

Join 874 other subscribers

Recent

  • Is The Cosmos a Vast Computation?
  • Building Semantic Search for E-commerce Using Product Embeddings and OpenSearch
  • Leader Election with ZooKeeper: Simplifying Distributed Systems Management
  • AWS Serverless Event Driven Data Ingestion from Multiple and Diverse Sources
  • A Step-by-Step Guide to Deploy a Static Website with CloudFront and S3 Using CDK Behind A Custom Domain

Search

Tags

Affordable Hosting algorithms amazon aoc-2020 believe in yourself best database earn money blogging education elementary sorting algorithms experience fashion finance Financial Freedom food friends goals google india indian cuisine indian education system java life life changing love make money microservices motivation oops podcast poor education system principles of microservices problem-solving programmer programming python reality seo spring success success factor technology top 5 typescript wordpress

Copyright © 2025 · Be My Aficionado · Log in

Go to mobile version