0

请问,如何在django-graphql-jwt中自定义get_payload函数?

def get_payload(token, context=None):
    try:
        payload = jwt_settings.JWT_DECODE_HANDLER(token, context)
    except jwt.ExpiredSignature:
        raise exceptions.JSONWebTokenExpired()
    except jwt.DecodeError:
        raise exceptions.JSONWebTokenError(_('Error decoding signature'))
    except jwt.InvalidTokenError:
        raise exceptions.JSONWebTokenError(_('Invalid token'))
    return payload
4

1 回答 1

0

这是我目前所做的解决方案:

我将此JWT_DECODE_HANDLER设置添加到GRAPHQL_JWT

    GRAPHQL_JWT = {
        'JWT_DECODE_HANDLER': 'path_to_your_customized_jwt_decode',
    }

比这是我的customized_jwt_decode功能:

from graphql_jwt.utils import jwt_decode

def customized_jwt_decode(token, context=None):
    try:
        payload = jwt_decode(token, context)
    except YourExceptionHere:
        # that ever you wanna do 
    return payload
于 2020-04-01T15:05:22.123 回答