For many collections in Postman we use authorization with the grant type=Authorization code
(to Azure). For requests using the grant type client credentials
I'm able to write the prerequest script which acquires the token automatically (if needed) and I would like to have such a script for the authorization code
flow too. There are many examples related to basic authorization
(user name/password) flow out there, but I haven't found any for the authorization code flow.
Here are the steps I have to do according the MS docs):
- I call POST method to the https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize with all required parameters, as
redirect_uri
I use https://www.getpostman.com/oauth2/callback - After successful authentication Azure sends the code as url parameter in the callback request to provided
redirect_uri
. In the browser it looks like this https://www.getpostman.com/oauth2/callback/?code=authorizationCodeGeneratedByAzure - To proceed further I would need now to somehow observe the
redirect_uri
, to catch the incoming request (the callback from Azure) and somehow grab the code from the request url parameters for further usage in the following request for the token acquisition. And this is what I can't figure out how to do.
So my question is:
How can I get the authorization_code from the url of Azure authentication response sent to redirect_uri
after the successful authentication in the Prerequest script?