2023-12-18 17:06:03 +00:00
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
|
|
|
|
|
|
class JWTMappingSettings(BaseModel):
|
|
|
|
"""Mapping between the user model and the JWT fields.
|
|
|
|
|
2024-09-11 07:33:42 +00:00
|
|
|
Fields are evaluated with jinja.
|
2023-12-18 17:06:03 +00:00
|
|
|
A ``user`` var is available.
|
|
|
|
"""
|
|
|
|
|
2024-10-28 08:13:00 +00:00
|
|
|
SUB: str | None = "{{ user.user_name }}"
|
|
|
|
NAME: str | None = (
|
2023-12-18 17:06:03 +00:00
|
|
|
"{% if user.formatted_name %}{{ user.formatted_name }}{% endif %}"
|
|
|
|
)
|
2024-10-28 08:13:00 +00:00
|
|
|
PHONE_NUMBER: str | None = (
|
2023-12-18 17:06:03 +00:00
|
|
|
"{% if user.phone_numbers %}{{ user.phone_numbers[0] }}{% endif %}"
|
|
|
|
)
|
2024-10-28 08:13:00 +00:00
|
|
|
EMAIL: str | None = (
|
2023-12-18 17:06:03 +00:00
|
|
|
"{% if user.preferred_email %}{{ user.preferred_email }}{% endif %}"
|
|
|
|
)
|
2024-10-28 08:13:00 +00:00
|
|
|
GIVEN_NAME: str | None = "{% if user.given_name %}{{ user.given_name }}{% endif %}"
|
|
|
|
FAMILY_NAME: str | None = (
|
2023-12-18 17:06:03 +00:00
|
|
|
"{% if user.family_name %}{{ user.family_name }}{% endif %}"
|
|
|
|
)
|
2024-10-28 08:13:00 +00:00
|
|
|
PREFERRED_USERNAME: str | None = (
|
2023-12-18 17:06:03 +00:00
|
|
|
"{% if user.display_name %}{{ user.display_name }}{% endif %}"
|
|
|
|
)
|
2024-10-28 08:13:00 +00:00
|
|
|
LOCALE: str | None = (
|
2023-12-18 17:06:03 +00:00
|
|
|
"{% if user.preferred_language %}{{ user.preferred_language }}{% endif %}"
|
|
|
|
)
|
2024-10-28 08:13:00 +00:00
|
|
|
ADDRESS: str | None = (
|
2023-12-18 17:06:03 +00:00
|
|
|
"{% if user.formatted_address %}{{ user.formatted_address }}{% endif %}"
|
|
|
|
)
|
2024-10-28 08:13:00 +00:00
|
|
|
PICTURE: str | None = (
|
2023-12-18 17:06:03 +00:00
|
|
|
"{% if user.photo %}{{ url_for('core.account.photo', user=user, field='photo', _external=True) }}{% endif %}"
|
|
|
|
)
|
2024-10-28 08:13:00 +00:00
|
|
|
WEBSITE: str | None = "{% if user.profile_url %}{{ user.profile_url }}{% endif %}"
|
2023-12-18 17:06:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
class JWTSettings(BaseModel):
|
|
|
|
"""JSON Web Token settings. Belong in the ``CANAILLE_OIDC.JWT`` namespace.
|
|
|
|
|
|
|
|
You can generate a RSA keypair with::
|
|
|
|
|
|
|
|
openssl genrsa -out private.pem 4096
|
|
|
|
openssl rsa -in private.pem -pubout -outform PEM -out public.pem
|
|
|
|
"""
|
|
|
|
|
2024-10-28 08:13:00 +00:00
|
|
|
PRIVATE_KEY: str | None = None
|
2023-12-18 17:06:03 +00:00
|
|
|
"""The private key.
|
|
|
|
|
|
|
|
If :py:data:`None` and debug mode is enabled, then an in-memory key will be used.
|
|
|
|
"""
|
|
|
|
|
2024-10-28 08:13:00 +00:00
|
|
|
PUBLIC_KEY: str | None = None
|
2023-12-18 17:06:03 +00:00
|
|
|
"""The public key.
|
|
|
|
|
|
|
|
If :py:data:`None` and debug mode is enabled, then an in-memory key will be used.
|
|
|
|
"""
|
|
|
|
|
2024-10-28 08:13:00 +00:00
|
|
|
ISS: str | None = None
|
2023-12-18 17:06:03 +00:00
|
|
|
"""The URI of the identity provider."""
|
|
|
|
|
|
|
|
KTY: str = "RSA"
|
|
|
|
"""The key type."""
|
|
|
|
|
|
|
|
ALG: str = "RS256"
|
|
|
|
"""The key algorithm."""
|
|
|
|
|
|
|
|
EXP: int = 3600
|
|
|
|
"""The time the JWT will be valid, in seconds."""
|
|
|
|
|
2024-10-28 08:13:00 +00:00
|
|
|
MAPPING: JWTMappingSettings | None = JWTMappingSettings()
|
2023-12-18 17:06:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OIDCSettings(BaseModel):
|
|
|
|
"""OpenID Connect settings.
|
|
|
|
|
|
|
|
Belong in the ``CANAILLE_OIDC`` namespace.
|
|
|
|
"""
|
|
|
|
|
|
|
|
DYNAMIC_CLIENT_REGISTRATION_OPEN: bool = False
|
2024-09-11 07:33:42 +00:00
|
|
|
"""Whether a token is needed for the RFC7591 dynamical client registration.
|
2023-12-18 17:06:03 +00:00
|
|
|
|
|
|
|
If :py:data:`True`, no token is needed to register a client.
|
2024-04-23 20:12:04 +00:00
|
|
|
If :py:data:`False`, dynamical client registration needs a token defined in
|
|
|
|
:attr:`DYNAMIC_CLIENT_REGISTRATION_TOKENS`.
|
2023-12-18 17:06:03 +00:00
|
|
|
"""
|
|
|
|
|
2024-10-28 08:13:00 +00:00
|
|
|
DYNAMIC_CLIENT_REGISTRATION_TOKENS: list[str] | None = None
|
2023-12-18 17:06:03 +00:00
|
|
|
"""A list of tokens that can be used for dynamic client registration."""
|
|
|
|
|
|
|
|
REQUIRE_NONCE: bool = True
|
|
|
|
"""Force the nonce exchange during the authentication flows.
|
|
|
|
|
|
|
|
This adds security but may not be supported by all clients.
|
|
|
|
"""
|
|
|
|
|
2024-03-29 16:30:12 +00:00
|
|
|
JWT: JWTSettings = JWTSettings()
|
2023-12-18 17:06:03 +00:00
|
|
|
"""JSON Web Token settings."""
|