Skip to content

Commit c8f3017

Browse files
committed
Merge PR #812 into 15.0
Signed-off-by sbidoul
2 parents 00854bf + 8ae5075 commit c8f3017

19 files changed

Lines changed: 817 additions & 0 deletions

File tree

auth_oauth_autologin/README.rst

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
====================
2+
Auth Oauth Autologin
3+
====================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:b39eab35ecf9f611b79515461079fc6ba8a002fc432515c31009b6c70eff01c3
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github
20+
:target: https://github.com/OCA/server-auth/tree/15.0/auth_oauth_autologin
21+
:alt: OCA/server-auth
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/server-auth-15-0/server-auth-15-0-auth_oauth_autologin
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-auth&target_branch=15.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This modules implements an automatic redirection to the configured OAuth
32+
provider login page, if there is one and only one enabled. This effectively
33+
makes the regular Odoo login screen invisible in normal circumstances.
34+
35+
**Table of contents**
36+
37+
.. contents::
38+
:local:
39+
40+
Configuration
41+
=============
42+
43+
Configure OAuth providers in Settings > Users and Companies, and make sure
44+
there is one and only one that has both the enabled and automatic login flags
45+
set.
46+
47+
When this is done, users visiting the login page (/web/login), or being
48+
redirected to it because they are not authenticated yet, will be redirected to
49+
the identity provider login page instead of the regular Odoo login page.
50+
51+
Be aware that this module does not actively prevent users from authenticating
52+
with an login and password stored in the Odoo database. In some unusual
53+
circumstances (such as identity provider errors), the regular Odoo login may
54+
still be displayed. Securely disabling Odoo login and password, if needed,
55+
should be the topic of another module.
56+
57+
Also be aware that this has a possibly surprising effect on the logout menu
58+
item. When the user logs out of Odoo, a redirect to the login page happens. The
59+
login page in turn redirects to the identity provider, which, if the user is
60+
already authenticated there, automatically logs the user back in Odoo, in a
61+
fresh session.
62+
63+
Usage
64+
=====
65+
66+
When configured, the Odoo login page redirects to the OAuth identify provider
67+
for authentication and login in Odoo. To access the regular Odoo login page,
68+
visit ``/web/login?no_autologin``.
69+
70+
Bug Tracker
71+
===========
72+
73+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-auth/issues>`_.
74+
In case of trouble, please check there if your issue has already been reported.
75+
If you spotted it first, help us to smash it by providing a detailed and welcomed
76+
`feedback <https://github.com/OCA/server-auth/issues/new?body=module:%20auth_oauth_autologin%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
77+
78+
Do not contact contributors directly about support or help with technical issues.
79+
80+
Credits
81+
=======
82+
83+
Authors
84+
~~~~~~~
85+
86+
* ACSONE SA/NV
87+
88+
Maintainers
89+
~~~~~~~~~~~
90+
91+
This module is maintained by the OCA.
92+
93+
.. image:: https://odoo-community.org/logo.png
94+
:alt: Odoo Community Association
95+
:target: https://odoo-community.org
96+
97+
OCA, or the Odoo Community Association, is a nonprofit organization whose
98+
mission is to support the collaborative development of Odoo features and
99+
promote its widespread use.
100+
101+
.. |maintainer-sbidoul| image:: https://github.com/sbidoul.png?size=40px
102+
:target: https://github.com/sbidoul
103+
:alt: sbidoul
104+
105+
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
106+
107+
|maintainer-sbidoul|
108+
109+
This module is part of the `OCA/server-auth <https://github.com/OCA/server-auth/tree/15.0/auth_oauth_autologin>`_ project on GitHub.
110+
111+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

auth_oauth_autologin/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import controllers
2+
from . import models
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2021 ACSONE SA/NV
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
{
5+
"name": "Auth Oauth Autologin",
6+
"summary": """
7+
Automatically redirect to the OAuth provider for login""",
8+
"version": "15.0.1.0.0",
9+
"license": "AGPL-3",
10+
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
11+
"maintainers": ["sbidoul"],
12+
"website": "https://github.com/OCA/server-auth",
13+
"depends": ["auth_oauth"],
14+
"data": ["views/auth_oauth_provider.xml"],
15+
"demo": [],
16+
"assets": {
17+
"web.assets_frontend": ["auth_oauth_autologin/static/src/js/web_login.js"]
18+
},
19+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import main
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2021 ACSONE SA/NV
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from urllib.parse import parse_qsl, urlparse
5+
6+
from odoo import http
7+
from odoo.http import request
8+
9+
from odoo.addons.auth_oauth.controllers.main import OAuthLogin
10+
11+
12+
class OAuthAutoLogin(OAuthLogin):
13+
def _autologin_disabled(self, redirect):
14+
url = urlparse(redirect)
15+
params = dict(parse_qsl(url.query, keep_blank_values=True))
16+
return "no_autologin" in params or "oauth_error" in params or "error" in params
17+
18+
def _autologin_link(self):
19+
providers = [p for p in self.list_providers() if p.get("autologin")]
20+
if len(providers) == 1:
21+
return providers[0].get("auth_link")
22+
23+
@http.route(
24+
"/auth/auto_login_redirect_link",
25+
type="json",
26+
auth="none",
27+
)
28+
def auto_login_redirect_link(self, *args, **kwargs):
29+
redirect = kwargs.get("redirect")
30+
if self._autologin_disabled(redirect):
31+
return False
32+
request.params["redirect"] = redirect
33+
auth_link = self._autologin_link()
34+
return auth_link
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * auth_oauth_autologin
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 16.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"Last-Translator: \n"
10+
"Language-Team: \n"
11+
"MIME-Version: 1.0\n"
12+
"Content-Type: text/plain; charset=UTF-8\n"
13+
"Content-Transfer-Encoding: \n"
14+
"Plural-Forms: \n"
15+
16+
#. module: auth_oauth_autologin
17+
#: model:ir.model.fields,field_description:auth_oauth_autologin.field_auth_oauth_provider__autologin
18+
msgid "Automatic Login"
19+
msgstr ""
20+
21+
#. module: auth_oauth_autologin
22+
#: model:ir.model.fields,help:auth_oauth_autologin.field_auth_oauth_provider__autologin
23+
msgid ""
24+
"If exactly one enabled provider has this checked, the login screen redirects"
25+
" to the OAuth provider."
26+
msgstr ""
27+
28+
#. module: auth_oauth_autologin
29+
#: model:ir.model,name:auth_oauth_autologin.model_auth_oauth_provider
30+
msgid "OAuth2 provider"
31+
msgstr ""

auth_oauth_autologin/i18n/fr.po

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * auth_oauth_autologin
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 16.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"PO-Revision-Date: 2025-01-23 09:02+0000\n"
10+
"Last-Translator: Vincent Hatakeyama <vincent+github@hatakeyama.fr>\n"
11+
"Language-Team: none\n"
12+
"Language: fr\n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: \n"
16+
"Plural-Forms: nplurals=2; plural=n > 1;\n"
17+
"X-Generator: Weblate 5.6.2\n"
18+
19+
#. module: auth_oauth_autologin
20+
#: model:ir.model.fields,field_description:auth_oauth_autologin.field_auth_oauth_provider__autologin
21+
msgid "Automatic Login"
22+
msgstr "Connexion automatique"
23+
24+
#. module: auth_oauth_autologin
25+
#: model:ir.model.fields,help:auth_oauth_autologin.field_auth_oauth_provider__autologin
26+
msgid ""
27+
"If exactly one enabled provider has this checked, the login screen redirects"
28+
" to the OAuth provider."
29+
msgstr ""
30+
"Si un seul fournisseur activé a cette case cochée, l’écran de connexion "
31+
"redirigera vers le fournisseur OAuth ."
32+
33+
#. module: auth_oauth_autologin
34+
#: model:ir.model,name:auth_oauth_autologin.model_auth_oauth_provider
35+
msgid "OAuth2 provider"
36+
msgstr "Fournisseur OAuth2"

auth_oauth_autologin/i18n/it.po

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * auth_oauth_autologin
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 16.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"PO-Revision-Date: 2025-01-25 16:06+0000\n"
10+
"Last-Translator: mymage <stefano.consolaro@mymage.it>\n"
11+
"Language-Team: none\n"
12+
"Language: it\n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: \n"
16+
"Plural-Forms: nplurals=2; plural=n != 1;\n"
17+
"X-Generator: Weblate 5.6.2\n"
18+
19+
#. module: auth_oauth_autologin
20+
#: model:ir.model.fields,field_description:auth_oauth_autologin.field_auth_oauth_provider__autologin
21+
msgid "Automatic Login"
22+
msgstr "Accesso automatico"
23+
24+
#. module: auth_oauth_autologin
25+
#: model:ir.model.fields,help:auth_oauth_autologin.field_auth_oauth_provider__autologin
26+
msgid ""
27+
"If exactly one enabled provider has this checked, the login screen redirects"
28+
" to the OAuth provider."
29+
msgstr ""
30+
"Se un solo provider abilitato ha selezionato questa opzione, la schermata di "
31+
"accesso reindirizza al provider OAuth."
32+
33+
#. module: auth_oauth_autologin
34+
#: model:ir.model,name:auth_oauth_autologin.model_auth_oauth_provider
35+
msgid "OAuth2 provider"
36+
msgstr "Provider OAuth2"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import auth_oauth_provider
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2021 ACSONE SA/NV <https://acsone.eu>
2+
# License: AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
3+
4+
from odoo import fields, models
5+
6+
7+
class AuthOauthProvider(models.Model):
8+
_inherit = "auth.oauth.provider"
9+
10+
autologin = fields.Boolean(
11+
string="Automatic Login",
12+
help=(
13+
"If exactly one enabled provider has this checked, "
14+
"the login screen redirects to the OAuth provider."
15+
),
16+
)

0 commit comments

Comments
 (0)