# Medium Article: How to Automate OAuth2 Token Renewal in Postman

**URL:** <https://community.postman.com/t/medium-article-how-to-automate-oauth2-token-renewal-in-postman/6630>\
**Category:** Help Hub\
**Created:** [July 18, 2019, 12:37pm UTC](https://community.postman.com/t/medium-article-how-to-automate-oauth2-token-renewal-in-postman/6630 "2019-07-18T12:37:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [July 18, 2019, 12:37pm UTC](https://community.postman.com/t/medium-article-how-to-automate-oauth2-token-renewal-in-postman/6630/1 "2019-07-18T12:37:30Z")

</div>

Hey everyone,

I have seen on a number of forums and stack overflow articles people expressing their frustration with the manual process Postman has for renewing OAuth2 tokens when they expire. I thought I would share a write up I did to help you get past the manual process and have your tokens renewing automatically.

Let me know what you think!

> **[How to Automate OAuth2 Token Renewal in Postman](https://allenheltondev.medium.com/how-to-automate-oauth2-token-renewal-in-postman-864420d381a0)**
>
> Discover how to automatically renew your OAuth2 access token in Postman so you never have to click the “Get New Access Token” button again.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [July 18, 2019, 1:33pm UTC](https://community.postman.com/t/medium-article-how-to-automate-oauth2-token-renewal-in-postman/6630/2 "2019-07-18T13:33:25Z")

</div>

Hey @allenheltondev

That’s awesome!! Great work!! 🏆

I wrote something that solved a similar issue in my context a while back - Love how Postman gives you the ability to created scripts like this in the application!!

> **[Postman – The Bearer of good news…](https://dannydainton.com/2018/09/10/postman-the-bearer-of-good-news/)**
>
> For a long time, I was doing something that just felt a bit wrong but it worked so I went with it, until I found an awesome community member, that decided to share their work to a wider audience. I…

---

<div class="post-metadata">

**Author:** ![surfgirl84](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@surfgirl84](https://community.postman.com/u/surfgirl84)\
**Post date:** [August 7, 2020, 12:44pm UTC](https://community.postman.com/t/medium-article-how-to-automate-oauth2-token-renewal-in-postman/6630/3 "2020-08-07T12:44:01Z")

</div>

Hello Allen, your method would really help me, just I have an implict flow, and do not really know how to implement this script with implicit crant type, do you have any suggestions? I would highly appreaciate! Ewa

---

<div class="post-metadata">

**Author:** ![lamnguyen1996](https://avatars.discourse-cdn.com/v4/letter/l/a698b9/32.png) [@lamnguyen1996](https://community.postman.com/u/lamnguyen1996)\
**Post date:** [June 19, 2021, 11:18am UTC](https://community.postman.com/t/medium-article-how-to-automate-oauth2-token-renewal-in-postman/6630/4 "2021-06-19T11:18:04Z")

</div>

Hi Allen,

That’s really great.  
But how about the new Authorization Code (With PCKE). I have set it up and can get access\_token by click on the Get Token button. Are there any ways to trigger it and get the token in the pre-request script?

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [June 21, 2021, 1:26pm UTC](https://community.postman.com/t/medium-article-how-to-automate-oauth2-token-renewal-in-postman/6630/5 "2021-06-21T13:26:33Z")

</div>

I could be wrong on this because I’m not a security expert, but I believe the PKCE flow requires a user to hit a login button. It’s intended to be used by an end user and not through automated means.

What we’ve done where I work is to set up a CCF (client credentials flow) for automation and use that while forcing our end users to go through PKCE.

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [June 22, 2021, 8:48am UTC](https://community.postman.com/t/medium-article-how-to-automate-oauth2-token-renewal-in-postman/6630/6 "2021-06-22T08:48:48Z")

</div>

There will be a refresh token and a refresh end point available you just have to send a post request to that refresh end point with the refresh token . You will get a new token . That’s the easiest way I guess

---

<div class="post-metadata">

**Author:** ![semangard](https://avatars.discourse-cdn.com/v4/letter/s/8491ac/32.png) [@semangard](https://community.postman.com/u/semangard)\
**Post date:** [July 14, 2021, 8:04am UTC](https://community.postman.com/t/medium-article-how-to-automate-oauth2-token-renewal-in-postman/6630/7 "2021-07-14T08:04:06Z")

</div>

Feature request asked : [Auto update of OAuth2 access tokens · Issue #10112 · postmanlabs/postman-app-support (github.com)](https://github.com/postmanlabs/postman-app-support/issues/10112)

---

<div class="post-metadata">

**Author:** ![Giiyms](https://avatars.discourse-cdn.com/v4/letter/g/858c86/32.png) [@Giiyms](https://community.postman.com/u/Giiyms)\
**Post date:** [August 9, 2021, 2:08pm UTC](https://community.postman.com/t/medium-article-how-to-automate-oauth2-token-renewal-in-postman/6630/8 "2021-08-09T14:08:40Z")

</div>

Is there a way to get the Collections authorization access token from the available tokens?  
Tried: pm.collectionVariables.get(“Access Token”)  
but it is not a variable.  
Would be nice to be able to access to the bearer token value inside the pre/test scripts.

---

<div class="post-metadata">

**Author:** ![JoshQA](https://avatars.discourse-cdn.com/v4/letter/j/dfb087/32.png) [@JoshQA](https://community.postman.com/u/JoshQA)\
**Post date:** [August 11, 2021, 8:25pm UTC](https://community.postman.com/t/medium-article-how-to-automate-oauth2-token-renewal-in-postman/6630/9 "2021-08-11T20:25:29Z")

</div>

really could use something like this, i am struggling to automate the oauth2 from google in postman. It just breaks after x time.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [December 12, 2024, 2:46pm UTC](https://community.postman.com/t/medium-article-how-to-automate-oauth2-token-renewal-in-postman/6630/10 "2024-12-12T14:46:54Z")

</div>

Closed on December 12, 2024, 2:46pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
