authentik.brands.models
brand models
1"""brand models""" 2 3from uuid import uuid4 4 5from django.db import models 6from django.http import HttpRequest 7from django.utils.translation import gettext_lazy as _ 8from rest_framework.serializers import Serializer 9from structlog.stdlib import get_logger 10 11from authentik.admin.files.fields import FileField 12from authentik.admin.files.manager import get_file_manager 13from authentik.admin.files.usage import FileUsage 14from authentik.crypto.models import CertificateKeyPair 15from authentik.flows.models import Flow 16from authentik.lib.models import SerializerModel 17 18LOGGER = get_logger() 19 20 21class Brand(SerializerModel): 22 """Single brand""" 23 24 brand_uuid = models.UUIDField(primary_key=True, editable=False, default=uuid4) 25 domain = models.TextField( 26 help_text=_( 27 "Domain that activates this brand. Can be a superset, i.e. `a.b` for `aa.b` and `ba.b`" 28 ) 29 ) 30 default = models.BooleanField( 31 default=False, 32 ) 33 34 branding_title = models.TextField(default="authentik") 35 36 branding_logo = FileField(default="/static/dist/assets/icons/icon_left_brand.svg") 37 branding_favicon = FileField(default="/static/dist/assets/icons/icon.png") 38 branding_custom_css = models.TextField(default="", blank=True) 39 branding_default_flow_background = FileField( 40 default="/static/dist/assets/images/flow_background.jpg", 41 ) 42 43 flow_authentication = models.ForeignKey( 44 Flow, null=True, on_delete=models.SET_NULL, related_name="brand_authentication" 45 ) 46 flow_invalidation = models.ForeignKey( 47 Flow, null=True, on_delete=models.SET_NULL, related_name="brand_invalidation" 48 ) 49 flow_recovery = models.ForeignKey( 50 Flow, null=True, on_delete=models.SET_NULL, related_name="brand_recovery" 51 ) 52 flow_unenrollment = models.ForeignKey( 53 Flow, null=True, on_delete=models.SET_NULL, related_name="brand_unenrollment" 54 ) 55 flow_user_settings = models.ForeignKey( 56 Flow, null=True, on_delete=models.SET_NULL, related_name="brand_user_settings" 57 ) 58 flow_device_code = models.ForeignKey( 59 Flow, null=True, on_delete=models.SET_NULL, related_name="brand_device_code" 60 ) 61 62 default_application = models.ForeignKey( 63 "authentik_core.Application", 64 null=True, 65 default=None, 66 on_delete=models.SET_DEFAULT, 67 help_text=_( 68 "When set, external users will be redirected to this application after authenticating." 69 ), 70 ) 71 72 web_certificate = models.ForeignKey( 73 CertificateKeyPair, 74 null=True, 75 default=None, 76 on_delete=models.SET_DEFAULT, 77 help_text=_("Web Certificate used by the authentik Core webserver."), 78 related_name="+", 79 ) 80 client_certificates = models.ManyToManyField( 81 CertificateKeyPair, 82 default=None, 83 blank=True, 84 help_text=_("Certificates used for client authentication."), 85 ) 86 attributes = models.JSONField(default=dict, blank=True) 87 88 def branding_logo_url(self) -> str: 89 """Get branding_logo URL""" 90 return get_file_manager(FileUsage.MEDIA).file_url(self.branding_logo) 91 92 def branding_logo_themed_urls(self) -> dict[str, str] | None: 93 """Get themed URLs for branding_logo if it contains %(theme)s""" 94 return get_file_manager(FileUsage.MEDIA).themed_urls(self.branding_logo) 95 96 def branding_favicon_url(self) -> str: 97 """Get branding_favicon URL""" 98 return get_file_manager(FileUsage.MEDIA).file_url(self.branding_favicon) 99 100 def branding_favicon_themed_urls(self) -> dict[str, str] | None: 101 """Get themed URLs for branding_favicon if it contains %(theme)s""" 102 return get_file_manager(FileUsage.MEDIA).themed_urls(self.branding_favicon) 103 104 def branding_default_flow_background_url(self) -> str: 105 """Get branding_default_flow_background URL""" 106 return get_file_manager(FileUsage.MEDIA).file_url(self.branding_default_flow_background) 107 108 def branding_default_flow_background_themed_urls(self) -> dict[str, str] | None: 109 """Get themed URLs for branding_default_flow_background if it contains %(theme)s""" 110 return get_file_manager(FileUsage.MEDIA).themed_urls(self.branding_default_flow_background) 111 112 @property 113 def serializer(self) -> type[Serializer]: 114 from authentik.brands.api import BrandSerializer 115 116 return BrandSerializer 117 118 @property 119 def default_locale(self) -> str: 120 """Get default locale""" 121 try: 122 return self.attributes.get("settings", {}).get("locale", "") 123 124 except Exception as exc: # noqa 125 LOGGER.warning("Failed to get default locale", exc=exc) 126 return "" 127 128 def __str__(self) -> str: 129 if self.default: 130 return "Default brand" 131 return f"Brand {self.domain}" 132 133 class Meta: 134 verbose_name = _("Brand") 135 verbose_name_plural = _("Brands") 136 indexes = [ 137 models.Index(fields=["domain"]), 138 models.Index(fields=["default"]), 139 ] 140 141 142class WebfingerProvider(models.Model): 143 """Provider which supports webfinger discovery""" 144 145 class Meta: 146 abstract = True 147 148 def webfinger(self, resource: str, request: HttpRequest) -> dict: 149 raise NotImplementedError()
22class Brand(SerializerModel): 23 """Single brand""" 24 25 brand_uuid = models.UUIDField(primary_key=True, editable=False, default=uuid4) 26 domain = models.TextField( 27 help_text=_( 28 "Domain that activates this brand. Can be a superset, i.e. `a.b` for `aa.b` and `ba.b`" 29 ) 30 ) 31 default = models.BooleanField( 32 default=False, 33 ) 34 35 branding_title = models.TextField(default="authentik") 36 37 branding_logo = FileField(default="/static/dist/assets/icons/icon_left_brand.svg") 38 branding_favicon = FileField(default="/static/dist/assets/icons/icon.png") 39 branding_custom_css = models.TextField(default="", blank=True) 40 branding_default_flow_background = FileField( 41 default="/static/dist/assets/images/flow_background.jpg", 42 ) 43 44 flow_authentication = models.ForeignKey( 45 Flow, null=True, on_delete=models.SET_NULL, related_name="brand_authentication" 46 ) 47 flow_invalidation = models.ForeignKey( 48 Flow, null=True, on_delete=models.SET_NULL, related_name="brand_invalidation" 49 ) 50 flow_recovery = models.ForeignKey( 51 Flow, null=True, on_delete=models.SET_NULL, related_name="brand_recovery" 52 ) 53 flow_unenrollment = models.ForeignKey( 54 Flow, null=True, on_delete=models.SET_NULL, related_name="brand_unenrollment" 55 ) 56 flow_user_settings = models.ForeignKey( 57 Flow, null=True, on_delete=models.SET_NULL, related_name="brand_user_settings" 58 ) 59 flow_device_code = models.ForeignKey( 60 Flow, null=True, on_delete=models.SET_NULL, related_name="brand_device_code" 61 ) 62 63 default_application = models.ForeignKey( 64 "authentik_core.Application", 65 null=True, 66 default=None, 67 on_delete=models.SET_DEFAULT, 68 help_text=_( 69 "When set, external users will be redirected to this application after authenticating." 70 ), 71 ) 72 73 web_certificate = models.ForeignKey( 74 CertificateKeyPair, 75 null=True, 76 default=None, 77 on_delete=models.SET_DEFAULT, 78 help_text=_("Web Certificate used by the authentik Core webserver."), 79 related_name="+", 80 ) 81 client_certificates = models.ManyToManyField( 82 CertificateKeyPair, 83 default=None, 84 blank=True, 85 help_text=_("Certificates used for client authentication."), 86 ) 87 attributes = models.JSONField(default=dict, blank=True) 88 89 def branding_logo_url(self) -> str: 90 """Get branding_logo URL""" 91 return get_file_manager(FileUsage.MEDIA).file_url(self.branding_logo) 92 93 def branding_logo_themed_urls(self) -> dict[str, str] | None: 94 """Get themed URLs for branding_logo if it contains %(theme)s""" 95 return get_file_manager(FileUsage.MEDIA).themed_urls(self.branding_logo) 96 97 def branding_favicon_url(self) -> str: 98 """Get branding_favicon URL""" 99 return get_file_manager(FileUsage.MEDIA).file_url(self.branding_favicon) 100 101 def branding_favicon_themed_urls(self) -> dict[str, str] | None: 102 """Get themed URLs for branding_favicon if it contains %(theme)s""" 103 return get_file_manager(FileUsage.MEDIA).themed_urls(self.branding_favicon) 104 105 def branding_default_flow_background_url(self) -> str: 106 """Get branding_default_flow_background URL""" 107 return get_file_manager(FileUsage.MEDIA).file_url(self.branding_default_flow_background) 108 109 def branding_default_flow_background_themed_urls(self) -> dict[str, str] | None: 110 """Get themed URLs for branding_default_flow_background if it contains %(theme)s""" 111 return get_file_manager(FileUsage.MEDIA).themed_urls(self.branding_default_flow_background) 112 113 @property 114 def serializer(self) -> type[Serializer]: 115 from authentik.brands.api import BrandSerializer 116 117 return BrandSerializer 118 119 @property 120 def default_locale(self) -> str: 121 """Get default locale""" 122 try: 123 return self.attributes.get("settings", {}).get("locale", "") 124 125 except Exception as exc: # noqa 126 LOGGER.warning("Failed to get default locale", exc=exc) 127 return "" 128 129 def __str__(self) -> str: 130 if self.default: 131 return "Default brand" 132 return f"Brand {self.domain}" 133 134 class Meta: 135 verbose_name = _("Brand") 136 verbose_name_plural = _("Brands") 137 indexes = [ 138 models.Index(fields=["domain"]), 139 models.Index(fields=["default"]), 140 ]
Single brand
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
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.
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.
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.
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.
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.
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.
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.
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.
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.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
89 def branding_logo_url(self) -> str: 90 """Get branding_logo URL""" 91 return get_file_manager(FileUsage.MEDIA).file_url(self.branding_logo)
Get branding_logo URL
93 def branding_logo_themed_urls(self) -> dict[str, str] | None: 94 """Get themed URLs for branding_logo if it contains %(theme)s""" 95 return get_file_manager(FileUsage.MEDIA).themed_urls(self.branding_logo)
Get themed URLs for branding_logo if it contains %(theme)s
97 def branding_favicon_url(self) -> str: 98 """Get branding_favicon URL""" 99 return get_file_manager(FileUsage.MEDIA).file_url(self.branding_favicon)
Get branding_favicon URL
101 def branding_favicon_themed_urls(self) -> dict[str, str] | None: 102 """Get themed URLs for branding_favicon if it contains %(theme)s""" 103 return get_file_manager(FileUsage.MEDIA).themed_urls(self.branding_favicon)
Get themed URLs for branding_favicon if it contains %(theme)s
105 def branding_default_flow_background_url(self) -> str: 106 """Get branding_default_flow_background URL""" 107 return get_file_manager(FileUsage.MEDIA).file_url(self.branding_default_flow_background)
Get branding_default_flow_background URL
109 def branding_default_flow_background_themed_urls(self) -> dict[str, str] | None: 110 """Get themed URLs for branding_default_flow_background if it contains %(theme)s""" 111 return get_file_manager(FileUsage.MEDIA).themed_urls(self.branding_default_flow_background)
Get themed URLs for branding_default_flow_background if it contains %(theme)s
113 @property 114 def serializer(self) -> type[Serializer]: 115 from authentik.brands.api import BrandSerializer 116 117 return BrandSerializer
Get serializer for this model
119 @property 120 def default_locale(self) -> str: 121 """Get default locale""" 122 try: 123 return self.attributes.get("settings", {}).get("locale", "") 124 125 except Exception as exc: # noqa 126 LOGGER.warning("Failed to get default locale", exc=exc) 127 return ""
Get default locale
Inherited Members
The requested object does not exist
The query returned multiple objects when only one was expected.
143class WebfingerProvider(models.Model): 144 """Provider which supports webfinger discovery""" 145 146 class Meta: 147 abstract = True 148 149 def webfinger(self, resource: str, request: HttpRequest) -> dict: 150 raise NotImplementedError()
Provider which supports webfinger discovery