コード例 #1
0
    def get_jwt_user(request):
        user = get_user(request)
        if user.is_authenticated:
            return user
        jwt_authentication = JSONWebTokenAuthentication()
        if jwt_authentication.get_jwt_value(request):
            jwt_value = jwt_authentication.get_jwt_value(request)
            import jwt
            try:
                payload = jwt_decode_handler(jwt_value)
            except jwt.ExpiredSignature:
                print("Signature expired.")
                msg = {
                    'jwtResponse': 'Signature has expired.'
                }
                return msg
            except jwt.DecodeError:
                print('Error decoding signature.')
                msg = {
                    'jwtResponse': 'Error decoding signature.'
                }
                return msg
            except jwt.InvalidTokenError:
                print("invalid token error")
                return exceptions.AuthenticationFailed()

            user = jwt_authentication.authenticate_credentials(payload)

            user, jwt = jwt_authentication.authenticate(request)
        return user
コード例 #2
0
ファイル: middleware.py プロジェクト: ajayram1509/movietest
 def get_jwt_user(self, request):
     user = None
     user = get_user(request)
     msg = None
     if user.is_authenticated:
         return user, msg
     jwt_authentication = JSONWebTokenAuthentication()
     token = jwt_authentication.get_jwt_value(request)
     if token:
         try:
             payload = jwt_decode_handler(token)
         except jwt.ExpiredSignature:
             msg = 'Signature has expired.'
         except jwt.DecodeError:
             msg = 'Error decoding signature.'
         except jwt.InvalidTokenError:
             msg = "Invalid Token/Credentials."
         if not msg:
             user = jwt_authentication.authenticate_credentials(payload)
     return user, msg