From 9d6a4205d0065d91d6ccec6b9042d03031cef817 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Tue, 12 Feb 2013 17:33:01 +0100 Subject: [PATCH] [FIX] auth_oauth: redirect to login page in case of failure with an automatic oauth signin, but avoid destroying user session bzr revid: odo@openerp.com-20130212163301-cnq949vr1h6hfvf5 --- addons/auth_oauth/controllers/main.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/addons/auth_oauth/controllers/main.py b/addons/auth_oauth/controllers/main.py index f461a675a47..1c38f7f4eae 100644 --- a/addons/auth_oauth/controllers/main.py +++ b/addons/auth_oauth/controllers/main.py @@ -2,8 +2,10 @@ import functools import logging import simplejson +import werkzeug.utils from werkzeug.exceptions import BadRequest +import openerp from openerp import SUPERUSER_ID import openerp.addons.web.http as oeweb from openerp.addons.web.controllers.main import db_monodb, set_cookie_and_redirect, login_and_redirect @@ -69,6 +71,13 @@ class OAuthController(oeweb.Controller): # auth_signup is not installed _logger.error("auth_signup not installed on database %s: oauth sign up cancelled." % (dbname,)) url = "/#action=login&oauth_error=1" + except openerp.exceptions.AccessDenied: + # oauth credentials not valid, user could be on a temporary session + _logger.info('OAuth2: access denied, redirect to main page in case a valid session exists, without setting cookies') + url = "/#action=login&oauth_error=3" + redirect = werkzeug.utils.redirect(url, 303) + redirect.autocorrect_location_header = False + return redirect except Exception, e: # signup error _logger.exception("OAuth2: %s" % str(e))