authentik.providers.oauth2.migrations.0031_remove_oauth2provider_backchannel_logout_uri_and_more

 1# Generated by Django 5.1.12 on 2025-10-02 05:45
 2
 3import authentik.lib.models
 4from django.apps.registry import Apps
 5from django.db.backends.base.schema import BaseDatabaseSchemaEditor
 6from django.db import migrations, models
 7
 8
 9def migrate_backchannel_logout_uri(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
10    OAuth2Provider = apps.get_model("authentik_providers_oauth2", "OAuth2Provider")
11
12    db_alias = schema_editor.connection.alias
13    for provider in OAuth2Provider.objects.using(db_alias).all():
14        provider.logout_uri = provider.backchannel_logout_uri
15        provider.logout_method = "backchannel"
16        provider.save(update_fields=["logout_uri", "logout_method"])
17
18
19class Migration(migrations.Migration):
20
21    dependencies = [
22        ("authentik_providers_oauth2", "0030_oauth2provider_refresh_token_threshold"),
23    ]
24
25    operations = [
26        migrations.AddField(
27            model_name="oauth2provider",
28            name="logout_method",
29            field=models.TextField(
30                choices=[("backchannel", "Back-channel"), ("frontchannel", "Front-channel")],
31                default="backchannel",
32                help_text="Backchannel logs out with server to server calls. Frontchannel uses iframes in your browser",
33                verbose_name="Logout Method",
34            ),
35        ),
36        migrations.AddField(
37            model_name="oauth2provider",
38            name="logout_uri",
39            field=models.TextField(
40                blank=True,
41                validators=[authentik.lib.models.DomainlessURLValidator(schemes=("http", "https"))],
42                verbose_name="Logout URI",
43            ),
44        ),
45        migrations.RunPython(migrate_backchannel_logout_uri, lambda *args: ...),
46        migrations.RemoveField(
47            model_name="oauth2provider",
48            name="backchannel_logout_uri",
49        ),
50    ]
def migrate_backchannel_logout_uri( apps: django.apps.registry.Apps, schema_editor: django.db.backends.base.schema.BaseDatabaseSchemaEditor):
10def migrate_backchannel_logout_uri(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
11    OAuth2Provider = apps.get_model("authentik_providers_oauth2", "OAuth2Provider")
12
13    db_alias = schema_editor.connection.alias
14    for provider in OAuth2Provider.objects.using(db_alias).all():
15        provider.logout_uri = provider.backchannel_logout_uri
16        provider.logout_method = "backchannel"
17        provider.save(update_fields=["logout_uri", "logout_method"])
class Migration(django.db.migrations.migration.Migration):
20class Migration(migrations.Migration):
21
22    dependencies = [
23        ("authentik_providers_oauth2", "0030_oauth2provider_refresh_token_threshold"),
24    ]
25
26    operations = [
27        migrations.AddField(
28            model_name="oauth2provider",
29            name="logout_method",
30            field=models.TextField(
31                choices=[("backchannel", "Back-channel"), ("frontchannel", "Front-channel")],
32                default="backchannel",
33                help_text="Backchannel logs out with server to server calls. Frontchannel uses iframes in your browser",
34                verbose_name="Logout Method",
35            ),
36        ),
37        migrations.AddField(
38            model_name="oauth2provider",
39            name="logout_uri",
40            field=models.TextField(
41                blank=True,
42                validators=[authentik.lib.models.DomainlessURLValidator(schemes=("http", "https"))],
43                verbose_name="Logout URI",
44            ),
45        ),
46        migrations.RunPython(migrate_backchannel_logout_uri, lambda *args: ...),
47        migrations.RemoveField(
48            model_name="oauth2provider",
49            name="backchannel_logout_uri",
50        ),
51    ]

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.

dependencies = [('authentik_providers_oauth2', '0030_oauth2provider_refresh_token_threshold')]
operations = [<AddField model_name='oauth2provider', name='logout_method', field=<django.db.models.fields.TextField>>, <AddField model_name='oauth2provider', name='logout_uri', field=<django.db.models.fields.TextField>>, <RunPython <function migrate_backchannel_logout_uri>, <function Migration.<lambda>>>, <RemoveField model_name='oauth2provider', name='backchannel_logout_uri'>]