From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/microsoft_account/controllers/main.py | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 addons/microsoft_account/controllers/main.py (limited to 'addons/microsoft_account/controllers/main.py') diff --git a/addons/microsoft_account/controllers/main.py b/addons/microsoft_account/controllers/main.py new file mode 100644 index 00000000..5256f82d --- /dev/null +++ b/addons/microsoft_account/controllers/main.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import json +from werkzeug.utils import redirect + +from odoo import http, registry +from odoo.http import request + + +class MicrosoftAuth(http.Controller): + + @http.route('/microsoft_account/authentication', type='http', auth="public") + def oauth2callback(self, **kw): + """ This route/function is called by Microsoft when user Accept/Refuse the consent of Microsoft """ + state = json.loads(kw['state']) + dbname = state.get('d') + service = state.get('s') + url_return = state.get('f') + + with registry(dbname).cursor() as cr: + if kw.get('code'): + access_token, refresh_token, ttl = request.env['microsoft.service']._get_microsoft_tokens(kw['code'], service) + request.env.user._set_microsoft_auth_tokens(access_token, refresh_token, ttl) + return redirect(url_return) + elif kw.get('error'): + return redirect("%s%s%s" % (url_return, "?error=", kw['error'])) + else: + return redirect("%s%s" % (url_return, "?error=Unknown_error")) -- cgit v1.2.3