2022-08-04 06:40:33 +00:00
|
|
|
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from rest_framework import serializers
|
|
|
|
|
|
|
|
from common.drf.fields import EncryptedField
|
|
|
|
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):
|
2022-11-04 06:22:38 +00:00
|
|
|
PREFIX_TITLE = '%s-%s' % (_('Authentication'), _('OAuth2'))
|
|
|
|
|
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(
|
|
|
|
required=False, max_length=1024, label=_('Provider end session endpoint')
|
|
|
|
)
|
|
|
|
AUTH_OAUTH2_LOGOUT_COMPLETELY = serializers.BooleanField(required=False, label=_('Logout completely'))
|
2022-08-04 06:40:33 +00:00
|
|
|
AUTH_OAUTH2_USER_ATTR_MAP = serializers.DictField(
|
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
|
|
|
)
|