# Best practice/solution to handle OAUTH access token refresh race condition

**URL:** <https://devforum.zoom.us/t/best-practice-solution-to-handle-oauth-access-token-refresh-race-condition/74137>\
**Category:** API and Webhooks\
**Tags:** oauth\
**Created:** [August 12, 2022, 4:17pm UTC](https://devforum.zoom.us/t/best-practice-solution-to-handle-oauth-access-token-refresh-race-condition/74137 "2022-08-12T16:17:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jfuhr](https://avatars.discourse-cdn.com/v4/letter/j/5fc32e/32.png) [@jfuhr](https://devforum.zoom.us/u/jfuhr)\
**Post date:** [August 12, 2022, 4:17pm UTC](https://devforum.zoom.us/t/best-practice-solution-to-handle-oauth-access-token-refresh-race-condition/74137/1 "2022-08-12T16:17:10Z")

</div>

As stated in the title, I’m looking for a solution to handle access token refresh requests.

The issue is that if multiple requests come in at the same time to create a meeting, and the access token is expired, a refresh request will be sent. Multiple calls to refresh the token will result in a failure because the first request will invalidate the others aka ‘race condition’.

I’ve read several posts on here without any good solution being provided.

My thought is to, after authorization and a exchange for access token:

1. store the access token, expiry time, and refresh token in a database (for scalability).
2. On an API call, fetch info from step 1. If not expired, use it.
3. If expired, set a flag on the table to indicate refresh is in progress. If flag is set, wait 1 second and query again.
4. Fetch refresh token, update database, remove flag.

This seems prone to errors so I’m looking for some working solutions.

Thanks!  
Jaime

---

<div class="post-metadata">

**Author:** ![gianni.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/gianni.zoom/32/32523_2.png) [@gianni.zoom](https://devforum.zoom.us/u/gianni.zoom)\
**Post date:** [August 15, 2022, 10:44pm UTC](https://devforum.zoom.us/t/best-practice-solution-to-handle-oauth-access-token-refresh-race-condition/74137/2 "2022-08-15T22:44:35Z")

</div>

Hi @jfuhr ,

Thank you for resurfacing this issue! I’m looking into some suggestions from our API team that align with security and API best practices.

Best,  
Gianni

---

<div class="post-metadata">

**Author:** ![gianni.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/gianni.zoom/32/32523_2.png) [@gianni.zoom](https://devforum.zoom.us/u/gianni.zoom)\
**Post date:** [August 16, 2022, 4:40pm UTC](https://devforum.zoom.us/t/best-practice-solution-to-handle-oauth-access-token-refresh-race-condition/74137/4 "2022-08-16T16:40:32Z")

</div>

Hi @jfuhr ,

Here’s what our API team has recommended:

Customer should see a “Save Access token into Database” error message when there are duplicate requests ‘oauth/token’. Those requests need to wait the first request completed.

I suggest the customer build a flag which can indicate if the new access token is in process, when the first request finds the access token is expired, then try to get the new access token.

Meanwhile it can make the value of flag “is true” (the default value is false), then the value is revised to false after the access token is successfully retrieved. In the process, the other request needs to wait.

Does this help?

---

<div class="post-metadata">

**Author:** ![jfuhr](https://avatars.discourse-cdn.com/v4/letter/j/5fc32e/32.png) [@jfuhr](https://devforum.zoom.us/u/jfuhr)\
**Post date:** [August 16, 2022, 5:13pm UTC](https://devforum.zoom.us/t/best-practice-solution-to-handle-oauth-access-token-refresh-race-condition/74137/5 "2022-08-16T17:13:35Z")

</div>

Okay, thanks for the assistance

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/6/1/614bdd549b610bbaa46ff934617683a02bdaa03c.png) [@system](https://devforum.zoom.us/u/system)\
**Post date:** [August 10, 2023, 9:40pm UTC](https://devforum.zoom.us/t/best-practice-solution-to-handle-oauth-access-token-refresh-race-condition/74137/6 "2023-08-10T21:40:29Z")

</div>

Closed on August 10, 2023, 9:40pm UTC

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