diff options
| author | Fabien Meghazi <fme@openerp.com> | 2012-09-24 17:37:29 +0200 |
|---|---|---|
| committer | Fabien Meghazi <fme@openerp.com> | 2012-09-24 17:37:29 +0200 |
| commit | 292252eb7dd18de14a3d4504e33c7b8df2936fbc (patch) | |
| tree | 629bd3089bd6bb1b10073d13246542ea5ddf2fc3 | |
| parent | a74b35ee3758545dabd811fe8ac9d0c68a3420ca (diff) | |
[ADD] Make things work .... or not ?
bzr revid: fme@openerp.com-20120924153729-e7lsjvfxfpjzrpm7
| -rw-r--r-- | addons/auth_oauth_provider/controllers/main.py | 31 | ||||
| -rw-r--r-- | addons/auth_oauth_provider/res_users.py | 12 |
2 files changed, 35 insertions, 8 deletions
diff --git a/addons/auth_oauth_provider/controllers/main.py b/addons/auth_oauth_provider/controllers/main.py index 63bf3cad61c..7ca4ab75d56 100644 --- a/addons/auth_oauth_provider/controllers/main.py +++ b/addons/auth_oauth_provider/controllers/main.py @@ -23,14 +23,27 @@ try: import openerp.addons.web.common.http as openerpweb except ImportError: - import web.common.http as openerpweb # noqa + import web.common.http as openerpweb -import simplejson +import openerp.modules.registry +from openerp import SUPERUSER_ID +import simplejson +import werkzeug +import urllib class AuthOAuthProvider(openerpweb.Controller): _cp_path = '/oauth2' + @openerpweb.httprequest + def auth(self, req, **kw): + # TODO: if logged and approval_prompt == auto then return get_token and redirect + search = req.params.copy() + if req.debug: + search['debug'] = 1 + redirect_url = '/?' + urllib.urlencode(search) + '#action=oauth2_auth' + return werkzeug.utils.redirect(redirect_url, 303) + @openerpweb.jsonrequest def get_token(self, req, client_id="", scope="", **kw): token = req.session.model('res.users').auth_oauth_provider_get_token(client_id, scope) @@ -39,8 +52,16 @@ class AuthOAuthProvider(openerpweb.Controller): } @openerpweb.httprequest - def tokeninfo(self, req, access_token="", **kw): - info = req.session.model('res.users').auth_oauth_provider_tokeninfo(access_token) - return simplejson.dumps(info) + def tokeninfo(self, req, dbname=None, access_token=None, **kw): + if not dbname or not access_token: + return simplejson.dumps({ "error": "No 'dbname' or 'access_token' url parameters specified." }) + try: + registry = openerp.modules.registry.RegistryManager.get(dbname) + with registry.cursor() as cr: + u = registry.get('res.users') + info = u.auth_oauth_provider_tokeninfo(cr, SUPERUSER_ID, access_token, kw) + return simplejson.dumps(info) + except Exception, e: + return simplejson.dumps({ "error": e.message }) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/auth_oauth_provider/res_users.py b/addons/auth_oauth_provider/res_users.py index 3831a6a97d0..983672e0261 100644 --- a/addons/auth_oauth_provider/res_users.py +++ b/addons/auth_oauth_provider/res_users.py @@ -40,14 +40,20 @@ class res_users(osv.osv): }, context=context) return token - def auth_oauth_provider_tokeninfo(self, cr, uid, access_token="", context=None): - user = self.browse(cr, uid, [uid], context=context) + def auth_oauth_provider_tokeninfo(self, cr, uid, access_token, context=None): + user_id = self.search(cr, uid, [('last_oauth_token', '=', access_token)], context=context) + if len(user_id) != 1: + return { + "error": "invalid_token" + } + user = self.browse(cr, uid, user_id[0], context=context) if access_token == user.last_oauth_token: return { "user_id": uid, "scope": user.last_oauth_token_scope, + "email": user.partner_id.email or '', # TODO: should deliver only according to scopes + "scope": user.last_oauth_token_scope, #"audience": "8819981768.apps.googleusercontent.com", - #"scope": "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email", #"expires_in": 436 } else: |
