當前位置: 首頁>>代碼示例>>Python>>正文


Python api_settings.JWT_PAYLOAD_HANDLER屬性代碼示例

本文整理匯總了Python中rest_framework_jwt.settings.api_settings.JWT_PAYLOAD_HANDLER屬性的典型用法代碼示例。如果您正苦於以下問題:Python api_settings.JWT_PAYLOAD_HANDLER屬性的具體用法?Python api_settings.JWT_PAYLOAD_HANDLER怎麽用?Python api_settings.JWT_PAYLOAD_HANDLER使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在rest_framework_jwt.settings.api_settings的用法示例。


在下文中一共展示了api_settings.JWT_PAYLOAD_HANDLER屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_token

# 需要導入模塊: from rest_framework_jwt.settings import api_settings [as 別名]
# 或者: from rest_framework_jwt.settings.api_settings import JWT_PAYLOAD_HANDLER [as 別名]
def get_token(self, obj):
        warnings.warn(
            'Support of djangorestframework-jwt will be removed in 3.0.0 version. '
            'Use rest_framework_simplejwt instead.',
            DeprecationWarning,
        )
        try:
            from rest_framework_jwt.settings import api_settings
        except ImportError:
            warnings.warn('djangorestframework-jwt must be installed for JWT authentication',
                          ImportWarning)
            raise

        jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
        jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER

        payload = jwt_payload_handler(self.get_jwt_payload(obj))
        token = jwt_encode_handler(payload)

        return token 
開發者ID:st4lk,項目名稱:django-rest-social-auth,代碼行數:22,代碼來源:serializers.py

示例2: create

# 需要導入模塊: from rest_framework_jwt.settings import api_settings [as 別名]
# 或者: from rest_framework_jwt.settings.api_settings import JWT_PAYLOAD_HANDLER [as 別名]
def create(self, request, *args, **kwargs):
        serializer = self.serializer_class(data=request.data)
        jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
        jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER
        try:
            if serializer.is_valid(raise_exception=True):
                student = serializer.create(request.data)
                jwt_token = {
                    'token': jwt_encode_handler(jwt_payload_handler(student.user))
                }
                return Response(jwt_token, status=status.HTTP_201_CREATED)
        except IntegrityError:
            serializer.error_messages = {
                'Error': 'Student with that username already exists!'}
        return Response(serializer.error_messages, status=status.HTTP_400_BAD_REQUEST) 
開發者ID:JBossOutreach,項目名稱:certificate-generator-server-archive,代碼行數:17,代碼來源:views.py

示例3: resolve_token

# 需要導入模塊: from rest_framework_jwt.settings import api_settings [as 別名]
# 或者: from rest_framework_jwt.settings.api_settings import JWT_PAYLOAD_HANDLER [as 別名]
def resolve_token(self, args, context, info):
        if (not context or not context.user or self.id != context.user.id) and not getattr(self, 'is_current_user', False):
            return None

        jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
        jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER

        payload = jwt_payload_handler(self)
        token = jwt_encode_handler(payload)

        return token 
開發者ID:morgante,項目名稱:django-graph-auth,代碼行數:13,代碼來源:schema.py

示例4: jwt_encode

# 需要導入模塊: from rest_framework_jwt.settings import api_settings [as 別名]
# 或者: from rest_framework_jwt.settings.api_settings import JWT_PAYLOAD_HANDLER [as 別名]
def jwt_encode(user):
    try:
        from rest_framework_jwt.settings import api_settings
    except ImportError:
        raise ImportError("djangorestframework_jwt needs to be installed")

    jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
    jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER

    payload = jwt_payload_handler(user)
    return jwt_encode_handler(payload) 
開發者ID:Tivix,項目名稱:django-rest-auth,代碼行數:13,代碼來源:utils.py

示例5: generate_jwt_token

# 需要導入模塊: from rest_framework_jwt.settings import api_settings [as 別名]
# 或者: from rest_framework_jwt.settings.api_settings import JWT_PAYLOAD_HANDLER [as 別名]
def generate_jwt_token(user, data):
    jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
    jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER
    payload = jwt_payload_handler(user)
    token = jwt_encode_handler(payload)
    data['token'] = token
    return data 
開發者ID:SystangoTechnologies,項目名稱:DjangoUnboxed,代碼行數:9,代碼來源:utils.py


注:本文中的rest_framework_jwt.settings.api_settings.JWT_PAYLOAD_HANDLER屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。