diff --git a/auth_oauth_login_field/README.rst b/auth_oauth_login_field/README.rst new file mode 100644 index 0000000000..d79e3ff21f --- /dev/null +++ b/auth_oauth_login_field/README.rst @@ -0,0 +1,73 @@ +====================== +Auth Oauth Login Field +====================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:fc5382a243d153a8cb6f66f54f2153c2655b737645f64385e65015f42a5e4d60 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github + :target: https://github.com/OCA/server-auth/tree/18.0/auth_oauth_login_field + :alt: OCA/server-auth +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-auth-18-0/server-auth-18-0-auth_oauth_login_field + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/server-auth&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Handle the ``login`` field from the JWT token in OAuth signup. This is +useful when you need to create users where the ``login`` field is +different from the ``email`` field. + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* ACSONE SA/NV + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/server-auth `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/auth_oauth_login_field/__init__.py b/auth_oauth_login_field/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/auth_oauth_login_field/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/auth_oauth_login_field/__manifest__.py b/auth_oauth_login_field/__manifest__.py new file mode 100644 index 0000000000..fcebc8b6ad --- /dev/null +++ b/auth_oauth_login_field/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Auth Oauth Login Field", + "summary": """Handle the login field in OAuth signup""", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "maintainers": ["sbidoul"], + "website": "https://github.com/OCA/server-auth", + "depends": [ + "auth_oauth", + ], + "data": [], + "demo": [], +} diff --git a/auth_oauth_login_field/models/__init__.py b/auth_oauth_login_field/models/__init__.py new file mode 100644 index 0000000000..8835165330 --- /dev/null +++ b/auth_oauth_login_field/models/__init__.py @@ -0,0 +1 @@ +from . import res_users diff --git a/auth_oauth_login_field/models/res_users.py b/auth_oauth_login_field/models/res_users.py new file mode 100644 index 0000000000..9c22216cfa --- /dev/null +++ b/auth_oauth_login_field/models/res_users.py @@ -0,0 +1,14 @@ +# Copyright 2021 ACSONE SA/NV + +from odoo import api, models + + +class ResUsers(models.Model): + _inherit = "res.users" + + @api.model + def _generate_signup_values(self, provider, validation, params): + res = super()._generate_signup_values(provider, validation, params) + if "login" in validation: + res["login"] = validation["login"] + return res diff --git a/auth_oauth_login_field/pyproject.toml b/auth_oauth_login_field/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/auth_oauth_login_field/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/auth_oauth_login_field/readme/DESCRIPTION.md b/auth_oauth_login_field/readme/DESCRIPTION.md new file mode 100644 index 0000000000..f3b772ec2b --- /dev/null +++ b/auth_oauth_login_field/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +Handle the `login` field from the JWT token in OAuth signup. This is useful when +you need to create users where the `login` field is different from the `email` +field. diff --git a/auth_oauth_login_field/readme/USAGE.md b/auth_oauth_login_field/readme/USAGE.md new file mode 100644 index 0000000000..2a16487265 --- /dev/null +++ b/auth_oauth_login_field/readme/USAGE.md @@ -0,0 +1,3 @@ +If a `login` field is present in the token, it will be used as `login` field on +user signup. When using the ``auth_oidc`` module, the Token Map can be populated +like this, for instance: ``preferred_username:login``. diff --git a/auth_oauth_login_field/static/description/index.html b/auth_oauth_login_field/static/description/index.html new file mode 100644 index 0000000000..155bdae37b --- /dev/null +++ b/auth_oauth_login_field/static/description/index.html @@ -0,0 +1,418 @@ + + + + + +Auth Oauth Login Field + + + +
+

Auth Oauth Login Field

+ + +

Beta License: AGPL-3 OCA/server-auth Translate me on Weblate Try me on Runboat

+

Handle the login field from the JWT token in OAuth signup. This is +useful when you need to create users where the login field is +different from the email field.

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/server-auth project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/auth_oauth_login_field/tests/__init__.py b/auth_oauth_login_field/tests/__init__.py new file mode 100644 index 0000000000..f03c5aecd0 --- /dev/null +++ b/auth_oauth_login_field/tests/__init__.py @@ -0,0 +1 @@ +from . import test_generate_signup_values diff --git a/auth_oauth_login_field/tests/test_generate_signup_values.py b/auth_oauth_login_field/tests/test_generate_signup_values.py new file mode 100644 index 0000000000..69a84879f9 --- /dev/null +++ b/auth_oauth_login_field/tests/test_generate_signup_values.py @@ -0,0 +1,48 @@ +from odoo.tests.common import TransactionCase + + +class TestGenerateSignupValues(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.user = cls.env["res.users"].create( + {"name": "Test user", "login": "testuser"} + ) + + def test_generate_signup_values_no_login(self): + provider_id = 1 + name = "Toto Le Héro" + email = "toto@example.com" + validation = { + "user_id": "1234567890", + "name": name, + "email": email, + } + params = { + "access_token": "thetoken", + } + res = self.user._generate_signup_values(provider_id, validation, params) + self.assertEqual(res["name"], name) + # Odoo's auth_oauth module sets login = email + self.assertTrue(res["login"] == res["email"]) + + def test_generate_signup_values_login(self): + provider_id = 1 + name = "Toto Le Héro" + email = "toto.externe@example.com" + login = "toto@example.com" + validation = { + "user_id": "1234567890", + "name": name, + "email": email, + "login": login, + } + params = { + "access_token": "thetoken", + } + res = self.user._generate_signup_values(provider_id, validation, params) + self.assertEqual(res["name"], name) + # With this module we can have a different login than email + self.assertTrue(res["login"] != res["email"]) + self.assertEqual(res["login"], login) + self.assertEqual(res["email"], email)