This repository has been archived by the owner on Nov 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Return either user info or anon user This makes a cleaner interface for boardwalk * Remove whitelist checking for /me endpoint
- Loading branch information
1 parent
47675f2
commit 5ef42c5
Showing
1 changed file
with
7 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -386,43 +386,19 @@ def me(): | |
""" | ||
returns information about the user making the request. | ||
If authentication is required for the deployment, and there is no | ||
access token, or it is expired and cannot be renewed, then return a | ||
401. | ||
If authentication is not required for the deployment, and there is no | ||
access token, or it is expired and cannot be renewed, then return | ||
an anonymous user. | ||
{'name': 'anonymous'} | ||
If the access token has not expired, or it can be refreshed with the | ||
refresh token, then return the following information about the user. | ||
{ | ||
"name": "Jane Doe", | ||
"email": "[email protected]", | ||
"avatar": "https:///lh6.googleusercontent.com/....", | ||
} | ||
In addition, if the access token was refreshed, the new access token | ||
will be sent back in the session cookie. | ||
If there are any problems getting the user's info, refreshing the token, etc | ||
then just return the anonymous user. | ||
""" | ||
|
||
# Do we have an access token? | ||
if current_user.is_anonymous: | ||
if whitelist_checker: | ||
return 'No access token', 401 | ||
else: | ||
return jsonify({'name': 'anonymous'}) | ||
return jsonify({'name': 'anonymous'}) | ||
try: | ||
user_data = get_user_info() | ||
except ValueError as e: | ||
return e.message, 401 | ||
except OAuth2Error as e: | ||
return 'Failed to get user info: ' + e.message, 401 | ||
if whitelist_checker is not None and not whitelist_checker.is_authorized(user_data['email']): | ||
return 'User no longer whitelisted', 401 | ||
except ValueError: | ||
return jsonify({'name': 'anonymous'}) | ||
except OAuth2Error: | ||
return jsonify({'name': 'anonymous'}) | ||
output = dict((k, user_data[k]) for k in ('name', 'email')) | ||
output['avatar'] = user_data['picture'] | ||
return jsonify(output) | ||
|