# OAuth 2.0 Token Refresh with Python

**URL:** <https://devforum.zoom.us/t/oauth-2-0-token-refresh-with-python/83594>\
**Category:** API and Webhooks\
**Tags:** api\
**Created:** [February 22, 2023, 8:55pm UTC](https://devforum.zoom.us/t/oauth-2-0-token-refresh-with-python/83594 "2023-02-22T20:55:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nbecirovic](https://avatars.discourse-cdn.com/v4/letter/n/9d8465/32.png) [@nbecirovic](https://devforum.zoom.us/u/nbecirovic)\
**Post date:** [February 22, 2023, 8:55pm UTC](https://devforum.zoom.us/t/oauth-2-0-token-refresh-with-python/83594/1 "2023-02-22T20:55:12Z")

</div>

Does anyone have example of Python code for refreshing OAuth 2.0 Token? I have built out my app fully and everything is working great, just can’t figure out how to refresh the token, as of now I’m just manually refreshing every 1 hour.

---

<div class="post-metadata">

**Author:** ![donte.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/donte.zoom/32/24412_2.png) [@donte.zoom](https://devforum.zoom.us/u/donte.zoom)\
**Post date:** [February 22, 2023, 9:35pm UTC](https://devforum.zoom.us/t/oauth-2-0-token-refresh-with-python/83594/2 "2023-02-22T21:35:46Z")

</div>

Thank you for posting in the Zoom Developer Forum – happy to help here @nbecirovic ! Before getting started, can you share how you are implementing OAuth in your application? Generally, you would want to store your refresh token for use when you want to make a request to get another token. You can either use a cache like Redis or db to handle storing and refreshing tokens

---

<div class="post-metadata">

**Author:** ![nbecirovic](https://avatars.discourse-cdn.com/v4/letter/n/9d8465/32.png) [@nbecirovic](https://devforum.zoom.us/u/nbecirovic)\
**Post date:** [February 23, 2023, 3:26pm UTC](https://devforum.zoom.us/t/oauth-2-0-token-refresh-with-python/83594/3 "2023-02-23T15:26:43Z")

</div>

I’m followed your guys guide for Postman for OAuth 2.0 and from there I just manually refresh the token and copy it to my Python application.

---

<div class="post-metadata">

**Author:** ![donte.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/donte.zoom/32/24412_2.png) [@donte.zoom](https://devforum.zoom.us/u/donte.zoom)\
**Post date:** [February 23, 2023, 3:28pm UTC](https://devforum.zoom.us/t/oauth-2-0-token-refresh-with-python/83594/4 "2023-02-23T15:28:10Z")

</div>

@nbecirovic

Are you able to share the snippet of code that handles making getting the Access token in your Python Application?

---

<div class="post-metadata">

**Author:** ![nbecirovic](https://avatars.discourse-cdn.com/v4/letter/n/9d8465/32.png) [@nbecirovic](https://devforum.zoom.us/u/nbecirovic)\
**Post date:** [February 23, 2023, 3:57pm UTC](https://devforum.zoom.us/t/oauth-2-0-token-refresh-with-python/83594/5 "2023-02-23T15:57:39Z")

</div>

I’m not getting the the token through my python code. I’ve created App in Zoom Marketplace, set up ClientID, Client Secret and Scopes. From there I used postman to create connection to Zoom API and via Postman I get the actual token to make the API calls.

I use that token in my Python code as such:

```auto
myToken = 'Bearer *token*'
myUrl = 'https://api.zoom.us/v2/users'
head = {'Authorization': myToken}

```

This works but its obviously not long term solution since I have to manually refresh that token in Postman and then copy it back to my Python code.

---

<div class="post-metadata">

**Author:** ![donte.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/donte.zoom/32/24412_2.png) [@donte.zoom](https://devforum.zoom.us/u/donte.zoom)\
**Post date:** [February 23, 2023, 4:11pm UTC](https://devforum.zoom.us/t/oauth-2-0-token-refresh-with-python/83594/6 "2023-02-23T16:11:27Z")

</div>

Okay, I see. The first thing I’d recommend is that the OAuth flow is handled in your application. That way you can implement the logic for:

1. Retrieving the access token

2. Storing/caching it for the duration of its lifetime (60 mins)

3. Refreshing the token

Here is a post with instructions on handling OAuth flow with a Python application. Take a look and let us know if you have any questions:

> [@Zoom Oauth python example](https://devforum.zoom.us/t/zoom-oauth-python-example/78181/2):
>
> Hi, @asanford, Welcome to the Zoom Developer Platform – happy to help. Please see the below OAuth2 Python example script smiley #!/usr/bin/env python from flask import Flask, abort, request from uuid import uuid4 import requests import requests.auth import urllib CLIENT\_ID = "YOUR\_ZOOM\_CLIENT\_ID" # Fill this in with your client ID CLIENT\_SECRET = "YOUR\_ZOOM\_SECRET" # Fill this in with your client secret REDIRECT\_URI = "http://localhost:65010/zoom\_callback" app = Flask(\_\_name\_\_) @app.route…

---

<div class="post-metadata">

**Author:** ![nbecirovic](https://avatars.discourse-cdn.com/v4/letter/n/9d8465/32.png) [@nbecirovic](https://devforum.zoom.us/u/nbecirovic)\
**Post date:** [February 23, 2023, 7:20pm UTC](https://devforum.zoom.us/t/oauth-2-0-token-refresh-with-python/83594/7 "2023-02-23T19:20:34Z")

</div>

In the above code would I use the same REDIRECT\_URI? In my current App I use:

```auto
https://oauth.pstmn.io/v1/callback

```

Also what do those functions do since I don’t see them being called or using the client variables?

---

<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:** [February 27, 2024, 10:57am UTC](https://devforum.zoom.us/t/oauth-2-0-token-refresh-with-python/83594/8 "2024-02-27T10:57:12Z")

</div>

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