Skip to content

Commit

Permalink
[ADD] auth_oidc_portal: Link OAuth provider on portal user create
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Rogos committed Nov 14, 2023
1 parent 6c78001 commit 7484abc
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 0 deletions.
35 changes: 35 additions & 0 deletions auth_oidc_portal/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
**This file is going to be generated by oca-gen-addon-readme.**

*Manual changes will be overwritten.*

Please provide content in the ``readme`` directory:

* **DESCRIPTION.rst** (required)
* INSTALL.rst (optional)
* CONFIGURE.rst (optional)
* **USAGE.rst** (optional, highly recommended)
* DEVELOP.rst (optional)
* ROADMAP.rst (optional)
* HISTORY.rst (optional, recommended)
* **CONTRIBUTORS.rst** (optional, highly recommended)
* CREDITS.rst (optional)

Content of this README will also be drawn from the addon manifest,
from keys such as name, authors, maintainers, development_status,
and license.

A good, one sentence summary in the manifest is also highly recommended.


Automatic changelog generation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`HISTORY.rst` can be auto generated using `towncrier <https://pypi.org/project/towncrier>`_.

Just put towncrier compatible changelog fragments into `readme/newsfragments`
and the changelog file will be automatically generated and updated when a new fragment is added.

Please refer to `towncrier` documentation to know more.

NOTE: the changelog will be automatically generated when using `/ocabot merge $option`.
If you need to run it manually, refer to `OCA/maintainer-tools README <https://github.com/OCA/maintainer-tools>`_.
3 changes: 3 additions & 0 deletions auth_oidc_portal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import wizard
19 changes: 19 additions & 0 deletions auth_oidc_portal/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2023 glueckkanja AG (https://www.glueckkanja.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Authentication OpenID Connect on Portal",
"summary": "Allow portal users to login through OpenID Connect Provider",
"version": "16.0.1.0.0",
"author": ("CRogos (glueckkanja AG), Odoo Community Association (OCA)"),
"license": "AGPL-3",
"maintainers": ["CRogos"],
"category": "hr",
"website": "https://github.com/OCA/server-auth",
"depends": ["auth_oidc", "portal"],
"data": [
"wizard/portal_wizard_views.xml",
],
"auto_install": False,
"installable": True,
}
3 changes: 3 additions & 0 deletions auth_oidc_portal/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Select a OAuth provider for a portal user. The email address is also used as oauth_id and the first active OAuth provider is selected as default when creating a new portal user.

.. image:: ..static/description/oauth-portal-user.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions auth_oidc_portal/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# See LICENSE file for full copyright and licensing details.

from . import portal_wizard
29 changes: 29 additions & 0 deletions auth_oidc_portal/wizard/portal_wizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from odoo import fields, models
from odoo.tools import email_normalize


class PortalWizardUser(models.TransientModel):
# A model to configure users in the portal wizard.

_inherit = "portal.wizard.user"

def _get_default_provider(self):
return self.env["auth.oauth.provider"].search([("enabled", "=", True)], limit=1)

oauth_provider_id = fields.Many2one(
"auth.oauth.provider",
string="OAuth Provider",
default=_get_default_provider,
domain=[("enabled", "=", True)],
)

def _create_user(self):
# create a new user for wizard_user.partner_id
# :returns record of res.users

user = super(PortalWizardUser, self)._create_user()
if self.oauth_provider_id:
user.oauth_uid = email_normalize(self.email).lower()
user.oauth_provider_id = self.oauth_provider_id

return user
14 changes: 14 additions & 0 deletions auth_oidc_portal/wizard/portal_wizard_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<!-- wizard view -->
<record id="wizard_view" model="ir.ui.view">
<field name="name">Grant oidc portal access</field>
<field name="model">portal.wizard</field>
<field name="inherit_id" ref="portal.wizard_view" />
<field name="arch" type="xml">
<field name="login_date" position="before">
<field name="oauth_provider_id" />
</field>
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions setup/auth_oidc_portal/odoo/addons/auth_oidc_portal
6 changes: 6 additions & 0 deletions setup/auth_oidc_portal/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 7484abc

Please sign in to comment.