-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11316 from camptocamp/openid-connect-GSGGR-152
Add OpenID connect support
- Loading branch information
Showing
21 changed files
with
1,024 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
commons/c2cgeoportal_commons/alembic/static/aa41e9613256_wip_add_openid_connect_support.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Copyright (c) 2024, Camptocamp SA | ||
# All rights reserved. | ||
|
||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
|
||
# 1. Redistributions of source code must retain the above copyright notice, this | ||
# list of conditions and the following disclaimer. | ||
# 2. Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
|
||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
# The views and conclusions contained in the software and documentation are those | ||
# of the authors and should not be interpreted as representing official policies, | ||
# either expressed or implied, of the FreeBSD Project. | ||
|
||
""" | ||
Add OpenID connect support. | ||
Revision ID: aa41e9613256 | ||
Revises: 910b4ca53b68 | ||
Create Date: 2024-08-30 15:56:31.163378 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from c2c.template.config import config | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "aa41e9613256" | ||
down_revision = "910b4ca53b68" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
"""Upgrade.""" | ||
staticschema = config["schema_static"] | ||
|
||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_index(op.f("ix_main_static_user_email"), "user", ["email"], unique=False, schema=staticschema) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
"""Downgrade.""" | ||
staticschema = config["schema_static"] | ||
|
||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_index(op.f("ix_main_static_user_email"), table_name="user", schema=staticschema) | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
OpenID Connect | ||
~~~~~~~~~~~~~~ | ||
|
||
We can configure an OpenID connect service as an SSO (Single Sign-On) provider for our application. This allows users to log in to our application using their OpenID Connect credentials. | ||
|
||
We use [OpenID Connect Discovery 1.0](https://openid.net/specs/openid-connect-discovery-1_0.html) with an Authorization Code Flow from [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html), with PKCE (Proof Key for Code Exchange, RFC 7636). | ||
|
||
.. mermaid:: | ||
|
||
sequenceDiagram | ||
actor User | ||
participant Browser | ||
participant Geoportal | ||
participant IAM | ||
Geoportal->>IAM: discovery endpoint | ||
|
||
User->>+Browser: Login | ||
Browser->>+Geoportal: Login | ||
Geoportal->>-Browser: redirect | ||
Browser->>+IAM: authorization endpoint | ||
IAM->>-Browser: redirect | ||
Browser->>+Geoportal: callback endpoint | ||
Geoportal->>IAM: token endpoint | ||
opt on using user info instead of jwt token | ||
Geoportal->>IAM: userinfo endpoint | ||
end | ||
Geoportal->>-Browser: authentication data in cookie | ||
Browser->>-User: Reload | ||
|
||
Browser->>+Geoportal: any auth endpoint | ||
opt on token expiry | ||
Geoportal->>IAM: refresh token endpoint | ||
end | ||
Geoportal->>-Browser: response | ||
|
||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
Authentication provider | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
If we want to use OpenID Connect as an authentication provider, we need to set the following configuration in our ``vars.yaml`` file: | ||
|
||
.. code:: yaml | ||
vars: | ||
authentication: | ||
openid_connect: | ||
enabled: true | ||
url: <the service URL> | ||
client_id: <the client application ID> | ||
user_info_fields: | ||
username: name # Default value | ||
email: email # Default value | ||
With that the user will be create in the database at the first login, and the access right will be set in the GeoMapFish database. | ||
The user correspondence will be done on the email field. | ||
|
||
~~~~~~~~~~~~~~~~~~~~~~ | ||
Authorization provider | ||
~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
If we want to use OpenID Connect as an authorization provider, we need to set the following configuration in our ``vars.yaml`` file: | ||
|
||
.. code:: yaml | ||
vars: | ||
authentication: | ||
openid_connect: | ||
enabled: true | ||
url: <the service URL> | ||
client_id: <the client application ID> | ||
provide_roles: true | ||
user_info_fields: | ||
username: name # Default value | ||
email: email # Default value | ||
settings_role: settings_role | ||
roles: roles | ||
With that the user will not be in the database only the roles will be set in the GeoMapFish database. | ||
|
||
~~~~~~~~~~~~~ | ||
Other options | ||
~~~~~~~~~~~~~ | ||
|
||
``client_secret``: The secret of the client. | ||
|
||
``trusted_audiences``: The list of trusted audiences, if the token audience is not in this list, the token will be rejected. | ||
|
||
``scopes``: The list of scopes to request, default is [``openid``, ``profile``, ``email``]. | ||
|
||
``query_user_info``: If ``true``, the user info will be requested instead if using the ``id_token``, default is false. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.