2017-06-13 18:40:05 -06:00
|
|
|
from flask import Flask, request, redirect
|
|
|
|
import requests
|
2017-06-28 17:21:19 -06:00
|
|
|
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():
|
2017-06-28 17:21:19 -06:00
|
|
|
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-28 17:21:19 -06:00
|
|
|
|
2017-06-13 18:40:05 -06:00
|
|
|
data = {'client_id': CLIENT_ID,
|
|
|
|
'client_secret': CLIENT_SECRET,
|
2017-06-28 17:21:19 -06:00
|
|
|
'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()
|
|
|
|
|
2017-06-28 17:21:19 -06:00
|
|
|
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__':
|
2017-06-28 17:21:19 -06:00
|
|
|
app.run(port=1235)
|