Skip to content
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

Refresh custom claims #33

Closed
madmoizo opened this issue Jul 14, 2018 · 1 comment
Closed

Refresh custom claims #33

madmoizo opened this issue Jul 14, 2018 · 1 comment

Comments

@madmoizo
Copy link

madmoizo commented Jul 14, 2018

Hi,

I switched from django-rest-framework-jwt to django-rest-framework-simplejwt.

  • I'm using a sliding token
  • I override TokenObtainSlidingSerializer get_token methods to add custom claims (first_name, last_name, ...)
  • Users can update some of these data in the app

Problem: refresh the token just update the exp value. Is there a way to refresh custom claims with fresh data too ?

@madmoizo madmoizo changed the title Refresh custom data Refresh custom claims Jul 14, 2018
@davesque
Copy link
Member

The only way to do that currently is to do something like this:

class MyRefreshSlidingSerializer(TokenRefreshSlidingSerializer):
    def validate(self, attrs):
        token = SlidingToken(attrs['token'])
        token.check_exp(api_settings.SLIDING_TOKEN_REFRESH_EXP_CLAIM)
        token.set_exp()

        # Do custom stuff here
        # ...

        return {'token': text_type(token)}

class MyRefreshSlidingView(TokenViewBase):
    serializer_class = MyRefreshSlidingSerializer

token_refresh_sliding = MyRefreshSlidingView.as_view()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants