-
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.
🚧 [#45] Initial changes for endpoints config
- Loading branch information
Showing
4 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
mozilla_django_oidc_db/migrations/0007_auto_20220411_1011.py
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,85 @@ | ||
# Generated by Django 3.2.12 on 2022-04-11 08:11 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("mozilla_django_oidc_db", "0006_openidconnectconfig_unique_id_claim"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="OpenIDConnectEndpointsConfig", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"oidc_op_discovery_endpoint", | ||
models.URLField( | ||
blank=True, | ||
help_text="URL of your OpenID Connect provider discovery endpoint ending with a slash (`.well-known/...` will be added automatically). If this is provided, the remaining endpoints can be omitted, as they will be derived from this endpoint.", | ||
max_length=1000, | ||
verbose_name="Discovery endpoint", | ||
), | ||
), | ||
( | ||
"oidc_op_jwks_endpoint", | ||
models.URLField( | ||
blank=True, | ||
help_text="URL of your OpenID Connect provider JSON Web Key Set endpoint. Required if `RS256` is used as signing algorithm", | ||
max_length=1000, | ||
verbose_name="JSON Web Key Set endpoint", | ||
), | ||
), | ||
( | ||
"oidc_op_authorization_endpoint", | ||
models.URLField( | ||
help_text="URL of your OpenID Connect provider authorization endpoint", | ||
max_length=1000, | ||
verbose_name="Authorization endpoint", | ||
), | ||
), | ||
( | ||
"oidc_op_token_endpoint", | ||
models.URLField( | ||
help_text="URL of your OpenID Connect provider token endpoint", | ||
max_length=1000, | ||
verbose_name="Token endpoint", | ||
), | ||
), | ||
( | ||
"oidc_op_user_endpoint", | ||
models.URLField( | ||
help_text="URL of your OpenID Connect provider userinfo endpoint", | ||
max_length=1000, | ||
verbose_name="User endpoint", | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "OpenID Connect endpoint configuration", | ||
"verbose_name_plural": "OpenID Connect endpoint configurations", | ||
}, | ||
), | ||
migrations.AddField( | ||
model_name="openidconnectconfig", | ||
name="endpoints_config", | ||
field=models.ForeignKey( | ||
blank=True, | ||
help_text="Model containing the endpoint configuration for the OpenID Connect provider", | ||
null=True, | ||
on_delete=django.db.models.deletion.DO_NOTHING, | ||
to="mozilla_django_oidc_db.openidconnectendpointsconfig", | ||
), | ||
), | ||
] |
43 changes: 43 additions & 0 deletions
43
mozilla_django_oidc_db/migrations/0008_auto_20220411_1015.py
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,43 @@ | ||
# Generated by Django 3.2.12 on 2022-04-11 08:15 | ||
|
||
from django.db import migrations | ||
|
||
from mozilla_django_oidc_db.utils import ( | ||
migrate_endpoints_backward, | ||
migrate_endpoints_forward, | ||
) | ||
|
||
|
||
def migrate_endpoints(apps, schema_editor): | ||
OpenIDConnectConfig = apps.get_model( | ||
"mozilla_django_oidc_db", "OpenIDConnectConfig" | ||
) | ||
OpenIDConnectEndpointsConfig = apps.get_model( | ||
"mozilla_django_oidc_db", "OpenIDConnectEndpointsConfig" | ||
) | ||
|
||
migrate_endpoints_forward(OpenIDConnectConfig, OpenIDConnectEndpointsConfig) | ||
|
||
|
||
def migrate_endpoints_reverse(apps, schema_editor): | ||
OpenIDConnectConfig = apps.get_model( | ||
"mozilla_django_oidc_db", "OpenIDConnectConfig" | ||
) | ||
OpenIDConnectEndpointsConfig = apps.get_model( | ||
"mozilla_django_oidc_db", "OpenIDConnectEndpointsConfig" | ||
) | ||
|
||
migrate_endpoints_backward(OpenIDConnectConfig, OpenIDConnectEndpointsConfig) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("mozilla_django_oidc_db", "0007_auto_20220411_1011"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
migrate_endpoints, reverse_code=migrate_endpoints_reverse | ||
), | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from django.db import models | ||
|
||
from solo.models import SingletonModel | ||
|
||
|
||
def migrate_endpoints_forward( | ||
config_singleton_model: SingletonModel, endpoints_config_model: models.Model | ||
): | ||
config = config_singleton_model.objects.first() | ||
if not config or config.endpoints_config: | ||
return | ||
|
||
endpoints_config = endpoints_config_model.objects.create( | ||
oidc_op_discovery_endpoint=config.oidc_op_discovery_endpoint, | ||
oidc_op_jwks_endpoint=config.oidc_op_jwks_endpoint, | ||
oidc_op_authorization_endpoint=config.oidc_op_authorization_endpoint, | ||
oidc_op_token_endpoint=config.oidc_op_token_endpoint, | ||
oidc_op_user_endpoint=config.oidc_op_user_endpoint, | ||
) | ||
|
||
config.endpoints_config = endpoints_config | ||
config.save() | ||
|
||
|
||
def migrate_endpoints_backward( | ||
config_singleton_model: SingletonModel, endpoints_config_model: models.Model | ||
): | ||
config = config_singleton_model.objects.first() | ||
if not config or not config.endpoints_config: | ||
return | ||
|
||
config.oidc_op_discovery_endpoint = ( | ||
config.endpoints_config.oidc_op_discovery_endpoint | ||
) | ||
config.oidc_op_jwks_endpoint = config.endpoints_config.oidc_op_jwks_endpoint | ||
config.oidc_op_authorization_endpoint = ( | ||
config.endpoints_config.oidc_op_authorization_endpoint | ||
) | ||
config.oidc_op_token_endpoint = config.endpoints_config.oidc_op_token_endpoint | ||
config.oidc_op_user_endpoint = config.endpoints_config.oidc_op_user_endpoint | ||
|
||
config.save() |