1 |
#!/usr/bin/python |
2 |
|
3 |
import flask |
4 |
from flask import session |
5 |
import conf |
6 |
import requests |
7 |
import json |
8 |
|
9 |
app = flask.Flask(__name__) |
10 |
|
11 |
app.config['secret_key'] = "asdkasdiq2jedmaid0q2238uwadscksnc" |
12 |
app.secret_key = "asdkasdiq2jedmaid0q2238uwadscksnc" |
13 |
|
14 |
appID = 'YrYc9oMO7fT0avRUAtbRO1cLvoOUUI08BAuqOAJc' |
15 |
appSecret = 'r9BIYjYOPotMQUOoI98DmH7Eu1M4zg6cMeLay7LOlSsrF1KhKZ' |
16 |
|
17 |
@app.route('/', methods=['GET']) |
18 |
def index(): |
19 |
auth_tok = None |
20 |
if flask.request.args.get('code'): |
21 |
payload = { |
22 |
'scopes': 'email sweet', |
23 |
'client_secret': appSecret, |
24 |
'code': flask.request.args.get('code'), |
25 |
'redirect_uri': 'http://localhost:5000/', |
26 |
'grant_type': 'authorization_code', |
27 |
'client_id': appID |
28 |
} |
29 |
resp = requests.post('http://localhost:5001/oauth/token', data=payload) |
30 |
auth_tok = json.loads(resp.text) |
31 |
print auth_tok |
32 |
if auth_tok.has_key('error'): |
33 |
print auth_tok['error'] |
34 |
return flask.make_response(auth_tok['error'], 200) |
35 |
|
36 |
session['auth_tok'] = auth_tok |
37 |
|
38 |
if 'auth_tok' in session: |
39 |
auth_tok = session['auth_tok'] |
40 |
else: |
41 |
auth_tok = {'access_token': '', 'refresh_token': ''} |
42 |
|
43 |
print auth_tok |
44 |
return flask.render_template('index.html', |
45 |
access_token=auth_tok['access_token'], |
46 |
refresh_token=auth_tok['refresh_token'], |
47 |
url=flask.request.args.get('where'), |
48 |
conf=conf) |
49 |
|
50 |
if __name__ == '__main__': |
51 |
app.run(debug=conf.debug, host=conf.HOST, port=conf.PORT) |