Values from console log in a OAuth2 authorization

Hello, nice to greet all of you.

I have an scenario in wich I need the values from console log, to set some environment variables.

So, in my case, the Authorization is using OAuth2.0 feature - Request URL. When I get a access_token, using the feature in the same authorizarion tab, all the OAuth process happens and is recorded in the console log.

From console log, I need:

  • From the firts GET after the consent, I need to extract the auth_code in the response headers, and set it in a variable.
  • From the POST, extract the access_token and id_token, and set in a variable.

NOTE: important to clarify, till this moment I didn’t made any request to the API, because I’m still in the Authorization Tab.

Could anyone help me, please?

Best, regards.

Hi @ronaldzam31. Welcome to the Postman Community.

Are you making use of our OAUth 2.0 helper?. If yes, the access token can be stored in a variable and refreshed automatically.

However, to store the authorization code and id_tokens, you will need to manually build an Oauth flow from scratch in Postman and write some scripts to store these values in the appropriate environment variables yourself.

Hello @gbadebo-bello, thank for your response.

Yes, I used OAuth2.0 helper.

My flow is Authorization Code with PCKE Grant, for this reason build from scratch the first GET to build the Authorization Code isn’t possible (or I don’t know how to).

Greetings,

Hi @ronaldzam31.

The first step is possible, but it has to be a manual process and can’t be automated. The initial Authorization request to get the authorization grant is a GET request that loads an authorization screen. That can be done in a GET request in Postman or by copy and pasting the URL(with all necessary scopes and redirect URI) in the browser. After you input your credentials, and you have been redirected, you can copy the authorization code from the query parameters in the URL and store that in an environment variable.

Ideally, you only need the authorization code once. Once you are able to get your access token, you can always use your refresh token to get a new access token.

Thank you very much @gbadebo-bello, I build the flow from scratch.

Greetings,

1 Like