-
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.
Merge pull request #100 from maykinmedia/feature/99-oidc-init-view
Define "generic" OpenID Connect init view
- Loading branch information
Showing
14 changed files
with
530 additions
and
34 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 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,38 @@ | ||
""" | ||
Helpers to work with (dynamic) OIDC configuration. | ||
The utilities here make it easier to work with configuration that lives on a | ||
configuration model instance rather than in Django settings, while also handling | ||
settings that are still defined in the django settings layer. | ||
""" | ||
|
||
from typing import Any | ||
|
||
from mozilla_django_oidc.utils import import_from_settings | ||
|
||
from .models import OpenIDConnectConfigBase | ||
|
||
|
||
def get_setting_from_config(config: OpenIDConnectConfigBase, attr: str, *args) -> Any: | ||
""" | ||
Look up a setting from the config record or fall back to Django settings. | ||
Django settings are defined as ``OIDC_SOME_SETTING``, in upper case, while our | ||
model fields typically match the name, but in lower case. So, we look up if the | ||
requested setting exists as an attribut on the configuration instance and use that | ||
when provided, otherwise we fall back to the django settings module. | ||
.. note:: A setting may also be defined as a (calculated) property of some kind on | ||
a/the configuration instance, rather than an explicit model field. That's why | ||
we use ``hasattr`` checks rather than relying on | ||
``config._meta.get_field(some_field)``. | ||
""" | ||
attr_lowercase = attr.lower() | ||
if hasattr(config, attr_lowercase): | ||
# Workaround for OIDC_RP_IDP_SIGN_KEY being an empty string by default. | ||
# mozilla-django-oidc explicitly checks if `OIDC_RP_IDP_SIGN_KEY` is not `None` | ||
# https://github.com/mozilla/mozilla-django-oidc/blob/master/mozilla_django_oidc/auth.py#L189 | ||
if (value_from_config := getattr(config, attr_lowercase)) == "": | ||
return None | ||
return value_from_config | ||
return import_from_settings(attr, *args) |
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,2 @@ | ||
class OIDCProviderOutage(Exception): | ||
pass |
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 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 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
Oops, something went wrong.