Spring Boot 3 OAuth2 Client for non reactive project
If not a medium member, try using the link here to view it for free.
IMPORTANT UPDATE DECEMBER 2024 ↬ For projects based on Spring boot 3.4.x or later, it is better to refer the other recent approach that does not need the use of reactive libraries in the code. Link is here.
Spring Boot 2.x.x sometime back had introduced a WebClient based OAuth2 Client & when we say WebClient that is Reactive & that does not work with a servlets based project out of the box in a go, one may get some errors, challenges for sure.
Reason for the error is the underneath framework to call token endpoint to resolve the access token should not be reactive.
So this blog post is dedicated to the very specific problem statement & the solution around the same. The blog post here majorly is code only. With a representational image for explanation.
Flow Diagram
Code
The code makes use of Spring Boot 3 + JDK17
There are mainly 3 components:-