Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Aug 14, 2026. It is now read-only.
forked from robbles/humanapi-sample-app
- Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapp.py
More file actions
Latest commit
executable file
·59 lines (41 loc) · 1.54 KB
/
Copy pathapp.py
File metadata and controls
executable file
·59 lines (41 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
fromflaskimportFlask, request, render_template, url_for, redirect, session
fromhumanapiimportget_authorize_url, get_auth_session
importsettings
app=Flask(__name__)
app.secret_key=settings.SECRET_KEY
@app.route('/', methods=['GET', 'POST'])
defindex():
ifrequest.method=='POST':
redirect_uri=url_for('humanapi_callback', _external=True)
authorize_url=get_authorize_url(redirect_uri)
returnredirect(authorize_url)
# Display intro page with login button that posts to here
returnrender_template('index.html')
@app.route('/humanapi/callback')
defhumanapi_callback():
# Get code from response
code=request.args.get('code')
ifnotcode:
return'Error: code parameter must be provided in oauth2 callback', 400
# Get an authorized session with HumanAPI
auth_session=get_auth_session(code)
# Fetch user profile
profile=auth_session.get('profile').json()
printprofile
session['id'] =profile['userId']
session['email'] =profile['email']
session['access_token'] =auth_session.access_token
# Redirect to location page
returnredirect(url_for('profile'))
@app.route('/profile')
defprofile():
# Profile data is pulled from session and populated from humanapi_callback
returnrender_template('profile.html')
@app.route('/location')
deflocation():
# TODO: Pull in user's location data
# display in template
returnrender_template('location.html')
if__name__=='__main__':
app.run(debug=True)