mirror of
https://github.com/bringout/oca-ocb-accounting.git
synced 2026-04-21 06:02:03 +02:00
Initial commit: Accounting packages
This commit is contained in:
commit
4ef34c2317
2661 changed files with 1709616 additions and 0 deletions
|
|
@ -0,0 +1,38 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# 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
|
||||
|
||||
|
||||
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.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()
|
||||
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:
|
||||
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"))
|
||||
Loading…
Add table
Add a link
Reference in a new issue