Spring Boot OAuth2 Part 2 - Fetching and using the Access Token
In this tutorial we will see how to use the authorization code to get the access token and then get the json data using the access token. We had in the previous tutorial done the following -
- The Resource Owner will ask the Client Application to get some data from the Resource Server.
- The Resource Server asks the Resource Owner to authenticate itself and as for authorization to share data.
- After successful authentication the Resource Server shares an authorization code with the client application
- The Client Application using the Authorization code and Secret key ask for the Access Token from the Resource Server.
- The Resource Server shares the Access Token with the Client Application.
- Using the shared Access Token the Client Application can now get the required JSON data from the Resource Server
Spring Boot Security - Implementing OAuth2
Spring Boot Security - Introduction to OAuth Spring Boot OAuth2 Part 1 - Getting The Authorization Code Spring Boot OAuth2 Part 2 - Getting The Access Token And Using it to fetch data. Spring Boot + OAuth 2 Client Credentials Grant - Hello World Example. Spring Boot + OAuth 2 Password Grant - Hello World Example. Facebook Authentication Using Spring Boot + Spring Social Simple Example.
Video
This tutorial is explained in the below Youtube Video.Lets Begin?
Getting the Access Token
For getting the access token from the resource server the changes are only required at the client application end.
In a previous tutorial we had implemented code to get the Authorization code from the Resource Server.
Using the Authorization Code received from the resource server we can get the access token.
As can be seen the authorization code is received as a request parameter. And the resource server is trying to contact the client application using the redirect uri. So we will write a controller to get the Authorization code as a request parameter. Then using this authorization code we get the Access Token.