Files
odoo_source/addons/google_account/controllers/main.py
T
Jeremy Kersten 75e1d93344 [IMP] google_calendar: rename google_cal[endar]_account_id
Rename from google_cal_account_id to google_calendar_account_id, to have
the complete 'service' name into the field and allow to use it from a
generic way in oauth2callback from google_account e.g.

task-2497212
pr-95744

closes odoo/odoo#95744

Related: odoo/upgrade#3673
Signed-off-by: Christophe Simonis <chs@odoo.com>
2022-08-10 14:43:02 +02: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.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"))