customize the get_payload function in django-graphql-jwt

459 Views Asked by At

please, how can I customise the get_payload function in django-graphql-jwt?

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
1

There are 1 best solutions below

0
On

here is the solution that I did for the moment:

I added this JWT_DECODE_HANDLER setting to GRAPHQL_JWT:

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

than here is my customized_jwt_decode function:

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