Skip to content

Commit f25f5d4

Browse files
committed
[ADD] auth_oauth_autologin
1 parent 480929d commit f25f5d4

File tree

17 files changed

+693
-0
lines changed

17 files changed

+693
-0
lines changed

auth_oauth_autologin/README.rst

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
====================
2+
Auth Oauth Autologin
3+
====================
4+
5+
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6+
!! This file is generated by oca-gen-addon-readme !!
7+
!! changes will be overwritten. !!
8+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9+
10+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
11+
:target: https://odoo-community.org/page/development-status
12+
:alt: Beta
13+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
14+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
15+
:alt: License: AGPL-3
16+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github
17+
:target: https://github.com/OCA/server-auth/tree/13.0/auth_oauth_autologin
18+
:alt: OCA/server-auth
19+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
20+
:target: https://translation.odoo-community.org/projects/server-auth-13-0/server-auth-13-0-auth_oauth_autologin
21+
:alt: Translate me on Weblate
22+
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
23+
:target: https://runbot.odoo-community.org/runbot/251/13.0
24+
:alt: Try me on Runbot
25+
26+
|badge1| |badge2| |badge3| |badge4| |badge5|
27+
28+
This modules implements an automatic redirection to the configured OAuth
29+
provider login page, if there is one and only one enabled. This effectively
30+
makes the regular Odoo login screen invisible in normal circumstances.
31+
32+
**Table of contents**
33+
34+
.. contents::
35+
:local:
36+
37+
Configuration
38+
=============
39+
40+
Configure OAuth providers in Settings > Users and Companies, and make sure
41+
there is only one that has the enabled flag set.
42+
43+
When this is done, users visiting the login page (/web/login), or being
44+
redirected to it because they are not authenticated yet, will be redirected to
45+
the identity provider login page instead of the regular Odoo login page.
46+
47+
Be aware that this module does not actively prevent users from authenticating
48+
with an login and password stored in the Odoo database. In some unusual
49+
circumstances (such as identity provider errors), the regular Odoo login may
50+
still be displayed. Securely disabling Odoo login and password, if needed,
51+
should be the topic of another module.
52+
53+
Also be aware that this has a possibly surprising effect on the logout menu
54+
item. When the user logs out of Odoo, a redirect to the login page happens. The
55+
login page in turn redirects to the identity provider, which, if the user is
56+
already authenticated there, automatically logs the user back in Odoo, in a
57+
fresh session.
58+
59+
Bug Tracker
60+
===========
61+
62+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-auth/issues>`_.
63+
In case of trouble, please check there if your issue has already been reported.
64+
If you spotted it first, help us smashing it by providing a detailed and welcomed
65+
`feedback <https://github.com/OCA/server-auth/issues/new?body=module:%20auth_oauth_autologin%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
66+
67+
Do not contact contributors directly about support or help with technical issues.
68+
69+
Credits
70+
=======
71+
72+
Authors
73+
~~~~~~~
74+
75+
* ACSONE SA/NV
76+
77+
Maintainers
78+
~~~~~~~~~~~
79+
80+
This module is maintained by the OCA.
81+
82+
.. image:: https://odoo-community.org/logo.png
83+
:alt: Odoo Community Association
84+
:target: https://odoo-community.org
85+
86+
OCA, or the Odoo Community Association, is a nonprofit organization whose
87+
mission is to support the collaborative development of Odoo features and
88+
promote its widespread use.
89+
90+
This module is part of the `OCA/server-auth <https://github.com/OCA/server-auth/tree/13.0/auth_oauth_autologin>`_ project on GitHub.
91+
92+
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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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": "13.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+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import main
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright 2021 ACSONE SA/NV
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
import werkzeug
5+
6+
from odoo import http
7+
8+
from odoo.addons.auth_oauth.controllers.main import OAuthLogin
9+
10+
11+
class OAuthAutoLogin(OAuthLogin):
12+
def _autologin_disabled(self):
13+
return (
14+
"no_autologin" in http.request.params
15+
or "oauth_error" in http.request.params
16+
or "error" in http.request.params
17+
)
18+
19+
def _autologin_link(self):
20+
providers = [p for p in self.list_providers() if p.get("autologin")]
21+
if len(providers) == 1:
22+
return providers[0].get("auth_link")
23+
24+
@http.route()
25+
def web_login(self, *args, **kw):
26+
response = super().web_login(*args, **kw)
27+
if not response.is_qweb:
28+
# presumably a redirect already
29+
return response
30+
if self._autologin_disabled():
31+
return response
32+
auth_link = self._autologin_link()
33+
if not auth_link:
34+
return response
35+
return werkzeug.utils.redirect(auth_link, 303)
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+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Configure OAuth providers in Settings > Users and Companies, and make sure
2+
there is one and only one that has both the enabled and automatic login flags
3+
set.
4+
5+
When this is done, users visiting the login page (/web/login), or being
6+
redirected to it because they are not authenticated yet, will be redirected to
7+
the identity provider login page instead of the regular Odoo login page.
8+
9+
Be aware that this module does not actively prevent users from authenticating
10+
with an login and password stored in the Odoo database. In some unusual
11+
circumstances (such as identity provider errors), the regular Odoo login may
12+
still be displayed. Securely disabling Odoo login and password, if needed,
13+
should be the topic of another module.
14+
15+
Also be aware that this has a possibly surprising effect on the logout menu
16+
item. When the user logs out of Odoo, a redirect to the login page happens. The
17+
login page in turn redirects to the identity provider, which, if the user is
18+
already authenticated there, automatically logs the user back in Odoo, in a
19+
fresh session.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This modules implements an automatic redirection to the configured OAuth
2+
provider login page, if there is one and only one enabled. This effectively
3+
makes the regular Odoo login screen invisible in normal circumstances.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
When configured, the Odoo login page redirects to the OAuth identify provider
2+
for authentication and login in Odoo. To access the regular Odoo login page,
3+
visit ``/web/login?no_autologin``.

0 commit comments

Comments
 (0)