2022-08-04 06:40:33 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from rest_framework import serializers
|
|
|
|
|
2023-01-16 11:02:09 +00:00
|
|
|
from common.serializers.fields import EncryptedField
|
2022-08-04 06:40:33 +00:00
|
|
|
from common.utils import static_or_direct
|
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
'OAuth2SettingSerializer',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class SettingImageField(serializers.ImageField):
|
|
|
|
def to_representation(self, value):
|
|
|
|
return static_or_direct(value)
|
|
|
|
|
|
|
|
|
|
|
|
class OAuth2SettingSerializer(serializers.Serializer):
|
2023-02-23 08:38:44 +00:00
|
|
|
PREFIX_TITLE = _('OAuth2')
|
2022-11-04 06:22:38 +00:00
|
|
|
|
2022-08-04 06:40:33 +00:00
|
|
|
AUTH_OAUTH2 = serializers.BooleanField(
|
2022-08-15 08:52:45 +00:00
|
|
|
default=False, label=_('Enable OAuth2 Auth')
|
2022-08-04 06:40:33 +00:00
|
|
|
)
|
|
|
|
AUTH_OAUTH2_LOGO_PATH = SettingImageField(
|
|
|
|
allow_null=True, required=False, label=_('Logo')
|
|
|
|
)
|
|
|
|
AUTH_OAUTH2_PROVIDER = serializers.CharField(
|
2022-08-15 08:52:45 +00:00
|
|
|
required=True, max_length=16, label=_('Service provider')
|
2022-08-04 06:40:33 +00:00
|
|
|
)
|
|
|
|
AUTH_OAUTH2_CLIENT_ID = serializers.CharField(
|
2022-08-15 08:52:45 +00:00
|
|
|
required=True, max_length=1024, label=_('Client Id')
|
2022-08-04 06:40:33 +00:00
|
|
|
)
|
|
|
|
AUTH_OAUTH2_CLIENT_SECRET = EncryptedField(
|
|
|
|
required=False, max_length=1024, label=_('Client Secret')
|
|
|
|
)
|
|
|
|
AUTH_OAUTH2_SCOPE = serializers.CharField(
|
2022-08-15 08:52:45 +00:00
|
|
|
required=True, max_length=1024, label=_('Scope'), allow_blank=True
|
2022-08-04 06:40:33 +00:00
|
|
|
)
|
|
|
|
AUTH_OAUTH2_PROVIDER_AUTHORIZATION_ENDPOINT = serializers.CharField(
|
2022-08-15 08:52:45 +00:00
|
|
|
required=True, max_length=1024, label=_('Provider auth endpoint')
|
2022-08-04 06:40:33 +00:00
|
|
|
)
|
|
|
|
AUTH_OAUTH2_ACCESS_TOKEN_ENDPOINT = serializers.CharField(
|
2022-08-15 08:52:45 +00:00
|
|
|
required=True, max_length=1024, label=_('Provider token endpoint')
|
2022-08-04 06:40:33 +00:00
|
|
|
)
|
|
|
|
AUTH_OAUTH2_ACCESS_TOKEN_METHOD = serializers.ChoiceField(
|
|
|
|
default='GET', label=_('Client authentication method'),
|
|
|
|
choices=(('GET', 'GET'), ('POST', 'POST'))
|
|
|
|
)
|
|
|
|
AUTH_OAUTH2_PROVIDER_USERINFO_ENDPOINT = serializers.CharField(
|
2022-08-15 08:52:45 +00:00
|
|
|
required=True, max_length=1024, label=_('Provider userinfo endpoint')
|
2022-08-04 06:40:33 +00:00
|
|
|
)
|
2022-08-26 09:59:16 +00:00
|
|
|
AUTH_OAUTH2_PROVIDER_END_SESSION_ENDPOINT = serializers.CharField(
|
2023-02-09 03:20:54 +00:00
|
|
|
required=False, allow_blank=True, max_length=1024, label=_('Provider end session endpoint')
|
2022-08-26 09:59:16 +00:00
|
|
|
)
|
|
|
|
AUTH_OAUTH2_LOGOUT_COMPLETELY = serializers.BooleanField(required=False, label=_('Logout completely'))
|
2023-06-08 02:06:14 +00:00
|
|
|
AUTH_OAUTH2_USER_ATTR_MAP = serializers.JSONField(
|
2022-08-15 08:52:45 +00:00
|
|
|
required=True, label=_('User attr map')
|
2022-08-04 06:40:33 +00:00
|
|
|
)
|
|
|
|
AUTH_OAUTH2_ALWAYS_UPDATE_USER = serializers.BooleanField(
|
2022-08-15 08:52:45 +00:00
|
|
|
default=True, label=_('Always update user')
|
2022-08-04 06:40:33 +00:00
|
|
|
)
|