[FIX] auth_oauth: authentication problem with the new server-side web framework
bzr revid: nicolas.vanhoren@openerp.com-20130624095255-uj6702oq6601eql5
This commit is contained in:
parent
ea03ed65b6
commit
0b6b7d643d
|
@ -7,7 +7,8 @@ from werkzeug.exceptions import BadRequest
|
|||
|
||||
import openerp
|
||||
from openerp import SUPERUSER_ID
|
||||
import openerp.addons.web.http as oeweb
|
||||
import openerp.addons.web.http as http
|
||||
from openerp.addons.web.http import request
|
||||
from openerp.addons.web.controllers.main import db_monodb, set_cookie_and_redirect, login_and_redirect
|
||||
from openerp.modules.registry import RegistryManager
|
||||
|
||||
|
@ -18,7 +19,7 @@ _logger = logging.getLogger(__name__)
|
|||
#----------------------------------------------------------
|
||||
def fragment_to_query_string(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper(self, req, **kw):
|
||||
def wrapper(self, **kw):
|
||||
if not kw:
|
||||
return """<html><head><script>
|
||||
var l = window.location;
|
||||
|
@ -30,18 +31,17 @@ def fragment_to_query_string(func):
|
|||
}
|
||||
window.location = r;
|
||||
</script></head><body></body></html>"""
|
||||
return func(self, req, **kw)
|
||||
return func(self, **kw)
|
||||
return wrapper
|
||||
|
||||
|
||||
#----------------------------------------------------------
|
||||
# Controller
|
||||
#----------------------------------------------------------
|
||||
class OAuthController(oeweb.Controller):
|
||||
_cp_path = '/auth_oauth'
|
||||
class OAuthController(http.Controller):
|
||||
|
||||
@oeweb.jsonrequest
|
||||
def list_providers(self, req, dbname):
|
||||
@http.route('/auth_oauth/list_providers', type='json', auth='none')
|
||||
def list_providers(self, dbname):
|
||||
try:
|
||||
registry = RegistryManager.get(dbname)
|
||||
with registry.cursor() as cr:
|
||||
|
@ -51,9 +51,9 @@ class OAuthController(oeweb.Controller):
|
|||
l = []
|
||||
return l
|
||||
|
||||
@oeweb.httprequest
|
||||
@http.route('/auth_oauth/signin', type='http', auth='none')
|
||||
@fragment_to_query_string
|
||||
def signin(self, req, **kw):
|
||||
def signin(self, **kw):
|
||||
state = simplejson.loads(kw['state'])
|
||||
dbname = state['d']
|
||||
provider = state['p']
|
||||
|
@ -71,7 +71,7 @@ class OAuthController(oeweb.Controller):
|
|||
url = '/#action=%s' % action
|
||||
elif menu:
|
||||
url = '/#menu_id=%s' % menu
|
||||
return login_and_redirect(req, *credentials, redirect_url=url)
|
||||
return login_and_redirect(*credentials, redirect_url=url)
|
||||
except AttributeError:
|
||||
# auth_signup is not installed
|
||||
_logger.error("auth_signup not installed on database %s: oauth sign up cancelled." % (dbname,))
|
||||
|
@ -88,14 +88,14 @@ class OAuthController(oeweb.Controller):
|
|||
_logger.exception("OAuth2: %s" % str(e))
|
||||
url = "/#action=login&oauth_error=2"
|
||||
|
||||
return set_cookie_and_redirect(req, url)
|
||||
return set_cookie_and_redirect(url)
|
||||
|
||||
@oeweb.httprequest
|
||||
def oea(self, req, **kw):
|
||||
@http.route('/auth_oauth/oea', type='http', auth='none')
|
||||
def oea(self, **kw):
|
||||
"""login user via OpenERP Account provider"""
|
||||
dbname = kw.pop('db', None)
|
||||
if not dbname:
|
||||
dbname = db_monodb(req)
|
||||
dbname = db_monodb()
|
||||
if not dbname:
|
||||
return BadRequest()
|
||||
|
||||
|
@ -105,7 +105,7 @@ class OAuthController(oeweb.Controller):
|
|||
try:
|
||||
model, provider_id = IMD.get_object_reference(cr, SUPERUSER_ID, 'auth_oauth', 'provider_openerp')
|
||||
except ValueError:
|
||||
return set_cookie_and_redirect(req, '/?db=%s' % dbname)
|
||||
return set_cookie_and_redirect('/?db=%s' % dbname)
|
||||
assert model == 'auth.oauth.provider'
|
||||
|
||||
state = {
|
||||
|
@ -115,6 +115,6 @@ class OAuthController(oeweb.Controller):
|
|||
}
|
||||
|
||||
kw['state'] = simplejson.dumps(state)
|
||||
return self.signin(req, **kw)
|
||||
return self.signin(**kw)
|
||||
|
||||
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
Loading…
Reference in New Issue