From e3fd75015c13d5b1bd211ac155dfb9e2d5970d60 Mon Sep 17 00:00:00 2001 From: Archana Vaghasiya Date: Fri, 9 Jun 2023 10:31:25 +0000 Subject: [PATCH] [FIX] google_account: accessing the url without any post data When a user tries to access the URL directly, at that time the value of dictionary `kw` is not available. The error will be generated. Error : KeyError: 'state' This commit will prevent the traceback. sentry-3947033806 closes odoo/odoo#127162 X-original-commit: a05c8732440257eef31767b579793f3e5eb8a141 Signed-off-by: Achraf Ben Azzouz (abz) --- addons/google_account/controllers/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/google_account/controllers/main.py b/addons/google_account/controllers/main.py index 37d2234d056..243d686f22b 100644 --- a/addons/google_account/controllers/main.py +++ b/addons/google_account/controllers/main.py @@ -2,6 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. import json +from werkzeug.exceptions import BadRequest from odoo import http from odoo.http import request @@ -12,9 +13,11 @@ class GoogleAuth(http.Controller): @http.route('/google_account/authentication', type='http', auth="public") def oauth2callback(self, **kw): """ This route/function is called by Google when user Accept/Refuse the consent of Google """ - state = json.loads(kw['state']) + state = json.loads(kw.get('state', '{}')) service = state.get('s') url_return = state.get('f') + if (not service or (kw.get('code') and not url_return)): + raise BadRequest() if kw.get('code'): base_url = request.httprequest.url_root.strip('/') or request.env.user.get_base_url()