zoukankan      html  css  js  c++  java
  • Django的JWT机制工作流程

    https://blog.csdn.net/bin_1022/article/details/81278513

    django-rest-framework-jwt token 怎么解码得到用户名?

        def get(self, request):
    
            auth = request.auth  # 前段传来的token在request.auth中
            print(auth)
            from rest_framework_jwt.utils import jwt_decode_handler
            b = jwt_decode_handler(auth)
            print(b)
            return Response('11')

    解码后:

    {'username': '18120192554', 'exp': 1536545855, 'user_id': 2, 'email': None}

    如何手动签发token?

    例如,注册成功后,返回前段token

        def post(self, request):
            serializer = RegisterSerializer(data=request.data)
            if serializer.is_valid():
                user_o = serializer.save()
                # 注册成功后,手动签发token
                payload = jwt_payload_handler(user_o)
                token = jwt_encode_handler(payload)
                return Response({'status': 0, 'meg': '创建成功', 'token': token})
            else:
                return Response(serializer.errors)
  • 相关阅读:
    LeetCode 21. 合并两个有序链表
    LeetCode 20. 有效的括号
    LeetCode 19. 删除链表的倒数第N个节点
    AI
    http
    IP地址
    wiodows /linux CMD
    git
    AI
    JS常用的获取值和设值的方法
  • 原文地址:https://www.cnblogs.com/yuqiangli0616/p/9612693.html
Copyright © 2011-2022 走看看