Skip to content

Commit

Permalink
📝[#114] update setup config docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Coperh committed Nov 22, 2024
1 parent 25feb25 commit 08b8d76
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 38 deletions.
45 changes: 27 additions & 18 deletions docs/setup_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,50 +22,59 @@ put the ``AdminOIDCConfigurationStep`` in your django-setup-configuration steps:
SETUP_CONFIGURATION_STEPS = [
...
"mozilla_django_oidc_db.setup_config.AdminOIDCConfigurationStep",
"mozilla_django_oidc_db.setup_configuration.steps.AdminOIDCConfigurationStep",
...
]
Configuration Settings:
Configuration Settings YAML:
=======================

* ``OIDC_DB_CONFIG_ENABLE``: enable setup configuration step

The setup configuration admin must contain the following base keys to use setup configuration:

* ``OIDC_DB_CONFIG_ENABLE``: enable setup configuration step boolean

* ``OIDC_DB_SETUP_CONFIG_ADMIN_AUTH``: Dictionary that maps OIDC fields to their values.


Example:

.. code-block:: python
.. code-block:: yaml
OTHER_ENABLE: True
OTHER_CONFiG:
...
OIDC_DB_CONFIG_ENABLE: True
OIDC_DB_SETUP_CONFIG_ADMIN_AUTH:
oidc_rp_client_id: client-id
oidc_rp_client_secret: secret
endpoint_config:
oidc_op_discovery_endpoint: https://keycloak.local/protocol/openid-connect/
...
OIDC_DB_SETUP_CONFIG_ADMIN_AUTH = {
"oidc_rp_client_id": "client-id",
"oidc_rp_client_secret": "secret",
"oidc_op_discovery_endpoint": "https://keycloak.local/protocol/openid-connect/",
}
Any field from the ``OpenIDConnectConfig`` can be added to ``OIDC_DB_SETUP_CONFIG_ADMIN_AUTH`` (except endpoints, see below)

Required Fields:
""""""""""""""""


* ``oidc_rp_client_id``: OpenID Connect client ID from the OIDC Provider.
* ``oidc_rp_client_secret``: OpenID Connect secret from the OIDC Provider.
* ``endpoint_config``: Dictionary containing endpoint information
* ``oidc_op_discovery_endpoint``: URL of your OpenID Connect provider discovery endpoint ending with a slash (`.well-known/...` will be added automatically).
**OR**
* ``oidc_op_authorization_endpoint``: URL of your OpenID Connect provider authorization endpoint
* ``oidc_op_token_endpoint``: URL of your OpenID Connect provider token endpoint
* ``oidc_op_user_endpoint``: URL of your OpenID Connect provider userinfo endpoint

The discovery endpoint can be configured to automatically fetch the other endpoints. Otherwise the endpoints must be set individually.

* ``oidc_op_discovery_endpoint``: URL of your OpenID Connect provider discovery endpoint ending with a slash (`.well-known/...` will be added automatically).

**OR**

* ``oidc_op_authorization_endpoint``: URL of your OpenID Connect provider authorization endpoint
* ``oidc_op_token_endpoint``: URL of your OpenID Connect provider token endpoint
* ``oidc_op_user_endpoint``: URL of your OpenID Connect provider userinfo endpoint

The endpoints must be provided in the ``endpoint_config`` dictionary.
You can add the discovery endpoint to automatically fetch the other endpoints. Otherwise the endpoints must be specified individually:


Optional Fields:
""""""""""""""""
All the following keys are placed in the ``OIDC_DB_SETUP_CONFIG_ADMIN_AUTH`` dictionary.

* ``oidc_op_jwks_endpoint``: URL of your OpenID Connect provider JSON Web Key Set endpoint.
Required if ``RS256`` is used as signing algorithm. No default value.
Expand Down
4 changes: 2 additions & 2 deletions mozilla_django_oidc_db/setup_configuration/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class AdminOIDCConfigurationStep(BaseConfigurationStep[AdminOIDCConfigurationMod

verbose_name = "Configuration for admin login via OpenID Connect"
config_model = AdminOIDCConfigurationModel
namespace = "ADMIN_OIDC"
enable_setting = "ADMIN_OIDC_CONFIG_ENABLE"
namespace = "OIDC_DB_SETUP_CONFIG_ADMIN_AUTH"
enable_setting = "OIDC_DB_CONFIG_ENABLE"

def execute(self, model: AdminOIDCConfigurationModel) -> None:

Expand Down
1 change: 0 additions & 1 deletion testapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@

INSTALLED_APPS += ["django_setup_configuration"]

OIDC_DB_CONFIG_ENABLE = True
SETUP_CONFIGURATION_STEPS = [
"mozilla_django_oidc_db.setup_configuration.steps.AdminOIDCConfigurationStep",
]
Expand Down
4 changes: 2 additions & 2 deletions tests/setupconfig/files/defaults.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ADMIN_OIDC_CONFIG_ENABLE: True
ADMIN_OIDC:
OIDC_DB_CONFIG_ENABLE: True
OIDC_DB_SETUP_CONFIG_ADMIN_AUTH:
oidc_rp_client_id: client-id
oidc_rp_client_secret: secret
endpoint_config:
Expand Down
4 changes: 2 additions & 2 deletions tests/setupconfig/files/discovery.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ADMIN_OIDC_CONFIG_ENABLE: True
ADMIN_OIDC:
OIDC_DB_CONFIG_ENABLE: True
OIDC_DB_SETUP_CONFIG_ADMIN_AUTH:
oidc_rp_client_id: testid
oidc_rp_client_secret: 7DB3KUAAizYCcmZufpHRVOcD0TOkNO3I
endpoint_config:
Expand Down
4 changes: 2 additions & 2 deletions tests/setupconfig/files/discovery_disabled.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ADMIN_OIDC_CONFIG_ENABLE: False
ADMIN_OIDC:
OIDC_DB_CONFIG_ENABLE: False
OIDC_DB_SETUP_CONFIG_ADMIN_AUTH:
oidc_rp_client_id: testid
oidc_rp_client_secret: 7DB3KUAAizYCcmZufpHRVOcD0TOkNO3I
endpoint_config:
Expand Down
4 changes: 2 additions & 2 deletions tests/setupconfig/files/empty.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ADMIN_OIDC_CONFIG_ENABLE: True
ADMIN_OIDC: {}
OIDC_DB_CONFIG_ENABLE: True
OIDC_DB_SETUP_CONFIG_ADMIN_AUTH: {}
4 changes: 2 additions & 2 deletions tests/setupconfig/files/full_setup.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ADMIN_OIDC_CONFIG_ENABLE: True
ADMIN_OIDC:
OIDC_DB_CONFIG_ENABLE: True
OIDC_DB_SETUP_CONFIG_ADMIN_AUTH:
oidc_rp_client_id: client-id
oidc_rp_client_secret: secret
oidc_rp_scopes_list:
Expand Down
4 changes: 2 additions & 2 deletions tests/setupconfig/files/partial_endpoints.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ADMIN_OIDC_CONFIG_ENABLE: True
ADMIN_OIDC:
OIDC_DB_CONFIG_ENABLE: True
OIDC_DB_SETUP_CONFIG_ADMIN_AUTH:
oidc_rp_client_id: client-id
oidc_rp_client_secret: secret
endpoint_config:
Expand Down
10 changes: 5 additions & 5 deletions tests/setupconfig/test_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def test_required_settings():
command_error.value
)

assert "ADMIN_OIDC.oidc_rp_client_id" in str(command_error.value)
assert "ADMIN_OIDC.oidc_rp_client_secret" in str(command_error.value)
assert "ADMIN_OIDC.endpoint_config" in str(command_error.value)
assert "OIDC_DB_SETUP_CONFIG_ADMIN_AUTH.oidc_rp_client_id" in str(command_error.value)
assert "OIDC_DB_SETUP_CONFIG_ADMIN_AUTH.oidc_rp_client_secret" in str(command_error.value)
assert "OIDC_DB_SETUP_CONFIG_ADMIN_AUTH.endpoint_config" in str(command_error.value)

config = OpenIDConnectConfig.get_solo()
assert not config.enabled
Expand All @@ -111,10 +111,10 @@ def test_partial_endpoints_provided():
command_error.value
)

assert "ADMIN_OIDC.endpoint_config.all.oidc_op_token_endpoint" in str(
assert "OIDC_DB_SETUP_CONFIG_ADMIN_AUTH.endpoint_config.all.oidc_op_token_endpoint" in str(
command_error.value
)
assert "ADMIN_OIDC.endpoint_config.all.oidc_op_user_endpoint" in str(
assert "OIDC_DB_SETUP_CONFIG_ADMIN_AUTH.endpoint_config.all.oidc_op_user_endpoint" in str(
command_error.value
)

Expand Down

0 comments on commit 08b8d76

Please sign in to comment.