From 7d2889207837dc6bad368146e55728ffa37a3ada Mon Sep 17 00:00:00 2001 From: Eunchong Yu Date: Wed, 22 Feb 2012 10:46:01 +0900 Subject: [PATCH 1/2] Copy an ignoring rule from .hgignore --- .gitignore | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6bc8029 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +docs/_build +LangDev.egg-info +db.sqlite +*.pyc +*.swp +*.cfg +.DS_Store From 0a795d8bbc2ddcb4b806fb2ca697629ecf2e6aa9 Mon Sep 17 00:00:00 2001 From: Eunchong Yu Date: Wed, 22 Feb 2012 12:36:09 +0900 Subject: [PATCH 2/2] Add an option to request the user info on the SSO API langdev#1 --- langdev/web/templates/thirdparty/app.html | 11 +++++++++++ langdev/web/thirdparty.py | 10 +++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/langdev/web/templates/thirdparty/app.html b/langdev/web/templates/thirdparty/app.html index 03e869d..6c183fd 100644 --- a/langdev/web/templates/thirdparty/app.html +++ b/langdev/web/templates/thirdparty/app.html @@ -103,6 +103,17 @@

Not Found

even if there is no given user, give error=ignore option into request.

+

Request the user information

+

If you need the information of given user when the authentication has + succeed, give with=userinfo option into request.

+ +

Response example: when with=userinfo option was given

+
HTTP/1.1 200 OK
+Vary: Accept
+Content-Type: application/json
+
+{{ require('langdev.web.serializers').json(current_user) }}
+

Delete

{% call render_raw_form('delete_app', app_key=app.key) %} diff --git a/langdev/web/thirdparty.py b/langdev/web/thirdparty.py index d95816b..93dd880 100644 --- a/langdev/web/thirdparty.py +++ b/langdev/web/thirdparty.py @@ -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): @@ -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)