• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • About
  • Subscribe BMA
  • Contact Us!

Be My Aficionado

Inspire Affection

You are here: Home / Programming / SWAGGER UI – Enable Token-Based Authentication In Spring Boot

SWAGGER UI – Enable Token-Based Authentication In Spring Boot2 min read

July 17, 2020 by Varun Shrivastava 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…

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • More
  • Click to print (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to share on Pocket (Opens in new window)
  • Click to share on Telegram (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)
  • Click to share on Skype (Opens in new window)
  • Click to email this to a friend (Opens in new window)

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

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Featured Posts

11 (Must Have) Ingredients that Can Turn You Into a Social Media Magnet in Freakishly Less Time

May 26, 2018 By Varun Shrivastava 7 Comments

Social Media Traffic is Dangerous for your Website Page Rank

April 17, 2017 By Varun Shrivastava 8 Comments

3 Best Laptops (Mid-Range) For Every Use Case In India

February 16, 2021 By Varun Shrivastava 1 Comment

Best 5 Useful Advice Every New Blogger must Implement

September 6, 2017 By Varun Shrivastava 1 Comment

iTerm2 – Colorize The Tailed Logs In ITerm2 Terminal

August 21, 2020 By Varun Shrivastava Leave a Comment

Latest Posts

  • How To Become Financially Independent In India?
  • Trie Data Structure Implementation | (PUT, GET, DELETE)
  • 5 THINGS I WISH I KNEW When I Started Programming
  • 3 Best Laptops (Mid-Range) For Every Use Case In India
  • Distributed System Architectural Patterns

Categories

  • Blogging (104)
  • Cooking (11)
  • Fashion (7)
  • Finance & Money (13)
  • Programming (53)
  • Reviews (4)
  • Technology (22)
  • Travelling (4)
  • Tutorials (12)
  • Web Hosting (8)
  • Wordpress N SEO (18)

Follow us on facebook

Follow us on facebook

Grab the Deal Now!

Hostgator Starting @$3.95/mo

DigitalOcean Free Credits

Trending

Affordable Hosting amazon aoc-2020 bad luck believe in yourself best database earn money blogging education experience fashion finance Financial Freedom food friends goals google india indian cuisine indian education system java javascript life life changing love make money microservices motivation oops poor education system principles of microservices problem-solving programmer programming reality seo SSD Hosting success technology tips top 5 VPS web web developer wordpress

Footer

Copyright © 2021 · BeMyAficionado by Varun Shrivastava · WordPress

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.