Django JWT Refresh Asking for Email and Password

Viewed 161

I'm trying to implement JWT in django and am using rest_framework_simple_jwt. The TokenObtainPairView is working properly and gives me the access and refresh token when I pass the email and password in the body. However, when I use the TokenRefreshView, it doesn't work and asks me for the email and password even though I should only have to pass the refresh token in the body. Any help here would be appreciated!

url('^api/token/', jwt_views.TokenObtainPairView.as_view(), name='token_obtain_pair'),
url('^api/token/refresh/', jwt_views.TokenRefreshView.as_view(), name='token_refresh'),
1 Answers

I had the same issue, and finally resolved it! The solution is changing the definition order.

Try;

url('^api/token/refresh/', jwt_views.TokenRefreshView.as_view(), name='token_refresh'),
url('^api/token/', jwt_views.TokenObtainPairView.as_view(), name='token_obtain_pair'),

instead of;

url('^api/token/', jwt_views.TokenObtainPairView.as_view(), name='token_obtain_pair'),
url('^api/token/refresh/', jwt_views.TokenRefreshView.as_view(), name='token_refresh'),
Related