-
Notifications
You must be signed in to change notification settings - Fork 306
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
Modify JWT Serializer Field Names #501
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greetings ! While you're at it, can you add refresh_expiration
field to dj_rest_auth.jwt_auth.get_refresh_view's response data since we are already returning an access expiration timestamp ?
def get_refresh_view():
""" Returns a Token Refresh CBV without a circular import """
from rest_framework_simplejwt.settings import api_settings as jwt_settings
from rest_framework_simplejwt.views import TokenRefreshView
class RefreshViewWithCookieSupport(TokenRefreshView):
serializer_class = CookieTokenRefreshSerializer
def finalize_response(self, request, response, *args, **kwargs):
if response.status_code == status.HTTP_200_OK and 'access' in response.data:
set_jwt_access_cookie(response, response.data['access'])
response.data['access_expiration'] = (timezone.now() + jwt_settings.ACCESS_TOKEN_LIFETIME)
if response.status_code == status.HTTP_200_OK and 'refresh' in response.data:
set_jwt_refresh_cookie(response, response.data['refresh'])
response.data['refresh_expiration'] = (timezone.now() + jwt_settings.REFRESH_TOKEN_LIFETIME)
return super().finalize_response(request, response, *args, **kwargs)
return RefreshViewWithCookieSupport
Good call @zackkh. I saw that but didn't dawn on me to include it. Let me know if there's anything else to be done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes are 5/5 and match up with djangorestframework-simplejwt
.
Closes #142
This change modifies the
JWTSerializer
fields to beaccess
andresponse
to align with the naming of rest_framework_jwt.serializers.TokenRefreshSerializerWith
rest_framework_simplejwt
being tightly coupled into the JWT usage, this made sense to adhere to the upstream dependency naming standards.Ultimately, it's ugly when using JWT to check for
access_token
names when authenticating, and then usingaccess
for a refresh.