authentik.providers.oauth2.migrations.0007_auto_20201016_1107_squashed_0017_alter_oauth2provider_token_validity

  1# Generated by Django 3.2.8 on 2021-10-10 16:24
  2
  3import django.db.models.deletion
  4from django.apps.registry import Apps
  5from django.db import migrations, models
  6from django.db.backends.base.schema import BaseDatabaseSchemaEditor
  7
  8import authentik.lib.utils.time
  9
 10scope_uid_map = {
 11    "openid": "goauthentik.io/providers/oauth2/scope-openid",
 12    "email": "goauthentik.io/providers/oauth2/scope-email",
 13    "profile": "goauthentik.io/providers/oauth2/scope-profile",
 14    "ak_proxy": "goauthentik.io/providers/proxy/scope-proxy",
 15}
 16
 17
 18def set_managed_flag(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
 19    ScopeMapping = apps.get_model("authentik_providers_oauth2", "ScopeMapping")
 20    db_alias = schema_editor.connection.alias
 21    for mapping in ScopeMapping.objects.using(db_alias).filter(name__startswith="Autogenerated "):
 22        mapping.managed = scope_uid_map[mapping.scope_name]
 23        mapping.save()
 24
 25
 26class Migration(migrations.Migration):
 27    replaces = [
 28        ("authentik_providers_oauth2", "0007_auto_20201016_1107"),
 29        ("authentik_providers_oauth2", "0008_oauth2provider_issuer_mode"),
 30        ("authentik_providers_oauth2", "0009_remove_oauth2provider_response_type"),
 31        ("authentik_providers_oauth2", "0010_auto_20201227_1804"),
 32        ("authentik_providers_oauth2", "0011_managed"),
 33        ("authentik_providers_oauth2", "0012_oauth2provider_access_code_validity"),
 34        ("authentik_providers_oauth2", "0013_alter_authorizationcode_nonce"),
 35        ("authentik_providers_oauth2", "0014_alter_oauth2provider_rsa_key"),
 36        ("authentik_providers_oauth2", "0015_auto_20210703_1313"),
 37        ("authentik_providers_oauth2", "0016_alter_authorizationcode_nonce"),
 38        ("authentik_providers_oauth2", "0017_alter_oauth2provider_token_validity"),
 39    ]
 40
 41    dependencies = [
 42        ("authentik_core", "0017_managed"),
 43        ("authentik_crypto", "0002_create_self_signed_kp"),
 44        ("authentik_providers_oauth2", "0006_remove_oauth2provider_name"),
 45    ]
 46
 47    operations = [
 48        migrations.AlterModelOptions(
 49            name="refreshtoken",
 50            options={"verbose_name": "OAuth2 Token", "verbose_name_plural": "OAuth2 Tokens"},
 51        ),
 52        migrations.AddField(
 53            model_name="oauth2provider",
 54            name="issuer_mode",
 55            field=models.TextField(
 56                choices=[
 57                    ("global", "Same identifier is used for all providers"),
 58                    (
 59                        "per_provider",
 60                        "Each provider has a different issuer, based on the application slug.",
 61                    ),
 62                ],
 63                default="per_provider",
 64                help_text="Configure how the issuer field of the ID Token should be filled.",
 65            ),
 66        ),
 67        migrations.RemoveField(
 68            model_name="oauth2provider",
 69            name="response_type",
 70        ),
 71        migrations.AlterField(
 72            model_name="refreshtoken",
 73            name="access_token",
 74            field=models.TextField(verbose_name="Access Token"),
 75        ),
 76        migrations.RunPython(
 77            code=set_managed_flag,
 78        ),
 79        migrations.AddField(
 80            model_name="oauth2provider",
 81            name="access_code_validity",
 82            field=models.TextField(
 83                default="minutes=1",
 84                help_text=(
 85                    "Access codes not valid on or after current time + this value (Format:"
 86                    " hours=1;minutes=2;seconds=3)."
 87                ),
 88                validators=[authentik.lib.utils.time.timedelta_string_validator],
 89            ),
 90        ),
 91        migrations.AlterField(
 92            model_name="authorizationcode",
 93            name="nonce",
 94            field=models.TextField(blank=True, default="", verbose_name="Nonce"),
 95        ),
 96        migrations.AlterField(
 97            model_name="oauth2provider",
 98            name="rsa_key",
 99            field=models.ForeignKey(
100                help_text=(
101                    "Key used to sign the tokens. Only required when JWT Algorithm is set to RS256."
102                ),
103                null=True,
104                on_delete=django.db.models.deletion.SET_NULL,
105                to="authentik_crypto.certificatekeypair",
106                verbose_name="RSA Key",
107            ),
108        ),
109        migrations.AddField(
110            model_name="authorizationcode",
111            name="revoked",
112            field=models.BooleanField(default=False),
113        ),
114        migrations.AddField(
115            model_name="refreshtoken",
116            name="revoked",
117            field=models.BooleanField(default=False),
118        ),
119        migrations.AlterField(
120            model_name="authorizationcode",
121            name="nonce",
122            field=models.TextField(default=None, null=True, verbose_name="Nonce"),
123        ),
124        migrations.AlterField(
125            model_name="oauth2provider",
126            name="token_validity",
127            field=models.TextField(
128                default="days=30",
129                help_text=(
130                    "Tokens not valid on or after current time + this value (Format:"
131                    " hours=1;minutes=2;seconds=3)."
132                ),
133                validators=[authentik.lib.utils.time.timedelta_string_validator],
134            ),
135        ),
136    ]
scope_uid_map = {'openid': 'goauthentik.io/providers/oauth2/scope-openid', 'email': 'goauthentik.io/providers/oauth2/scope-email', 'profile': 'goauthentik.io/providers/oauth2/scope-profile', 'ak_proxy': 'goauthentik.io/providers/proxy/scope-proxy'}
def set_managed_flag( apps: django.apps.registry.Apps, schema_editor: django.db.backends.base.schema.BaseDatabaseSchemaEditor):
19def set_managed_flag(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
20    ScopeMapping = apps.get_model("authentik_providers_oauth2", "ScopeMapping")
21    db_alias = schema_editor.connection.alias
22    for mapping in ScopeMapping.objects.using(db_alias).filter(name__startswith="Autogenerated "):
23        mapping.managed = scope_uid_map[mapping.scope_name]
24        mapping.save()
class Migration(django.db.migrations.migration.Migration):
 27class Migration(migrations.Migration):
 28    replaces = [
 29        ("authentik_providers_oauth2", "0007_auto_20201016_1107"),
 30        ("authentik_providers_oauth2", "0008_oauth2provider_issuer_mode"),
 31        ("authentik_providers_oauth2", "0009_remove_oauth2provider_response_type"),
 32        ("authentik_providers_oauth2", "0010_auto_20201227_1804"),
 33        ("authentik_providers_oauth2", "0011_managed"),
 34        ("authentik_providers_oauth2", "0012_oauth2provider_access_code_validity"),
 35        ("authentik_providers_oauth2", "0013_alter_authorizationcode_nonce"),
 36        ("authentik_providers_oauth2", "0014_alter_oauth2provider_rsa_key"),
 37        ("authentik_providers_oauth2", "0015_auto_20210703_1313"),
 38        ("authentik_providers_oauth2", "0016_alter_authorizationcode_nonce"),
 39        ("authentik_providers_oauth2", "0017_alter_oauth2provider_token_validity"),
 40    ]
 41
 42    dependencies = [
 43        ("authentik_core", "0017_managed"),
 44        ("authentik_crypto", "0002_create_self_signed_kp"),
 45        ("authentik_providers_oauth2", "0006_remove_oauth2provider_name"),
 46    ]
 47
 48    operations = [
 49        migrations.AlterModelOptions(
 50            name="refreshtoken",
 51            options={"verbose_name": "OAuth2 Token", "verbose_name_plural": "OAuth2 Tokens"},
 52        ),
 53        migrations.AddField(
 54            model_name="oauth2provider",
 55            name="issuer_mode",
 56            field=models.TextField(
 57                choices=[
 58                    ("global", "Same identifier is used for all providers"),
 59                    (
 60                        "per_provider",
 61                        "Each provider has a different issuer, based on the application slug.",
 62                    ),
 63                ],
 64                default="per_provider",
 65                help_text="Configure how the issuer field of the ID Token should be filled.",
 66            ),
 67        ),
 68        migrations.RemoveField(
 69            model_name="oauth2provider",
 70            name="response_type",
 71        ),
 72        migrations.AlterField(
 73            model_name="refreshtoken",
 74            name="access_token",
 75            field=models.TextField(verbose_name="Access Token"),
 76        ),
 77        migrations.RunPython(
 78            code=set_managed_flag,
 79        ),
 80        migrations.AddField(
 81            model_name="oauth2provider",
 82            name="access_code_validity",
 83            field=models.TextField(
 84                default="minutes=1",
 85                help_text=(
 86                    "Access codes not valid on or after current time + this value (Format:"
 87                    " hours=1;minutes=2;seconds=3)."
 88                ),
 89                validators=[authentik.lib.utils.time.timedelta_string_validator],
 90            ),
 91        ),
 92        migrations.AlterField(
 93            model_name="authorizationcode",
 94            name="nonce",
 95            field=models.TextField(blank=True, default="", verbose_name="Nonce"),
 96        ),
 97        migrations.AlterField(
 98            model_name="oauth2provider",
 99            name="rsa_key",
100            field=models.ForeignKey(
101                help_text=(
102                    "Key used to sign the tokens. Only required when JWT Algorithm is set to RS256."
103                ),
104                null=True,
105                on_delete=django.db.models.deletion.SET_NULL,
106                to="authentik_crypto.certificatekeypair",
107                verbose_name="RSA Key",
108            ),
109        ),
110        migrations.AddField(
111            model_name="authorizationcode",
112            name="revoked",
113            field=models.BooleanField(default=False),
114        ),
115        migrations.AddField(
116            model_name="refreshtoken",
117            name="revoked",
118            field=models.BooleanField(default=False),
119        ),
120        migrations.AlterField(
121            model_name="authorizationcode",
122            name="nonce",
123            field=models.TextField(default=None, null=True, verbose_name="Nonce"),
124        ),
125        migrations.AlterField(
126            model_name="oauth2provider",
127            name="token_validity",
128            field=models.TextField(
129                default="days=30",
130                help_text=(
131                    "Tokens not valid on or after current time + this value (Format:"
132                    " hours=1;minutes=2;seconds=3)."
133                ),
134                validators=[authentik.lib.utils.time.timedelta_string_validator],
135            ),
136        ),
137    ]

The base class for all migrations.

Migration files will import this from django.db.migrations.Migration and subclass it as a class called Migration. It will have one or more of the following attributes:

  • operations: A list of Operation instances, probably from django.db.migrations.operations
  • dependencies: A list of tuples of (app_path, migration_name)
  • run_before: A list of tuples of (app_path, migration_name)
  • replaces: A list of migration_names

Note that all migrations come out of migrations and into the Loader or Graph as instances, having been initialized with their app label and name.

replaces = [('authentik_providers_oauth2', '0007_auto_20201016_1107'), ('authentik_providers_oauth2', '0008_oauth2provider_issuer_mode'), ('authentik_providers_oauth2', '0009_remove_oauth2provider_response_type'), ('authentik_providers_oauth2', '0010_auto_20201227_1804'), ('authentik_providers_oauth2', '0011_managed'), ('authentik_providers_oauth2', '0012_oauth2provider_access_code_validity'), ('authentik_providers_oauth2', '0013_alter_authorizationcode_nonce'), ('authentik_providers_oauth2', '0014_alter_oauth2provider_rsa_key'), ('authentik_providers_oauth2', '0015_auto_20210703_1313'), ('authentik_providers_oauth2', '0016_alter_authorizationcode_nonce'), ('authentik_providers_oauth2', '0017_alter_oauth2provider_token_validity')]
dependencies = [('authentik_core', '0017_managed'), ('authentik_crypto', '0002_create_self_signed_kp'), ('authentik_providers_oauth2', '0006_remove_oauth2provider_name')]
operations = [<AlterModelOptions name='refreshtoken', options={'verbose_name': 'OAuth2 Token', 'verbose_name_plural': 'OAuth2 Tokens'}>, <AddField model_name='oauth2provider', name='issuer_mode', field=<django.db.models.fields.TextField>>, <RemoveField model_name='oauth2provider', name='response_type'>, <AlterField model_name='refreshtoken', name='access_token', field=<django.db.models.fields.TextField>>, <RunPython code=<function set_managed_flag>>, <AddField model_name='oauth2provider', name='access_code_validity', field=<django.db.models.fields.TextField>>, <AlterField model_name='authorizationcode', name='nonce', field=<django.db.models.fields.TextField>>, <AlterField model_name='oauth2provider', name='rsa_key', field=<django.db.models.fields.related.ForeignKey>>, <AddField model_name='authorizationcode', name='revoked', field=<django.db.models.fields.BooleanField>>, <AddField model_name='refreshtoken', name='revoked', field=<django.db.models.fields.BooleanField>>, <AlterField model_name='authorizationcode', name='nonce', field=<django.db.models.fields.TextField>>, <AlterField model_name='oauth2provider', name='token_validity', field=<django.db.models.fields.TextField>>]