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

Commit

Permalink
Merge pull request #2 from Kroisse/master
Browse files Browse the repository at this point in the history
Add an option to request the user info on SSO API
  • Loading branch information
dahlia committed Feb 24, 2012
2 parents e85f1c0 + 0a795d8 commit 3154a29
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
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)

0 comments on commit 3154a29

Please sign in to comment.