Skip to content

User ID method handling #169

@ethanjahn

Description

@ethanjahn

Hi, thanks for the great work on this project!

I am using Auth0 and have been using the now deprecated django-rest-framework-jwt library but would like to switch to simplejwt. Part of the implementation I was using used a function to alter a username from the token and authenticate the user in Django's User model.

The relevant function is:

# auth0authorization/user.py

from django.contrib.auth import authenticate

def jwt_get_username_from_payload_handler(payload):
    username = payload.get('sub').replace('|', '.')
    authenticate(remote_user=username)
    return username

and the setting in django-rest-framework-jwt is:

JWT_AUTH = {
    'JWT_PAYLOAD_GET_USERNAME_HANDLER':
        'auth0authorization.user.jwt_get_username_from_payload_handler'
   ...
}

This is necessary because Auth0 uses usernames that look like "auth0|username" and they recommend storing as "auth0.username" in the User model (not fully sure why) and also because I need to authenticate the remote user before the token user_id claim means anything.

Do you know if there is a way to use a function upon receiving the JWT token in simplejwt? Alternatively, if there is a workaround happy to implement it!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions