Created
September 16, 2023 19:07
-
-
Save Celeo/b9829a0540e72fbc26a79a155eb5f2fc to your computer and use it in GitHub Desktop.
Extremely simple Python Flask app for authenticating with VATSIM Dev OAuth
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
import json | |
from urllib.parse import quote_plus | |
from flask import Flask, redirect, request, jsonify | |
import httpx | |
app = Flask(__name__) | |
CLIENT_ID = '638' | |
CLIENT_SECRET = 'mUMSDmiVV4YAK0aleuVi1XWNp0MDFPKzjOLqPecF' | |
CALLBACK_URL = 'https://floral-dust-864.fly.dev/callback' | |
@app.route('/login') | |
def login(): | |
print('Access: /login') | |
callback = quote_plus(CALLBACK_URL) | |
return redirect(f'https://auth-dev.vatsim.net/oauth/authorize?client_id={CLIENT_ID}&redirect_uri={callback}&response_type=code&scope=full_name%20vatsim_details') | |
@app.route('/callback') | |
def callback(): | |
print('Access: /callback') | |
code = request.args.get('code', None) | |
print(f'Code is: {code}') | |
resp = httpx.post('https://auth-dev.vatsim.net/oauth/token', data = { | |
'grant_type': 'authorization_code', | |
'client_id': CLIENT_ID, | |
'client_secret': CLIENT_SECRET, | |
'redirect_uri': CALLBACK_URL, | |
'code': code | |
}) | |
print(f'Got status {resp.status_code} from VATSIM DEV OAuth token endpoint') | |
return jsonify(json.loads(resp.text)) | |
@app.route('/info') | |
def info(): | |
print('Access /info') | |
token = request.args.get('access_token', None) | |
print(f'Access token is: {token}') | |
resp = httpx.get('https://auth-dev.vatsim.net/api/user', headers = { 'authorization': f'Bearer {token}', 'accept': 'application/json' }) | |
print(f'Got status {resp.status_code} from VATSIM DEV Oauth user info endpoint') | |
return jsonify(json.loads(resp.text)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment