Example #1
0
def jwt_encode_handler(payload):
    key = api_settings.JWT_PRIVATE_KEY or jwt_get_secret_key(payload)
    return jwt.encode(
        payload,
        key,
        api_settings.JWT_ALGORITHM
    ).decode('utf-8')
Example #2
0
def jwt_decode_handler(token):
    options = {
        'verify_exp': api_settings.JWT_VERIFY_EXPIRATION,
    }
    # get user from token, BEFORE verification, to get user secret key
    unverified_payload = jwt.decode(token, None, False)
    secret_key = jwt_get_secret_key(unverified_payload)
    return jwt.decode(token,
                      api_settings.JWT_PUBLIC_KEY or secret_key,
                      api_settings.JWT_VERIFY,
                      options=options,
                      leeway=api_settings.JWT_LEEWAY,
                      algorithms=[api_settings.JWT_ALGORITHM])
Example #3
0
def jwt_decode_handler(token):
    options = {
        'verify_exp': api_settings.JWT_VERIFY_EXPIRATION,
    }
    # get user from token, BEFORE verification, to get user secret key
    unverified_payload = jwt.decode(token, None, False)
    secret_key = jwt_get_secret_key(unverified_payload)
    return jwt.decode(token,
                      b64decode(secret_key),
                      api_settings.JWT_VERIFY,
                      options=options,
                      leeway=api_settings.JWT_LEEWAY,
                      audience=api_settings.JWT_AUDIENCE,
                      issuer=api_settings.JWT_ISSUER,
                      algorithms=[api_settings.JWT_ALGORITHM])
Example #4
0
def jwt_decode_handler(token, options=None):
    if not options:
        options = {}
    options.setdefault("verify_exp", api_settings.JWT_VERIFY_EXPIRATION)
    # get user from token, BEFORE verification, to get user secret key
    unverified_payload = jwt.decode(token, None, False)
    secret_key = jwt_get_secret_key(unverified_payload)
    return jwt.decode(
        token,
        api_settings.JWT_PUBLIC_KEY or secret_key,
        api_settings.JWT_VERIFY,
        options=options,
        leeway=api_settings.JWT_LEEWAY,
        audience=api_settings.JWT_AUDIENCE,
        issuer=api_settings.JWT_ISSUER,
        algorithms=[api_settings.JWT_ALGORITHM],
    )
Example #5
0
def jwt_decode_handler(token, isRefresh=False):
    options = {
        'verify_exp': api_settings.JWT_VERIFY_EXPIRATION,
    }
    if isRefresh:
        options = {
            'verify_exp': False,
        }

    unverified_payload = jwt.decode(token, None, False)
    secret_key = jwt_get_secret_key(unverified_payload)
    return jwt.decode(token,
                      api_settings.JWT_PUBLIC_KEY or secret_key,
                      api_settings.JWT_VERIFY,
                      options=options,
                      leeway=api_settings.JWT_LEEWAY,
                      audience=api_settings.JWT_AUDIENCE,
                      issuer=api_settings.JWT_ISSUER,
                      algorithms=[api_settings.JWT_ALGORITHM])
Example #6
0
def jwt_decode_handler_for_refresh_token(token):
    '''
    This code is from here:
    https://github.com/jpadilla/django-rest-framework-jwt/blob/master/rest_framework_jwt/utils.py#L99
    but i override `leeway` parameter in jwt.decode()
    '''
    options = {
        'verify_exp': api_settings.JWT_VERIFY_EXPIRATION,
    }
    # get user from token, BEFORE verification, to get user secret key
    unverified_payload = jwt.decode(token, None, False)
    secret_key = jwt_get_secret_key(unverified_payload)
    return jwt.decode(token,
                      api_settings.JWT_PUBLIC_KEY or secret_key,
                      api_settings.JWT_VERIFY,
                      options=options,
                      leeway=api_settings.JWT_REFRESH_EXPIRATION_DELTA,
                      audience=api_settings.JWT_AUDIENCE,
                      issuer=api_settings.JWT_ISSUER,
                      algorithms=[api_settings.JWT_ALGORITHM])