# 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:** 1\
**Showing post:** 2

<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/)

---

_[View the full topic](https://devforum.zoom.us/t/zoom-oauth-python-example/78181)._
