django-graphql-jwt icon indicating copy to clipboard operation
django-graphql-jwt copied to clipboard

revoke_refresh_token not firing

Open Delvio opened this issue 4 years ago • 3 comments

Hi, I am trying to implement one-time use refresh token, I created the signal as the documentation stated but it's firing:

from django.dispatch import receiver
from graphql_jwt.refresh_token.signals import refresh_token_rotated



@receiver(refresh_token_rotated, sender=RefreshToken)
def revoke_refresh_token(sender, request, refresh_token, **kwargs):
    refresh_token.revoke(refresh_token)
    print("Please work this time")

whenever I generate a new refresh_token using a previous refresh_token nothing happens.

Delvio avatar Jun 06 '20 22:06 Delvio

A am tried too, it is not working

furkan-guvenc avatar Jun 07 '20 20:06 furkan-guvenc

Any updates on this?

berkcoker avatar Oct 05 '21 20:10 berkcoker

Is it because the sender is the RefreshTokenMixin rather than the RefreshToken model? Looking at this line here https://github.com/flavors/django-graphql-jwt/blob/704f24e7ebbea0b81015ef3c1f4a302e9d432ecf/graphql_jwt/refresh_token/mixins.py#L57 the sender is cls not the model itself.

Which means to fix it just remove the sender from the signal receiver call, as per Django docs specifying that sender would only filter the signals out to your disadvantage in this case.

@receiver(refresh_token_rotated)
def revoke_refresh_token(sender, request, refresh_token, **kwargs):
    refresh_token.revoke(refresh_token)
    print("This should work now")

marcinocto avatar Jan 07 '22 11:01 marcinocto