'How to get access token using oauth 2.0 authorization grant type in rest assured
I have an api with oauth2.0 authorization grant type authentication which has the following steps -
- Get method for authorization code which opens up a form in browser where you need to enter credentials. This results in a series of post redirect requests and finally returns a authorization code in third post response header
- Now a post request is sent, with grant type authorization code containing client credentials and the above authorization code we got from the get request, in the body and it returns the access token
This is how it works in postman. How can I achieve the same thing using Rest Assured?
Solution 1:[1]
You need two handlers
Handler 1:
- To redirect to oauth server. (requeter should identity list of grant types, generate url with client_id and state and redirect application to this url)
- Once end user signs in and allows the grant. (assumed that user allows)
Handler 2:
- oauth server redirects back to postman with a authorization_code and state.
- You need to configure redirect to your server callback url.
- Once you receive these two
- Verify state is same as what you sent. if yes proceed.
- send authorization_code, cleint_secret, client_id back to server to recieve access_token and refresh_token
- Use access_token to access data.
- Use refresh_token to get new access_token.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | cedric |