Zoom Oauth python example

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.

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

OAuth with Zoom

1 Like

awesome! Thanks Donte!!!

You’re welcome @asanford !

1 Like

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
  • Must set Redirect URL for OAuth to have: 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.
2 Likes

Thanks for sharing these steps @enielsen!

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