# Zoom Oauth python example

**URL:** <https://devforum.zoom.us/t/zoom-oauth-python-example/78181>\
**Category:** API and Webhooks\
**Created:** [November 1, 2022, 10:39pm UTC](https://devforum.zoom.us/t/zoom-oauth-python-example/78181 "2022-11-01T22:39:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![asanford](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/asanford/32/38469_2.png) [@asanford](https://devforum.zoom.us/u/asanford)\
**Post date:** [November 1, 2022, 10:39pm UTC](https://devforum.zoom.us/t/zoom-oauth-python-example/78181/1 "2022-11-01T22:39:27Z")

</div>

Does anyone have an example to compare to for Oauth? I’m new to most of all this and struggling on finding a good starting point.

---

<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:** [November 2, 2022, 3:06pm UTC](https://devforum.zoom.us/t/zoom-oauth-python-example/78181/2 "2022-11-02T15:06:26Z")

</div>

Hi, @asanford,

Welcome to the Zoom Developer Platform – happy to help. Please see the below OAuth2 Python example script 😃

```auto
#!/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('/')
def homepage():
    text = '<a href="%s">Authenticate with Zoom</a>'
    return text % make_authorization_url()

def make_authorization_url():
    # Generate a random string for the state parameter
    # Save it for use later to prevent xsrf attacks
    
    params = {"client_id": CLIENT_ID,
              "response_type": "code",
              "redirect_uri": REDIRECT_URI}
    url = "https://zoom.us/oauth/authorize?" + urllib.parse.urlencode(params)
    return url

@app.route('/zoom_callback')
def zoom_callback():
    error = request.args.get('error', '')
    if error:
        return "Error: " + error
    
    code = request.args.get('code')
    access_token = get_token(code)
    # Note: In most cases, you'll want to store the access token, in, say,
    # a session for use in other parts of your web app.
    return "Your user info is: %s" % get_username(access_token)

def get_token(code):
    client_auth = requests.auth.HTTPBasicAuth(CLIENT_ID, CLIENT_SECRET)
    post_data = {"grant_type": "authorization_code",
                 "code": code,
                 "redirect_uri": REDIRECT_URI}

    response = requests.post("https://zoom.us/oauth/token",
                             auth=client_auth,
                             data=post_data)
    token_json = response.json()
    print(token_json)
    return token_json["access_token"]
    
    
def get_username(access_token):
    
    headers= {"Authorization": "bearer " + access_token}
    response = requests.get("https://api.zoom.us/v2/users/me", headers=headers)
    me_json = response.json()
    return me_json

if __name__ == ' __main__':
    app.run(debug=True, port=65010)

```

Enter values for client\_ID and Secret, then to run the script, use the following command in your terminal:  
python3 nameofscript.py

OAuth 2.0 Resources :

# Create an OAuth App

[https://marketplace.zoom.us/docs/guides/build/oauth-app/](https://marketplace.zoom.us/docs/guides/build/oauth-app/)

# OAuth with Zoom

[https://marketplace.zoom.us/docs/guides/auth/oauth/](https://marketplace.zoom.us/docs/guides/auth/oauth/)

---

<div class="post-metadata">

**Author:** ![asanford](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/asanford/32/38469_2.png) [@asanford](https://devforum.zoom.us/u/asanford)\
**Post date:** [November 2, 2022, 3:53pm UTC](https://devforum.zoom.us/t/zoom-oauth-python-example/78181/3 "2022-11-02T15:53:45Z")

</div>

awesome! Thanks Donte!!!

---

<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:** [November 2, 2022, 4:05pm UTC](https://devforum.zoom.us/t/zoom-oauth-python-example/78181/4 "2022-11-02T16:05:08Z")

</div>

You’re welcome @asanford !

---

<div class="post-metadata">

**Author:** ![enielsen](https://avatars.discourse-cdn.com/v4/letter/e/da6949/32.png) [@enielsen](https://devforum.zoom.us/u/enielsen)\
**Post date:** [November 28, 2022, 5:51pm UTC](https://devforum.zoom.us/t/zoom-oauth-python-example/78181/5 "2022-11-28T17:51:29Z")

</div>

Just noting here (for people like me new to setting this up), that for the above script to work one must correctly configure the Oauth App in the marketplace, especially setting:

- Scopes must have at least: View all user information /user:read:admin
- Must set the Oauth Allow list to: [http://localhost:65010](http://localhost:65010)
- Must set Redirect URL for OAuth to have: [http://localhost:65010](http://localhost:65010)
- Not sure if really have to set all the other info like dev name and email address, but I did all that as well.

---

<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, 1:44am UTC](https://devforum.zoom.us/t/zoom-oauth-python-example/78181/6 "2023-02-23T01:44:31Z")

</div>

Thanks for sharing these steps @enielsen!

---

<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 26, 2024, 5:20pm UTC](https://devforum.zoom.us/t/zoom-oauth-python-example/78181/7 "2024-02-26T17:20:36Z")

</div>

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