cabana/server.py

41 lines
1.1 KiB
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
CLIENT_ID = '4b43250e7499a97d62a5'
CLIENT_SECRET = '65dbd43f3e298e024a7aff85b2a9ed261ffc9fcf'
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():
CLIENT_ID = '4b43250e7499a97d62a5'
CLIENT_SECRET = '65dbd43f3e298e024a7aff85b2a9ed261ffc9fcf'
2017-06-13 18:40:05 -06:00
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']
return redirect('https://community.comma.ai/cabana/?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)