-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚚 Split models into separate modules
Organizing by DigiD and eHerkenning, similarly to the SAML models.
- Loading branch information
1 parent
a296a83
commit 0bedd5c
Showing
6 changed files
with
215 additions
and
214 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 was deleted.
Oops, something went wrong.
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,12 @@ | ||
from .base import get_default_scopes_bsn, get_default_scopes_kvk | ||
from .digid import DigiDConfig, DigiDMachtigenConfig | ||
from .eherkenning import EHerkenningBewindvoeringConfig, EHerkenningConfig | ||
|
||
__all__ = [ | ||
"get_default_scopes_bsn", | ||
"get_default_scopes_kvk", | ||
"DigiDConfig", | ||
"DigiDMachtigenConfig", | ||
"EHerkenningConfig", | ||
"EHerkenningBewindvoeringConfig", | ||
] |
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,31 @@ | ||
from django.utils.functional import classproperty | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from mozilla_django_oidc_db.models import OpenIDConnectConfigBase | ||
|
||
|
||
def get_default_scopes_bsn(): | ||
""" | ||
Returns the default scopes to request for OpenID Connect logins | ||
""" | ||
return ["openid", "bsn"] | ||
|
||
|
||
def get_default_scopes_kvk(): | ||
""" | ||
Returns the default scopes to request for OpenID Connect logins | ||
""" | ||
return ["openid", "kvk"] | ||
|
||
|
||
class OpenIDConnectBaseConfig(OpenIDConnectConfigBase): | ||
""" | ||
Base configuration for DigiD/eHerkenning authentication via OpenID Connect. | ||
""" | ||
|
||
class Meta: | ||
abstract = True | ||
|
||
@classproperty | ||
def oidcdb_check_idp_availability(cls) -> bool: | ||
return True |
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,83 @@ | ||
from collections.abc import Collection | ||
|
||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from django_jsonform.models.fields import ArrayField | ||
from mozilla_django_oidc_db.typing import ClaimPath | ||
|
||
from .base import OpenIDConnectBaseConfig, get_default_scopes_bsn | ||
|
||
|
||
class DigiDConfig(OpenIDConnectBaseConfig): | ||
""" | ||
Configuration for DigiD authentication via OpenID connect | ||
""" | ||
|
||
identifier_claim_name = models.CharField( | ||
_("BSN claim name"), | ||
max_length=100, | ||
help_text=_("The name of the claim in which the BSN of the user is stored"), | ||
default="bsn", | ||
) | ||
oidc_rp_scopes_list = ArrayField( | ||
verbose_name=_("OpenID Connect scopes"), | ||
base_field=models.CharField(_("OpenID Connect scope"), max_length=50), | ||
default=get_default_scopes_bsn, | ||
blank=True, | ||
help_text=_( | ||
"OpenID Connect scopes that are requested during login. " | ||
"These scopes are hardcoded and must be supported by the identity provider" | ||
), | ||
) | ||
|
||
class Meta: | ||
verbose_name = _("OpenID Connect configuration for DigiD") | ||
|
||
@property | ||
def oidcdb_username_claim(self) -> list[str]: | ||
return [self.identifier_claim_name] | ||
|
||
|
||
class DigiDMachtigenConfig(OpenIDConnectBaseConfig): | ||
# TODO: support periods in claim keys | ||
vertegenwoordigde_claim_name = models.CharField( | ||
verbose_name=_("vertegenwoordigde claim name"), | ||
default="aanvrager.bsn", | ||
max_length=50, | ||
help_text=_( | ||
"Name of the claim in which the BSN of the person being represented is stored" | ||
), | ||
) | ||
gemachtigde_claim_name = models.CharField( | ||
verbose_name=_("gemachtigde claim name"), | ||
default="gemachtigde.bsn", | ||
max_length=50, | ||
help_text=_( | ||
"Name of the claim in which the BSN of the person representing someone else is stored" | ||
), | ||
) | ||
oidc_rp_scopes_list = ArrayField( | ||
verbose_name=_("OpenID Connect scopes"), | ||
base_field=models.CharField(_("OpenID Connect scope"), max_length=50), | ||
default=get_default_scopes_bsn, | ||
blank=True, | ||
help_text=_( | ||
"OpenID Connect scopes that are requested during login. " | ||
"These scopes are hardcoded and must be supported by the identity provider" | ||
), | ||
) | ||
|
||
class Meta: | ||
verbose_name = _("OpenID Connect configuration for DigiD Machtigen") | ||
|
||
@property | ||
def digid_eherkenning_machtigen_claims(self) -> dict[str, ClaimPath]: | ||
return { | ||
"vertegenwoordigde": [self.vertegenwoordigde_claim_name], | ||
"gemachtigde": [self.gemachtigde_claim_name], | ||
} | ||
|
||
@property | ||
def oidcdb_sensitive_claims(self) -> Collection[ClaimPath]: | ||
return list(self.digid_eherkenning_machtigen_claims.values()) |
Oops, something went wrong.