cabana/server.py

38 lines
942 B
Python
Raw Normal View History

2017-06-13 18:40:05 -06:00
from flask import Flask, request, redirect
import requests
import json
2017-06-13 18:40:05 -06:00
2017-06-30 22:27:04 -06:00
CLIENT_ID = 'f1e42d14f45491f9ca34'
2019-06-18 14:54:13 -06:00
CLIENT_SECRET = ''
2017-06-13 18:40:05 -06:00
OAUTH_STATES = []
app = Flask(__name__)
@app.route('/auth_state')
def auth_state():
# save anti csrf secret
secret = request.args.get('state')
OAUTH_STATES.append(secret)
@app.route('/callback')
def callback():
code = request.args.get('code')
state = request.args.get('state')
2017-06-13 18:40:05 -06:00
data = {'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
'code': code,
'state': state}
2017-06-13 18:40:05 -06:00
resp = requests.post('https://github.com/login/oauth/access_token',
data=data,
headers={'Accept': 'application/json'})
oauth_resp = resp.json()
route = json.loads(state)['route']
2017-06-30 22:27:04 -06:00
return redirect('http://127.0.0.1:3000/?route={}&gh_access_token={}'.format(route, oauth_resp['access_token']))
2017-06-13 18:40:05 -06:00
if __name__ == '__main__':
app.run(port=1235)