-
-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by sbidoul
- Loading branch information
Showing
6 changed files
with
62 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,32 @@ | ||
# Copyright 2021 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import werkzeug | ||
from urllib.parse import parse_qsl, urlparse | ||
|
||
from odoo import http | ||
from odoo.http import request | ||
|
||
from odoo.addons.auth_oauth.controllers.main import OAuthLogin | ||
|
||
|
||
class OAuthAutoLogin(OAuthLogin): | ||
def _autologin_disabled(self): | ||
return ( | ||
"no_autologin" in http.request.params | ||
or "oauth_error" in http.request.params | ||
or "error" in http.request.params | ||
) | ||
def _autologin_disabled(self, redirect): | ||
url = urlparse(redirect) | ||
params = dict(parse_qsl(url.query)) | ||
return "no_autologin" in params or "oauth_error" in params or "error" in params | ||
|
||
def _autologin_link(self): | ||
providers = [p for p in self.list_providers() if p.get("autologin")] | ||
if len(providers) == 1: | ||
return providers[0].get("auth_link") | ||
|
||
@http.route() | ||
def web_login(self, *args, **kw): | ||
response = super().web_login(*args, **kw) | ||
if not response.is_qweb: | ||
# presumably a redirect already | ||
return response | ||
if self._autologin_disabled(): | ||
return response | ||
@http.route( | ||
"/auth/auto_login_redirect_link", type="json", auth="none", | ||
) | ||
def auto_login_redirect_link(self, *args, **kwargs): | ||
redirect = kwargs.get("redirect") | ||
if self._autologin_disabled(redirect): | ||
return False | ||
request.params["redirect"] = redirect | ||
auth_link = self._autologin_link() | ||
if not auth_link: | ||
return response | ||
return werkzeug.utils.redirect(auth_link, 303) | ||
return auth_link |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
odoo.define("auth_oauth_autologin.redirect", function(require) { | ||
"use strict"; | ||
|
||
var publicWidget = require("web.public.widget"); | ||
|
||
publicWidget.registry.authOauthAutologinWidget = publicWidget.Widget.extend({ | ||
selector: ".oe_login_form", | ||
|
||
/** | ||
* @override | ||
*/ | ||
start: function() { | ||
const def = this._super.apply(this, arguments); | ||
let url = window.location.href; | ||
if (url.includes("/web/login")) { | ||
url = url.replace("/web/login", "/web"); | ||
} | ||
this._rpc({ | ||
route: "/auth/auto_login_redirect_link", | ||
params: { | ||
redirect: url, | ||
}, | ||
}).then(function(result) { | ||
if (result) { | ||
window.location = result; | ||
} | ||
}); | ||
return def; | ||
}, | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<template | ||
id="assets_frontend" | ||
name="auth_oauth_autologin assets" | ||
inherit_id="web.assets_frontend" | ||
> | ||
<xpath expr="." position="inside"> | ||
<script | ||
type="text/javascript" | ||
src="/auth_oauth_autologin/static/src/js/web_login.js" | ||
/> | ||
</xpath> | ||
</template> | ||
</odoo> |