Skip to content
This repository has been archived by the owner on Sep 7, 2018. It is now read-only.

Add an option to request the user info on SSO API #2

Merged
merged 2 commits into from
Feb 24, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
docs/_build
LangDev.egg-info
db.sqlite
*.pyc
*.swp
*.cfg
.DS_Store
11 changes: 11 additions & 0 deletions langdev/web/templates/thirdparty/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ <h1>Not Found</h1>
even if there is no given user, give <code>error=ignore</code> option into
request.</p>

<h3>Request the user information</h3>
<p>If you need the information of given user when the authentication has
succeed, give <code>with=userinfo</code> option into request.</p>

<h3>Response example: when <code>with=userinfo</code> option was given</h3>
<pre>HTTP/1.1 200 OK
Vary: Accept
Content-Type: application/json

{{ require('langdev.web.serializers').json(current_user) }}</pre>

<h2>Delete</h2>
{% call render_raw_form('delete_app', app_key=app.key) %}
<input type="submit" value="Delete" />
Expand Down
10 changes: 9 additions & 1 deletion langdev/web/thirdparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def delete_app(app_key):
def sso(app_key, user_login):
"""Simple SSO API."""
app = get_app(app_key)
require_userinfo = request.values.get('with') == 'userinfo'
error_ignored = request.values.get('error') == 'ignore'
success = None
if User.LOGIN_PATTERN.match(user_login):
Expand All @@ -108,5 +109,12 @@ def sso(app_key, user_login):
success = False
if success is None:
success = app.hmac(user.password) == request.values['password']
return render('thirdparty/sso', success, success=success)
if success and require_userinfo:
result = user
# workaround to include ``email`` attribute in the response.
# see also :func:`langdev.objsimplify.transform`.
g.current_user = user
else:
result = success
return render('thirdparty/sso', result, success=success)