Created
February 10, 2021 15:28
-
-
Save federicoemartinez/e63c7130fb9af95dfa1737c879ca190a to your computer and use it in GitHub Desktop.
zoom oauth example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from base64 import b64encode | |
from flask import Flask, redirect, url_for, session, request, jsonify | |
from flask_oauthlib.client import OAuth | |
API_SECRET = "SECRET_KEY" | |
API_KEY = "API_KEY" | |
PUBLIC_URL = "http://SOMETHING.ngrok.io/" | |
app = Flask(__name__) | |
app.debug = True | |
app.secret_key = 'development' | |
oauth = OAuth(app) | |
zoom = oauth.remote_app( | |
'zoom', | |
consumer_key=API_KEY, | |
consumer_secret=API_SECRET, | |
base_url='https://zoom.us/v2/', | |
access_token_url='https://zoom.us/oauth/token', | |
authorize_url='https://zoom.us/oauth/authorize', | |
access_token_headers= {'basic':b64encode((API_KEY + ":" + API_SECRET).encode('utf8'))}, | |
access_token_method='POST', | |
access_token_params = {"redirect_uri": PUBLIC_URL + "authorized"} | |
) | |
@app.route('/') | |
def index(): | |
if 'zoom_token' in session: | |
resp = zoom.post('users/me/meetings', data={'type':1, 'topic':"test"}, format="json") | |
print(resp.data) | |
return jsonify(status=resp.status, data=resp.data) | |
return redirect(url_for('login')) | |
@app.route('/login') | |
def login(): | |
return zoom.authorize(callback=PUBLIC_URL + "authorized") | |
@app.route('/logout') | |
def logout(): | |
session.pop('zoom_token', None) | |
return redirect(url_for('index')) | |
@app.route('/authorized') | |
def authorized(): | |
resp = zoom.authorized_response() | |
print(resp) | |
if resp is None: | |
return 'Access denied: reason=%s error=%s' % ( | |
request.args['error_reason'], | |
request.args['error_description'] | |
) | |
session['zoom_token'] = (resp['access_token'], '') | |
return redirect(PUBLIC_URL ) | |
@zoom.tokengetter | |
def get_douban_oauth_token(): | |
return session.get('zoom_token') | |
if __name__ == '__main__': | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment