-
Notifications
You must be signed in to change notification settings - Fork 670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extending RefreshToken method to use customized token claims #481
Comments
This is the same as my question. |
Summary: Change
|
in RefreshToken.for_user(user), can't I pass any other parameter I want to include in the payload? |
I'm having the same problem.
So, I thought about Subclassing From my point of view, the easier solution would be add a hook at the end of the @classmethod
def for_user(cls, user):
"""
Returns an authorization token for the given user that will be provided
after authenticating the user's credentials.
"""
user_id = getattr(user, api_settings.USER_ID_FIELD)
if not isinstance(user_id, int):
user_id = str(user_id)
token = cls()
token[api_settings.USER_ID_CLAIM] = user_id
token = cls.for_user_post_hook(user, token)
return token
def for_user_post_hook(cls, User, token):
# does nothing by default, but allows custom behaviours
return token What do you think about it? That being said, I believe storing the full tokens in DB seems like a security risk, as someone already pointed out. I believe we should only store the jti and token expiration, and maybe the I'd be happy to make a PR for that if you'd like. |
I used the docs straightforward instructions on how to extend the get_token method of MyTokenObtainSerializer to include a custom claim in the JWT token it produced. However, I am trying to extend the RefreshToken.for_user() method in the same way and I'm not sure how to go about doing it. Admittedly, my understanding of inheritance in python is tenuous.
The text was updated successfully, but these errors were encountered: