[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) <abz@odoo.com>
This commit is contained in:
Archana Vaghasiya
2023-07-06 15:03:42 +02:00
parent 200ccf1b10
commit e3fd75015c
+4 -1
View File
@@ -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()