How to automatically set OAuth 2.0 Access Token as variable

I have set up OAuth 2.0 Authorization with Authorization Code flow (i.e. user needs to authenticate) for a collection and i would like to automatically set the response, which includes access token, refresh token and other properties, as variables. Currently i am having to copy things manually from the UI.

after clicking on Get New Access Token

I get the access token in the UI but i also want to be able to automatically save the tokens into variables

If i go to the console i can see the json response so i would like to find a way to access that response and save the tokens please

Since I am using Authorization Code flow, it requires a user to sign in so it won’t be possible to just have a post request in the pre-script, which works if it’s a Client Credentials flow


Hey there! First, I’d like to welcome you to the Postman community and congrats on your first post! :confetti_ball:

So currently we are VERY close to getting auto update/refresh of OAuth2 access tokens feature implemented.

As of now, the only way to do this is as you described, generate an access token, copy-paste it into a variable and then use that variable under the access token field.

There is also an excellent post by @allen.helton about a workaround for token renewal that uses pre-request scripts:

Hope this helps! :smile:


ok thanks for letting me know. Looking forward to the new feature being deployed!