[ADD] Make things work .... or not ?
bzr revid: fme@openerp.com-20120924153729-e7lsjvfxfpjzrpm7
This commit is contained in:
parent
a74b35ee37
commit
292252eb7d
|
@ -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 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:
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue