Skip to content

Commit 0a795d8

Browse files
committed
Add an option to request the user info on the SSO API langdev#1
1 parent 7d28892 commit 0a795d8

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

langdev/web/templates/thirdparty/app.html

+11
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ <h1>Not Found</h1>
103103
even if there is no given user, give <code>error=ignore</code> option into
104104
request.</p>
105105

106+
<h3>Request the user information</h3>
107+
<p>If you need the information of given user when the authentication has
108+
succeed, give <code>with=userinfo</code> option into request.</p>
109+
110+
<h3>Response example: when <code>with=userinfo</code> option was given</h3>
111+
<pre>HTTP/1.1 200 OK
112+
Vary: Accept
113+
Content-Type: application/json
114+
115+
{{ require('langdev.web.serializers').json(current_user) }}</pre>
116+
106117
<h2>Delete</h2>
107118
{% call render_raw_form('delete_app', app_key=app.key) %}
108119
<input type="submit" value="Delete" />

langdev/web/thirdparty.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def delete_app(app_key):
8787
def sso(app_key, user_login):
8888
"""Simple SSO API."""
8989
app = get_app(app_key)
90+
require_userinfo = request.values.get('with') == 'userinfo'
9091
error_ignored = request.values.get('error') == 'ignore'
9192
success = None
9293
if User.LOGIN_PATTERN.match(user_login):
@@ -108,5 +109,12 @@ def sso(app_key, user_login):
108109
success = False
109110
if success is None:
110111
success = app.hmac(user.password) == request.values['password']
111-
return render('thirdparty/sso', success, success=success)
112+
if success and require_userinfo:
113+
result = user
114+
# workaround to include ``email`` attribute in the response.
115+
# see also :func:`langdev.objsimplify.transform`.
116+
g.current_user = user
117+
else:
118+
result = success
119+
return render('thirdparty/sso', result, success=success)
112120

0 commit comments

Comments
 (0)