当前位置: 首页>>代码示例>>Python>>正文


Python api_settings.JWT_ENCODE_HANDLER属性代码示例

本文整理汇总了Python中rest_framework_jwt.settings.api_settings.JWT_ENCODE_HANDLER属性的典型用法代码示例。如果您正苦于以下问题:Python api_settings.JWT_ENCODE_HANDLER属性的具体用法?Python api_settings.JWT_ENCODE_HANDLER怎么用?Python api_settings.JWT_ENCODE_HANDLER使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在rest_framework_jwt.settings.api_settings的用法示例。


在下文中一共展示了api_settings.JWT_ENCODE_HANDLER属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_token

# 需要导入模块: from rest_framework_jwt.settings import api_settings [as 别名]
# 或者: from rest_framework_jwt.settings.api_settings import JWT_ENCODE_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_ENCODE_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_ENCODE_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_ENCODE_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_ENCODE_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_ENCODE_HANDLER属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。