Skip to content

Commit 4e095ae

Browse files
committed
[4777][ADD] auth_oauth_enforced
1 parent 97c5c01 commit 4e095ae

File tree

14 files changed

+629
-0
lines changed

14 files changed

+629
-0
lines changed

auth_oauth_enforced/README.rst

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
======================
2+
Auth OAuth Enforced
3+
======================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:6e65a7f2af3e5fed27a05a5fbe038b72e403595474a8b896c2d2bb836faf654f
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-qrtl%2Faxls--custom-lightgray.png?logo=github
20+
:target: https://github.com/qrtl/thc-oca/tree/16.0/auth_oauth_enforced
21+
:alt: qrtl/thc-oca
22+
23+
|badge1| |badge2| |badge3|
24+
25+
This module controls login methods by email domain, requiring OAuth for
26+
specified domains, as defined in company settings.
27+
28+
**Table of contents**
29+
30+
.. contents::
31+
:local:
32+
33+
Bug Tracker
34+
===========
35+
36+
Bugs are tracked on `GitHub Issues <https://github.com/qrtl/thc-oca/issues>`_.
37+
In case of trouble, please check there if your issue has already been reported.
38+
If you spotted it first, help us to smash it by providing a detailed and welcomed
39+
`feedback <https://github.com/qrtl/thc-oca/issues/new?body=module:%20auth_oauth_enforced%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
40+
41+
Do not contact contributors directly about support or help with technical issues.
42+
43+
Credits
44+
=======
45+
46+
Authors
47+
-------
48+
49+
* Quartile Limited
50+
51+
Maintainers
52+
-----------
53+
54+
This module is part of the `qrtl/thc-oca <https://github.com/qrtl/thc-oca/tree/16.0/auth_oauth_enforced>`_ project on GitHub.
55+
56+
You are welcome to contribute.

auth_oauth_enforced/__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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2024 Quartile Limited (https://www.quartile.co)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
3+
{
4+
"name": "Auth OAuth Enforced",
5+
"version": "16.0.1.0.0",
6+
"author": "Quartile Limited, Odoo Community Association (OCA)",
7+
"website": "https://www.quartile.co",
8+
"category": "Tools",
9+
"license": "AGPL-3",
10+
"depends": ["auth_oauth", "auth_signup"],
11+
"data": [
12+
"views/res_company_views.xml",
13+
],
14+
"installable": True,
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import main
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 2024 Quartile Limited (https://www.quartile.co)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
3+
4+
5+
from odoo import _, http
6+
from odoo.http import request
7+
8+
from odoo.addons.auth_signup.controllers import main
9+
from odoo.addons.web.controllers import home
10+
11+
12+
class Home(home.Home):
13+
@http.route("/web/login", type="http", auth="none")
14+
def web_login(self, redirect=None, **kw):
15+
# Only proceed if it's a POST request and 'login' is provided
16+
if request.httprequest.method != "POST" or "login" not in kw:
17+
return super().web_login(redirect=redirect, **kw)
18+
login = kw["login"]
19+
user = request.env["res.users"].sudo().search([("login", "=", login)], limit=1)
20+
# Only proceed if 'force_oauth_domains' is set for the company
21+
if user._is_allowed_password_login():
22+
return super().web_login(redirect=redirect, **kw)
23+
# User is not allowed to login with a password, prompt for OAuth login
24+
providers = self.list_providers()
25+
values = request.params
26+
values["error"] = _(
27+
"You are not allowed to login with password. Please use OAuth login."
28+
)
29+
values["providers"] = providers
30+
return request.render("web.login", values)
31+
32+
33+
class CustomAuthSignup(main.AuthSignupHome):
34+
@http.route(
35+
"/web/reset_password", type="http", auth="public", website=True, sitemap=False
36+
)
37+
def web_auth_reset_password(self, *args, **kw):
38+
qcontext = self.get_auth_signup_qcontext()
39+
login = qcontext.get("login", request.params.get("login"))
40+
password = qcontext.get("password")
41+
confirm_password = qcontext.get("confirm_password")
42+
if not login or not password or not confirm_password:
43+
return super().web_auth_reset_password(*args, **kw)
44+
user = request.env["res.users"].sudo().search([("login", "=", login)], limit=1)
45+
if user._is_allowed_password_login():
46+
return super().web_auth_reset_password(*args, **kw)
47+
qcontext["error"] = _(
48+
"You are not allowed to login with password. Please use OAuth login."
49+
)
50+
return request.render("auth_signup.reset_password", qcontext)

auth_oauth_enforced/i18n/ja.po

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * auth_oauth_enforced
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 16.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"POT-Creation-Date: 2024-03-01 09:10+0000\n"
10+
"PO-Revision-Date: 2024-03-01 09:10+0000\n"
11+
"Last-Translator: \n"
12+
"Language-Team: \n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: \n"
16+
"Plural-Forms: \n"
17+
18+
#. module: auth_oauth_enforced
19+
#: model:ir.model,name:auth_oauth_enforced.model_res_company
20+
msgid "Companies"
21+
msgstr "会社"
22+
23+
#. module: auth_oauth_enforced
24+
#: model:ir.model.fields,help:auth_oauth_enforced.field_res_company__force_oauth_domains
25+
msgid "Fill in the domains, separated by commas."
26+
msgstr "カンマで区切ってドメインを入力"
27+
28+
#. module: auth_oauth_enforced
29+
#: model:ir.model.fields,field_description:auth_oauth_enforced.field_res_company__force_oauth_domains
30+
msgid "Force OAuth Domains"
31+
msgstr "OAuth強制ドメイン"
32+
33+
#. module: auth_oauth_enforced
34+
#: model:ir.model,name:auth_oauth_enforced.model_res_users
35+
msgid "User"
36+
msgstr "ユーザ"
37+
38+
#. module: auth_oauth_enforced
39+
#. odoo-python
40+
#: code:addons/auth_oauth_enforced/controllers/main.py:0
41+
#: code:addons/auth_oauth_enforced/controllers/main.py:0
42+
#, python-format
43+
msgid "You are not allowed to login with password. Please use OAuth login."
44+
msgstr "あなたはパスワードログインを許可されていません。OAuthログインを使用してください。"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import res_company
2+
from . import res_users
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright 2024 Quartile Limited (https://www.quartile.co)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
3+
4+
from odoo import fields, models
5+
6+
7+
class ResCompany(models.Model):
8+
_inherit = "res.company"
9+
10+
force_oauth_domains = fields.Char(
11+
"Force OAuth Domains", help="Fill in the domains, separated by commas."
12+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2024 Quartile Limited (https://www.quartile.co)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
3+
4+
from odoo import api, models
5+
6+
7+
class ResUsers(models.Model):
8+
_inherit = "res.users"
9+
10+
@api.model
11+
def _is_allowed_password_login(self):
12+
force_domains = self.company_id.force_oauth_domains
13+
if not force_domains:
14+
return True
15+
force_domains_list = [domain.strip() for domain in force_domains.split(",")]
16+
return not any(self.login.endswith(domain) for domain in force_domains_list)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This module controls login methods by email domain, requiring OAuth for
2+
specified domains, as defined in company settings.

0 commit comments

Comments
 (0)