authentik.providers.scim.models

SCIM Provider models

  1"""SCIM Provider models"""
  2
  3from typing import Any, Self
  4from uuid import uuid4
  5
  6from django.db import models
  7from django.templatetags.static import static
  8from django.utils.translation import gettext_lazy as _
  9from dramatiq.actor import Actor
 10from requests.auth import AuthBase
 11from rest_framework.serializers import Serializer
 12from structlog.stdlib import get_logger
 13
 14from authentik.core.models import BackchannelProvider, Group, PropertyMapping, User
 15from authentik.lib.models import InternallyManagedMixin, SerializerModel, SimpleThroughModel
 16from authentik.lib.sync.outgoing.base import BaseOutgoingSyncClient
 17from authentik.lib.sync.outgoing.models import OutgoingSyncObjectQueryMixin, OutgoingSyncProvider
 18from authentik.lib.utils.time import timedelta_from_string, timedelta_string_validator
 19from authentik.providers.scim.clients.auth import SCIMBasicAuth, SCIMTokenAuth
 20
 21LOGGER = get_logger()
 22
 23
 24class SCIMProviderUser(InternallyManagedMixin, SerializerModel):
 25    """Mapping of a user and provider to a SCIM user ID"""
 26
 27    id = models.UUIDField(primary_key=True, editable=False, default=uuid4)
 28    scim_id = models.TextField()
 29    user = models.ForeignKey(User, on_delete=models.CASCADE)
 30    provider = models.ForeignKey("SCIMProvider", on_delete=models.CASCADE)
 31    attributes = models.JSONField(default=dict)
 32
 33    @property
 34    def serializer(self) -> type[Serializer]:
 35        from authentik.providers.scim.api.users import SCIMProviderUserSerializer
 36
 37        return SCIMProviderUserSerializer
 38
 39    class Meta:
 40        unique_together = (("scim_id", "user", "provider"),)
 41
 42    def __str__(self) -> str:
 43        return f"SCIM Provider User {self.user_id} to {self.provider_id}"
 44
 45
 46class SCIMProviderGroup(InternallyManagedMixin, SerializerModel):
 47    """Mapping of a group and provider to a SCIM user ID"""
 48
 49    id = models.UUIDField(primary_key=True, editable=False, default=uuid4)
 50    scim_id = models.TextField()
 51    group = models.ForeignKey(Group, on_delete=models.CASCADE)
 52    provider = models.ForeignKey("SCIMProvider", on_delete=models.CASCADE)
 53    attributes = models.JSONField(default=dict)
 54
 55    @property
 56    def serializer(self) -> type[Serializer]:
 57        from authentik.providers.scim.api.groups import SCIMProviderGroupSerializer
 58
 59        return SCIMProviderGroupSerializer
 60
 61    class Meta:
 62        unique_together = (("scim_id", "group", "provider"),)
 63
 64    def __str__(self) -> str:
 65        return f"SCIM Provider Group {self.group_id} to {self.provider_id}"
 66
 67
 68class SCIMAuthenticationMode(models.TextChoices):
 69    """SCIM authentication modes"""
 70
 71    TOKEN = "token", _("Token")
 72    BASIC = "basic", _("Basic")
 73    OAUTH_SILENT = "oauth", _("OAuth (Silent)")
 74    OAUTH_INTERACTIVE = "oauth_interactive", _("OAuth (interactive)")
 75
 76
 77class SCIMCompatibilityMode(models.TextChoices):
 78    """SCIM compatibility mode"""
 79
 80    DEFAULT = "default", _("Default")
 81    AWS = "aws", _("AWS")
 82    SLACK = "slack", _("Slack")
 83    SALESFORCE = "sfdc", _("Salesforce")
 84    GITLAB = "gitlab", _("GitLab")
 85    WEBEX = "webex", _("Webex")
 86    VCENTER = "vcenter", _("vCenter")
 87
 88
 89class SCIMProvider(OutgoingSyncObjectQueryMixin, OutgoingSyncProvider, BackchannelProvider):
 90    """SCIM 2.0 provider to create users and groups in external applications"""
 91
 92    exclude_users_service_account = models.BooleanField(default=False)
 93
 94    group_filters = models.ManyToManyField(
 95        "authentik_core.group",
 96        default=None,
 97        blank=True,
 98        help_text=_("Group filters used to define sync-scope for groups."),
 99        through="SCIMProviderGroupFilter",
100    )
101
102    url = models.TextField(help_text=_("Base URL to SCIM requests, usually ends in /v2"))
103
104    auth_mode = models.TextField(
105        choices=SCIMAuthenticationMode.choices, default=SCIMAuthenticationMode.TOKEN
106    )
107
108    token = models.TextField(help_text=_("Authentication token"), blank=True)
109    auth_basic_user = models.TextField(
110        help_text=_("Username used for Basic authentication"), blank=True
111    )
112    auth_basic_password = models.TextField(
113        help_text=_("Password used for Basic authentication"), blank=True
114    )
115    auth_oauth = models.ForeignKey(
116        "authentik_sources_oauth.OAuthSource",
117        on_delete=models.SET_DEFAULT,
118        default=None,
119        null=True,
120        help_text=_("OAuth Source used for authentication"),
121    )
122    auth_oauth_params = models.JSONField(
123        blank=True, default=dict, help_text=_("Additional OAuth parameters, such as grant_type")
124    )
125    auth_oauth_user = models.ForeignKey(
126        "authentik_core.User", on_delete=models.SET_NULL, default=None, null=True
127    )
128
129    verify_certificates = models.BooleanField(default=True)
130
131    property_mappings_group = models.ManyToManyField(
132        PropertyMapping,
133        default=None,
134        blank=True,
135        help_text=_("Property mappings used for group creation/updating."),
136        through="SCIMProviderGroupPropertyMapping",
137    )
138
139    compatibility_mode = models.CharField(
140        max_length=30,
141        choices=SCIMCompatibilityMode.choices,
142        default=SCIMCompatibilityMode.DEFAULT,
143        verbose_name=_("SCIM Compatibility Mode"),
144        help_text=_("Alter authentik behavior for vendor-specific SCIM implementations."),
145    )
146    service_provider_config_cache_timeout = models.TextField(
147        default="hours=1",
148        validators=[timedelta_string_validator],
149        help_text=_(
150            "Cache duration for ServiceProviderConfig responses. Set minutes=0 to disable."
151        ),
152    )
153
154    def scim_auth(self) -> AuthBase:
155        if self.auth_mode == SCIMAuthenticationMode.BASIC:
156            return SCIMBasicAuth(self)
157        if self.auth_mode in [
158            SCIMAuthenticationMode.OAUTH_SILENT,
159            SCIMAuthenticationMode.OAUTH_INTERACTIVE,
160        ]:
161            try:
162                from authentik.enterprise.providers.scim.auth_oauth2 import SCIMOAuthAuth
163
164                return SCIMOAuthAuth(self)
165            except ImportError:
166                LOGGER.warning("Failed to import SCIM OAuth Client")
167        return SCIMTokenAuth(self)
168
169    @property
170    def icon_url(self) -> str | None:
171        return static("authentik/sources/scim/light.svg")
172
173    @property
174    def sync_actor(self) -> Actor:
175        from authentik.providers.scim.tasks import scim_sync
176
177        return scim_sync
178
179    def client_for_model(
180        self, model: type[User | Group | SCIMProviderUser | SCIMProviderGroup]
181    ) -> BaseOutgoingSyncClient[User | Group, Any, Any, Self]:
182        if issubclass(model, User | SCIMProviderUser):
183            from authentik.providers.scim.clients.users import SCIMUserClient
184
185            return SCIMUserClient(self)
186        if issubclass(model, Group | SCIMProviderGroup):
187            from authentik.providers.scim.clients.groups import SCIMGroupClient
188
189            return SCIMGroupClient(self)
190        raise ValueError(f"Invalid model {model}")
191
192    def save(self, *args, **kwargs):
193        from django.core.cache import cache
194
195        cache_key = f"goauthentik.io/providers/scim/{self.pk}/service_provider_config"
196        cache.delete(cache_key)
197        super().save(*args, **kwargs)
198
199    @classmethod
200    def get_object_mappings(cls, obj: User | Group) -> list[tuple[str, str]]:
201        if isinstance(obj, User):
202            return list(obj.scimprovideruser_set.values_list("provider__pk", "scim_id"))
203        if isinstance(obj, Group):
204            return list(obj.scimprovidergroup_set.values_list("provider__pk", "scim_id"))
205        raise ValueError(f"Invalid type {type(obj)}")
206
207    @property
208    def component(self) -> str:
209        return "ak-provider-scim-form"
210
211    @property
212    def service_provider_config_cache_timeout_seconds(self) -> int:
213        return max(
214            0,
215            int(timedelta_from_string(self.service_provider_config_cache_timeout).total_seconds()),
216        )
217
218    @property
219    def serializer(self) -> type[Serializer]:
220        from authentik.providers.scim.api.providers import SCIMProviderSerializer
221
222        return SCIMProviderSerializer
223
224    def __str__(self):
225        return f"SCIM Provider {self.name}"
226
227    class Meta:
228        verbose_name = _("SCIM Provider")
229        verbose_name_plural = _("SCIM Providers")
230
231
232class SCIMProviderGroupFilter(SimpleThroughModel):
233    group = models.ForeignKey(Group, on_delete=models.CASCADE)
234    scim_provider = models.ForeignKey(
235        SCIMProvider, on_delete=models.CASCADE, db_column="scimprovider_id"
236    )
237
238    class Meta:
239        db_table = "authentik_providers_scim_scimprovider_group_filters"
240        unique_together = (("group", "scim_provider"),)
241        verbose_name = _("SCIM Provider Group Filter")
242        verbose_name_plural = _("SCIM Provider Group Filters")
243
244    def __str__(self):
245        return (
246            f"SCIMProviderGroupFilter for SCIMProvider {self.scim_provider_id} "
247            f"and Group {self.group_id}."
248        )
249
250
251class SCIMProviderGroupPropertyMapping(SimpleThroughModel):
252    property_mapping = models.ForeignKey(
253        PropertyMapping, on_delete=models.CASCADE, db_column="propertymapping_id"
254    )
255    scim_provider = models.ForeignKey(
256        SCIMProvider, on_delete=models.CASCADE, db_column="scimprovider_id"
257    )
258
259    class Meta:
260        db_table = "authentik_providers_scim_scimprovider_property_mappings_group"
261        unique_together = (("property_mapping", "scim_provider"),)
262        verbose_name = _("SCIMProvider Group Property Mapping")
263        verbose_name_plural = _("SCIMProvider Group Property Mappings")
264
265    def __str__(self):
266        return (
267            f"SCIMProviderGroupPropertyMapping for SCIMProvider {self.scim_provider_id} "
268            f"and PropertyMapping {self.property_mapping_id}."
269        )
270
271
272class SCIMMapping(PropertyMapping):
273    """Map authentik data to outgoing SCIM requests"""
274
275    expression_allowed_types = [dict]
276
277    @property
278    def component(self) -> str:
279        return "ak-property-mapping-provider-scim-form"
280
281    @property
282    def serializer(self) -> type[Serializer]:
283        from authentik.providers.scim.api.property_mappings import SCIMMappingSerializer
284
285        return SCIMMappingSerializer
286
287    def __str__(self):
288        return f"SCIM Provider Mapping {self.name}"
289
290    class Meta:
291        verbose_name = _("SCIM Provider Mapping")
292        verbose_name_plural = _("SCIM Provider Mappings")
LOGGER = <BoundLoggerLazyProxy(logger=None, wrapper_class=None, processors=None, context_class=None, initial_values={}, logger_factory_args=())>
25class SCIMProviderUser(InternallyManagedMixin, SerializerModel):
26    """Mapping of a user and provider to a SCIM user ID"""
27
28    id = models.UUIDField(primary_key=True, editable=False, default=uuid4)
29    scim_id = models.TextField()
30    user = models.ForeignKey(User, on_delete=models.CASCADE)
31    provider = models.ForeignKey("SCIMProvider", on_delete=models.CASCADE)
32    attributes = models.JSONField(default=dict)
33
34    @property
35    def serializer(self) -> type[Serializer]:
36        from authentik.providers.scim.api.users import SCIMProviderUserSerializer
37
38        return SCIMProviderUserSerializer
39
40    class Meta:
41        unique_together = (("scim_id", "user", "provider"),)
42
43    def __str__(self) -> str:
44        return f"SCIM Provider User {self.user_id} to {self.provider_id}"

Mapping of a user and provider to a SCIM user ID

def id(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def scim_id(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

user

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

provider

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

def attributes(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

serializer: type[rest_framework.serializers.Serializer]
34    @property
35    def serializer(self) -> type[Serializer]:
36        from authentik.providers.scim.api.users import SCIMProviderUserSerializer
37
38        return SCIMProviderUserSerializer

Get serializer for this model

user_id
provider_id
def objects(unknown):

The type of the None singleton.

class SCIMProviderUser.DoesNotExist(django.core.exceptions.ObjectDoesNotExist):

The requested object does not exist

class SCIMProviderUser.MultipleObjectsReturned(django.core.exceptions.MultipleObjectsReturned):

The query returned multiple objects when only one was expected.

47class SCIMProviderGroup(InternallyManagedMixin, SerializerModel):
48    """Mapping of a group and provider to a SCIM user ID"""
49
50    id = models.UUIDField(primary_key=True, editable=False, default=uuid4)
51    scim_id = models.TextField()
52    group = models.ForeignKey(Group, on_delete=models.CASCADE)
53    provider = models.ForeignKey("SCIMProvider", on_delete=models.CASCADE)
54    attributes = models.JSONField(default=dict)
55
56    @property
57    def serializer(self) -> type[Serializer]:
58        from authentik.providers.scim.api.groups import SCIMProviderGroupSerializer
59
60        return SCIMProviderGroupSerializer
61
62    class Meta:
63        unique_together = (("scim_id", "group", "provider"),)
64
65    def __str__(self) -> str:
66        return f"SCIM Provider Group {self.group_id} to {self.provider_id}"

Mapping of a group and provider to a SCIM user ID

def id(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def scim_id(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

group

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

provider

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

def attributes(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

serializer: type[rest_framework.serializers.Serializer]
56    @property
57    def serializer(self) -> type[Serializer]:
58        from authentik.providers.scim.api.groups import SCIMProviderGroupSerializer
59
60        return SCIMProviderGroupSerializer

Get serializer for this model

group_id
provider_id
def objects(unknown):

The type of the None singleton.

class SCIMProviderGroup.DoesNotExist(django.core.exceptions.ObjectDoesNotExist):

The requested object does not exist

class SCIMProviderGroup.MultipleObjectsReturned(django.core.exceptions.MultipleObjectsReturned):

The query returned multiple objects when only one was expected.

class SCIMAuthenticationMode(django.db.models.enums.TextChoices):
69class SCIMAuthenticationMode(models.TextChoices):
70    """SCIM authentication modes"""
71
72    TOKEN = "token", _("Token")
73    BASIC = "basic", _("Basic")
74    OAUTH_SILENT = "oauth", _("OAuth (Silent)")
75    OAUTH_INTERACTIVE = "oauth_interactive", _("OAuth (interactive)")

SCIM authentication modes

class SCIMCompatibilityMode(django.db.models.enums.TextChoices):
78class SCIMCompatibilityMode(models.TextChoices):
79    """SCIM compatibility mode"""
80
81    DEFAULT = "default", _("Default")
82    AWS = "aws", _("AWS")
83    SLACK = "slack", _("Slack")
84    SALESFORCE = "sfdc", _("Salesforce")
85    GITLAB = "gitlab", _("GitLab")
86    WEBEX = "webex", _("Webex")
87    VCENTER = "vcenter", _("vCenter")

SCIM compatibility mode

 90class SCIMProvider(OutgoingSyncObjectQueryMixin, OutgoingSyncProvider, BackchannelProvider):
 91    """SCIM 2.0 provider to create users and groups in external applications"""
 92
 93    exclude_users_service_account = models.BooleanField(default=False)
 94
 95    group_filters = models.ManyToManyField(
 96        "authentik_core.group",
 97        default=None,
 98        blank=True,
 99        help_text=_("Group filters used to define sync-scope for groups."),
100        through="SCIMProviderGroupFilter",
101    )
102
103    url = models.TextField(help_text=_("Base URL to SCIM requests, usually ends in /v2"))
104
105    auth_mode = models.TextField(
106        choices=SCIMAuthenticationMode.choices, default=SCIMAuthenticationMode.TOKEN
107    )
108
109    token = models.TextField(help_text=_("Authentication token"), blank=True)
110    auth_basic_user = models.TextField(
111        help_text=_("Username used for Basic authentication"), blank=True
112    )
113    auth_basic_password = models.TextField(
114        help_text=_("Password used for Basic authentication"), blank=True
115    )
116    auth_oauth = models.ForeignKey(
117        "authentik_sources_oauth.OAuthSource",
118        on_delete=models.SET_DEFAULT,
119        default=None,
120        null=True,
121        help_text=_("OAuth Source used for authentication"),
122    )
123    auth_oauth_params = models.JSONField(
124        blank=True, default=dict, help_text=_("Additional OAuth parameters, such as grant_type")
125    )
126    auth_oauth_user = models.ForeignKey(
127        "authentik_core.User", on_delete=models.SET_NULL, default=None, null=True
128    )
129
130    verify_certificates = models.BooleanField(default=True)
131
132    property_mappings_group = models.ManyToManyField(
133        PropertyMapping,
134        default=None,
135        blank=True,
136        help_text=_("Property mappings used for group creation/updating."),
137        through="SCIMProviderGroupPropertyMapping",
138    )
139
140    compatibility_mode = models.CharField(
141        max_length=30,
142        choices=SCIMCompatibilityMode.choices,
143        default=SCIMCompatibilityMode.DEFAULT,
144        verbose_name=_("SCIM Compatibility Mode"),
145        help_text=_("Alter authentik behavior for vendor-specific SCIM implementations."),
146    )
147    service_provider_config_cache_timeout = models.TextField(
148        default="hours=1",
149        validators=[timedelta_string_validator],
150        help_text=_(
151            "Cache duration for ServiceProviderConfig responses. Set minutes=0 to disable."
152        ),
153    )
154
155    def scim_auth(self) -> AuthBase:
156        if self.auth_mode == SCIMAuthenticationMode.BASIC:
157            return SCIMBasicAuth(self)
158        if self.auth_mode in [
159            SCIMAuthenticationMode.OAUTH_SILENT,
160            SCIMAuthenticationMode.OAUTH_INTERACTIVE,
161        ]:
162            try:
163                from authentik.enterprise.providers.scim.auth_oauth2 import SCIMOAuthAuth
164
165                return SCIMOAuthAuth(self)
166            except ImportError:
167                LOGGER.warning("Failed to import SCIM OAuth Client")
168        return SCIMTokenAuth(self)
169
170    @property
171    def icon_url(self) -> str | None:
172        return static("authentik/sources/scim/light.svg")
173
174    @property
175    def sync_actor(self) -> Actor:
176        from authentik.providers.scim.tasks import scim_sync
177
178        return scim_sync
179
180    def client_for_model(
181        self, model: type[User | Group | SCIMProviderUser | SCIMProviderGroup]
182    ) -> BaseOutgoingSyncClient[User | Group, Any, Any, Self]:
183        if issubclass(model, User | SCIMProviderUser):
184            from authentik.providers.scim.clients.users import SCIMUserClient
185
186            return SCIMUserClient(self)
187        if issubclass(model, Group | SCIMProviderGroup):
188            from authentik.providers.scim.clients.groups import SCIMGroupClient
189
190            return SCIMGroupClient(self)
191        raise ValueError(f"Invalid model {model}")
192
193    def save(self, *args, **kwargs):
194        from django.core.cache import cache
195
196        cache_key = f"goauthentik.io/providers/scim/{self.pk}/service_provider_config"
197        cache.delete(cache_key)
198        super().save(*args, **kwargs)
199
200    @classmethod
201    def get_object_mappings(cls, obj: User | Group) -> list[tuple[str, str]]:
202        if isinstance(obj, User):
203            return list(obj.scimprovideruser_set.values_list("provider__pk", "scim_id"))
204        if isinstance(obj, Group):
205            return list(obj.scimprovidergroup_set.values_list("provider__pk", "scim_id"))
206        raise ValueError(f"Invalid type {type(obj)}")
207
208    @property
209    def component(self) -> str:
210        return "ak-provider-scim-form"
211
212    @property
213    def service_provider_config_cache_timeout_seconds(self) -> int:
214        return max(
215            0,
216            int(timedelta_from_string(self.service_provider_config_cache_timeout).total_seconds()),
217        )
218
219    @property
220    def serializer(self) -> type[Serializer]:
221        from authentik.providers.scim.api.providers import SCIMProviderSerializer
222
223        return SCIMProviderSerializer
224
225    def __str__(self):
226        return f"SCIM Provider {self.name}"
227
228    class Meta:
229        verbose_name = _("SCIM Provider")
230        verbose_name_plural = _("SCIM Providers")

SCIM 2.0 provider to create users and groups in external applications

def exclude_users_service_account(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

group_filters

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example::

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

def url(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def auth_mode(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def token(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def auth_basic_user(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def auth_basic_password(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

auth_oauth

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

def auth_oauth_params(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

auth_oauth_user

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

def verify_certificates(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property_mappings_group

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example::

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

def compatibility_mode(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def service_provider_config_cache_timeout(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def scim_auth(self) -> requests.auth.AuthBase:
155    def scim_auth(self) -> AuthBase:
156        if self.auth_mode == SCIMAuthenticationMode.BASIC:
157            return SCIMBasicAuth(self)
158        if self.auth_mode in [
159            SCIMAuthenticationMode.OAUTH_SILENT,
160            SCIMAuthenticationMode.OAUTH_INTERACTIVE,
161        ]:
162            try:
163                from authentik.enterprise.providers.scim.auth_oauth2 import SCIMOAuthAuth
164
165                return SCIMOAuthAuth(self)
166            except ImportError:
167                LOGGER.warning("Failed to import SCIM OAuth Client")
168        return SCIMTokenAuth(self)
icon_url: str | None
170    @property
171    def icon_url(self) -> str | None:
172        return static("authentik/sources/scim/light.svg")
sync_actor: dramatiq.actor.Actor
174    @property
175    def sync_actor(self) -> Actor:
176        from authentik.providers.scim.tasks import scim_sync
177
178        return scim_sync
180    def client_for_model(
181        self, model: type[User | Group | SCIMProviderUser | SCIMProviderGroup]
182    ) -> BaseOutgoingSyncClient[User | Group, Any, Any, Self]:
183        if issubclass(model, User | SCIMProviderUser):
184            from authentik.providers.scim.clients.users import SCIMUserClient
185
186            return SCIMUserClient(self)
187        if issubclass(model, Group | SCIMProviderGroup):
188            from authentik.providers.scim.clients.groups import SCIMGroupClient
189
190            return SCIMGroupClient(self)
191        raise ValueError(f"Invalid model {model}")
def save(self, *args, **kwargs):
193    def save(self, *args, **kwargs):
194        from django.core.cache import cache
195
196        cache_key = f"goauthentik.io/providers/scim/{self.pk}/service_provider_config"
197        cache.delete(cache_key)
198        super().save(*args, **kwargs)

Save the current instance. Override this in a subclass if you want to control the saving process.

The 'force_insert' and 'force_update' parameters can be used to insist that the "save" must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.

@classmethod
def get_object_mappings( cls, obj: authentik.core.models.User | authentik.core.models.Group) -> list[tuple[str, str]]:
200    @classmethod
201    def get_object_mappings(cls, obj: User | Group) -> list[tuple[str, str]]:
202        if isinstance(obj, User):
203            return list(obj.scimprovideruser_set.values_list("provider__pk", "scim_id"))
204        if isinstance(obj, Group):
205            return list(obj.scimprovidergroup_set.values_list("provider__pk", "scim_id"))
206        raise ValueError(f"Invalid type {type(obj)}")

Get a list of mapping between User/Group and ProviderUser/Group: [("provider_pk", "obj_pk")]

component: str
208    @property
209    def component(self) -> str:
210        return "ak-provider-scim-form"

Return component used to edit this object

service_provider_config_cache_timeout_seconds: int
212    @property
213    def service_provider_config_cache_timeout_seconds(self) -> int:
214        return max(
215            0,
216            int(timedelta_from_string(self.service_provider_config_cache_timeout).total_seconds()),
217        )
serializer: type[rest_framework.serializers.Serializer]
219    @property
220    def serializer(self) -> type[Serializer]:
221        from authentik.providers.scim.api.providers import SCIMProviderSerializer
222
223        return SCIMProviderSerializer

Get serializer for this model

def sync_page_size(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def sync_page_timeout(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def discovery_enabled(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def dry_run(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

schedules

Accessor to the related objects manager on the one-to-many relation created by GenericRelation.

In the example::

class Post(Model):
    comments = GenericRelation(Comment)

post.comments is a ReverseGenericManyToOneDescriptor instance.

tasks

Accessor to the related objects manager on the one-to-many relation created by GenericRelation.

In the example::

class Post(Model):
    comments = GenericRelation(Comment)

post.comments is a ReverseGenericManyToOneDescriptor instance.

def get_auth_mode_display(unknown):

Method descriptor with partial application of the given arguments and keywords.

Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.

auth_oauth_id
auth_oauth_user_id
def get_compatibility_mode_display(unknown):

Method descriptor with partial application of the given arguments and keywords.

Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.

provider_ptr_id
provider_ptr

Accessor to the related object on the forward side of a one-to-one relation.

In the example::

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Restaurant.place is a ForwardOneToOneDescriptor instance.

scimprovideruser_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

scimprovidergroup_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

scimprovidergroupfilter_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

scimprovidergrouppropertymapping_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class SCIMProvider.DoesNotExist(django.core.exceptions.ObjectDoesNotExist):

The requested object does not exist

class SCIMProvider.MultipleObjectsReturned(django.core.exceptions.MultipleObjectsReturned):

The query returned multiple objects when only one was expected.

class SCIMProviderGroupFilter(authentik.lib.models.SimpleThroughModel):
233class SCIMProviderGroupFilter(SimpleThroughModel):
234    group = models.ForeignKey(Group, on_delete=models.CASCADE)
235    scim_provider = models.ForeignKey(
236        SCIMProvider, on_delete=models.CASCADE, db_column="scimprovider_id"
237    )
238
239    class Meta:
240        db_table = "authentik_providers_scim_scimprovider_group_filters"
241        unique_together = (("group", "scim_provider"),)
242        verbose_name = _("SCIM Provider Group Filter")
243        verbose_name_plural = _("SCIM Provider Group Filters")
244
245    def __str__(self):
246        return (
247            f"SCIMProviderGroupFilter for SCIMProvider {self.scim_provider_id} "
248            f"and Group {self.group_id}."
249        )

SCIMProviderGroupFilter(id, group, scim_provider)

group

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

scim_provider

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

group_id
scim_provider_id
def id(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def objects(unknown):

The type of the None singleton.

class SCIMProviderGroupFilter.DoesNotExist(django.core.exceptions.ObjectDoesNotExist):

The requested object does not exist

class SCIMProviderGroupFilter.MultipleObjectsReturned(django.core.exceptions.MultipleObjectsReturned):

The query returned multiple objects when only one was expected.

class SCIMProviderGroupPropertyMapping(authentik.lib.models.SimpleThroughModel):
252class SCIMProviderGroupPropertyMapping(SimpleThroughModel):
253    property_mapping = models.ForeignKey(
254        PropertyMapping, on_delete=models.CASCADE, db_column="propertymapping_id"
255    )
256    scim_provider = models.ForeignKey(
257        SCIMProvider, on_delete=models.CASCADE, db_column="scimprovider_id"
258    )
259
260    class Meta:
261        db_table = "authentik_providers_scim_scimprovider_property_mappings_group"
262        unique_together = (("property_mapping", "scim_provider"),)
263        verbose_name = _("SCIMProvider Group Property Mapping")
264        verbose_name_plural = _("SCIMProvider Group Property Mappings")
265
266    def __str__(self):
267        return (
268            f"SCIMProviderGroupPropertyMapping for SCIMProvider {self.scim_provider_id} "
269            f"and PropertyMapping {self.property_mapping_id}."
270        )

SCIMProviderGroupPropertyMapping(id, property_mapping, scim_provider)

property_mapping

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

scim_provider

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

property_mapping_id
scim_provider_id
def id(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def objects(unknown):

The type of the None singleton.

class SCIMProviderGroupPropertyMapping.DoesNotExist(django.core.exceptions.ObjectDoesNotExist):

The requested object does not exist

class SCIMProviderGroupPropertyMapping.MultipleObjectsReturned(django.core.exceptions.MultipleObjectsReturned):

The query returned multiple objects when only one was expected.

class SCIMMapping(authentik.core.models.PropertyMapping):
273class SCIMMapping(PropertyMapping):
274    """Map authentik data to outgoing SCIM requests"""
275
276    expression_allowed_types = [dict]
277
278    @property
279    def component(self) -> str:
280        return "ak-property-mapping-provider-scim-form"
281
282    @property
283    def serializer(self) -> type[Serializer]:
284        from authentik.providers.scim.api.property_mappings import SCIMMappingSerializer
285
286        return SCIMMappingSerializer
287
288    def __str__(self):
289        return f"SCIM Provider Mapping {self.name}"
290
291    class Meta:
292        verbose_name = _("SCIM Provider Mapping")
293        verbose_name_plural = _("SCIM Provider Mappings")

Map authentik data to outgoing SCIM requests

expression_allowed_types = [<class 'dict'>]
component: str
278    @property
279    def component(self) -> str:
280        return "ak-property-mapping-provider-scim-form"

Return component used to edit this object

serializer: type[rest_framework.serializers.Serializer]
282    @property
283    def serializer(self) -> type[Serializer]:
284        from authentik.providers.scim.api.property_mappings import SCIMMappingSerializer
285
286        return SCIMMappingSerializer

Get serializer for this model

propertymapping_ptr_id
propertymapping_ptr

Accessor to the related object on the forward side of a one-to-one relation.

In the example::

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Restaurant.place is a ForwardOneToOneDescriptor instance.

class SCIMMapping.DoesNotExist(authentik.core.models.PropertyMapping.DoesNotExist):

The requested object does not exist

class SCIMMapping.MultipleObjectsReturned(authentik.core.models.PropertyMapping.MultipleObjectsReturned):

The query returned multiple objects when only one was expected.