Skip to content

Commit

Permalink
♻️ [#45] Refactor config models
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm committed Apr 8, 2022
1 parent 2adcc55 commit 4fb7b0e
Showing 1 changed file with 35 additions and 26 deletions.
61 changes: 35 additions & 26 deletions mozilla_django_oidc_db/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Dict, List

import django
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.postgres.fields import JSONField
Expand Down Expand Up @@ -103,30 +102,6 @@ class OpenIDConnectConfigBase(SingletonModel):
),
)

oidc_rp_client_id = models.CharField(
_("OpenID Connect client ID"),
max_length=1000,
help_text=_("OpenID Connect client ID provided by the OIDC Provider"),
)
oidc_rp_client_secret = models.CharField(
_("OpenID Connect secret"),
max_length=1000,
help_text=_("OpenID Connect secret provided by the OIDC Provider"),
)
oidc_rp_sign_algo = models.CharField(
_("OpenID sign algorithm"),
max_length=50,
help_text=_("Algorithm the Identity Provider uses to sign ID tokens"),
default="HS256",
)
oidc_rp_scopes_list = ArrayField(
verbose_name=_("OpenID Connect scopes"),
base_field=models.CharField(_("OpenID Connect scope"), max_length=50),
default=get_default_scopes,
blank=True,
help_text=_("OpenID Connect scopes that are requested during login"),
)

oidc_op_discovery_endpoint = models.URLField(
_("Discovery endpoint"),
max_length=1000,
Expand Down Expand Up @@ -170,6 +145,38 @@ class OpenIDConnectConfigBase(SingletonModel):
blank=True,
)

class Meta:
abstract = True

def __str__(self) -> str:
return force_text(self._meta.verbose_name)


class OpenIDConnectClientBaseConfig(models.Model):
oidc_rp_client_id = models.CharField(
_("OpenID Connect client ID"),
max_length=1000,
help_text=_("OpenID Connect client ID provided by the OIDC Provider"),
)
oidc_rp_client_secret = models.CharField(
_("OpenID Connect secret"),
max_length=1000,
help_text=_("OpenID Connect secret provided by the OIDC Provider"),
)
oidc_rp_sign_algo = models.CharField(
_("OpenID sign algorithm"),
max_length=50,
help_text=_("Algorithm the Identity Provider uses to sign ID tokens"),
default="HS256",
)
oidc_rp_scopes_list = ArrayField(
verbose_name=_("OpenID Connect scopes"),
base_field=models.CharField(_("OpenID Connect scope"), max_length=50),
default=get_default_scopes,
blank=True,
help_text=_("OpenID Connect scopes that are requested during login"),
)

@property
def oidc_rp_scopes(self) -> str:
"""
Expand All @@ -184,7 +191,9 @@ def __str__(self) -> str:
return force_text(self._meta.verbose_name)


class OpenIDConnectConfig(CachingMixin, OpenIDConnectConfigBase):
class OpenIDConnectConfig(
CachingMixin, OpenIDConnectClientBaseConfig, OpenIDConnectConfigBase
):
"""
Configuration for authentication/authorization via OpenID connect
"""
Expand Down

0 comments on commit 4fb7b0e

Please sign in to comment.