Files
odoo_source/addons/google_account/controllers/main.py
T
pedrambiria f8ce09276a [FIX] google_calendar: send the request URL for the redirect_uri
Before this commit: if a different `web.base.url` is set with
`web.base.url.freeze`, during the first synchronization of Google
calendar it will show a mismatch URL error. The problem is that we
send the `redirect_uri` based on the `web.base.url` in the
`_get_authorize_uri` function.

The solution is to use the request root URL instead.

opw-3175539

closes odoo/odoo#114482

X-original-commit: 8f94f2ec864bdb54e3deb9b853a2720c5c92f592
Signed-off-by: Arnaud Joset <arj@odoo.com>
Signed-off-by: Pedram Bi Ria (pebr) <pebr@odoo.com>
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2023-03-07 09:03:04 +01:00

36 lines
1.4 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import json
from odoo import http
from odoo.http import request
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'])
service = state.get('s')
url_return = state.get('f')
if kw.get('code'):
base_url = request.httprequest.url_root.strip('/') or request.env.user.get_base_url()
access_token, refresh_token, ttl = request.env['google.service']._get_google_tokens(
kw['code'],
service,
redirect_uri=f'{base_url}/google_account/authentication'
)
service_field = f'google_{service}_account_id'
if service_field in request.env.user:
getattr(request.env.user, service_field)._set_auth_tokens(access_token, refresh_token, ttl)
else:
raise Warning('No callback field for service <%s>' % service)
return request.redirect(url_return)
elif kw.get('error'):
return request.redirect("%s%s%s" % (url_return, "?error=", kw['error']))
else:
return request.redirect("%s%s" % (url_return, "?error=Unknown_error"))