Skip to content

Commit

Permalink
🚧 generate setupconfig yaml example
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbal committed Jan 9, 2025
1 parent c632590 commit 507d6b4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 25 deletions.
1 change: 1 addition & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ python:
extra_requirements:
- tests
- docs
- setup-configuration
3 changes: 3 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

django.setup()

from django_setup_configuration.documentation.model_directive import setup


# -- Project information -----------------------------------------------------

project = "mozilla_django_oidc_db"
Expand Down
17 changes: 2 additions & 15 deletions docs/setup_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,12 @@ The setup configuration source must contain the following base keys to use this

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

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


Example: *setup_config.yml*

.. code-block:: YAML
other_enable: True
other_config:
...
oidc_db_config_enable: True
oidc_db_config_admin_auth:
items:
- identifier: admin-oidc
oidc_rp_client_id: client-id
oidc_rp_client_secret: secret
endpoint_config:
oidc_op_discovery_endpoint: https://keycloak.local/protocol/openid-connect/
...
.. pydantic-model-example:: mozilla_django_oidc_db.setup_configuration.steps.AdminOIDCConfigurationStep

This is file is then used with the setup configuration command setup the OIDC admin:

Expand Down
19 changes: 10 additions & 9 deletions mozilla_django_oidc_db/setup_configuration/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,32 @@
from django_setup_configuration.models import ConfigurationModel
from pydantic import AnyUrl, Discriminator, Field, Tag
from typing_extensions import Annotated

from mozilla_django_oidc_db.models import get_claim_mapping
from mozilla_django_oidc_db.models import OpenIDConnectConfig
from mozilla_django_oidc_db.fields import ClaimFieldDefault


class OIDCFullEndpointConfig(ConfigurationModel):
oidc_op_authorization_endpoint: AnyUrl = DjangoModelRef(
OpenIDConnectConfig, "oidc_op_authorization_endpoint"
OpenIDConnectConfig, "oidc_op_authorization_endpoint", examples=["http://keycloak.local:8080/realms/test/openid-connect/auth"]
)
oidc_op_token_endpoint: AnyUrl = DjangoModelRef(
OpenIDConnectConfig, "oidc_op_token_endpoint"
OpenIDConnectConfig, "oidc_op_token_endpoint", examples=["http://keycloak.local:8080/realms/test/protocol/openid-connect/token"]
)
oidc_op_user_endpoint: AnyUrl = DjangoModelRef(
OpenIDConnectConfig, "oidc_op_user_endpoint"
OpenIDConnectConfig, "oidc_op_user_endpoint", examples=["http://keycloak.local:8080/realms/test/protocol/openid-connect/userinfo"]
)
oidc_op_logout_endpoint: AnyUrl | Literal[""] = DjangoModelRef(
OpenIDConnectConfig, "oidc_op_logout_endpoint"
OpenIDConnectConfig, "oidc_op_logout_endpoint", examples=["http://keycloak.local:8080/realms/test/protocol/openid-connect/logout"]
)
oidc_op_jwks_endpoint: AnyUrl | Literal[""] = DjangoModelRef(
OpenIDConnectConfig, "oidc_op_jwks_endpoint"
OpenIDConnectConfig, "oidc_op_jwks_endpoint", examples=["http://keycloak.local:8080/realms/test/protocol/openid-connect/certs"]
)


class OIDCDiscoveryEndpoint(ConfigurationModel):
oidc_op_discovery_endpoint: AnyUrl = DjangoModelRef(
OpenIDConnectConfig, "oidc_op_discovery_endpoint", default=None
OpenIDConnectConfig, "oidc_op_discovery_endpoint", default=None, examples=["http://keycloak.local:8080/realms/test/"]
)


Expand All @@ -55,13 +56,13 @@ def get_endpoint_endpoint_model(endpoint_data):
class AdminOIDCConfigurationModelItem(ConfigurationModel):
# Currently unused because we use a SingletonModel, but this will be relevant in the
# future
identifier: str = Field(description="a unique identifier for this configuration")
identifier: str = Field(description="a unique identifier for this configuration", examples=["admin-oidc"])

# Change default to True
enabled: bool = DjangoModelRef(OpenIDConnectConfig, "enabled", default=True)

# Json
claim_mapping: dict = DjangoModelRef(OpenIDConnectConfig, "claim_mapping")
claim_mapping: dict = DjangoModelRef(OpenIDConnectConfig, "claim_mapping", examples=[get_claim_mapping()])

# Arrays are overridden to make the typing simpler (the underlying Django field is an ArrayField, which is non-standard)
username_claim: list[str] = DjangoModelRef(OpenIDConnectConfig, "username_claim")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Changelog = "https://github.com/maykinmedia/mozilla-django-oidc-db/blob/master/C

[project.optional-dependencies]
setup-configuration = [
"django-setup-configuration>=0.4.0",
"django-setup-configuration @ git+https://github.com/maykinmedia/django-setup-configuration.git@feature/model-documentation-directive",
]
tests = [
"psycopg2",
Expand Down

0 comments on commit 507d6b4

Please sign in to comment.