[英]How to use DRF JWT resfresh
I can generate token,However, after the Web accesses me with the first token, I cannot give a new token可以生成token,但是Web用第一个token访问我后,不能给新token
I set it in setting我在设置中设置
'JWT_ALLOW_REFRESH': True,
But I don't know how to get a new one但是不知道怎么换新的
Please let me know if you need anything else如果您还需要什么,请告诉我
I thought that after this setting is completed, the token will be changed automatically Medium expiration time,Looks like I'm wrong我以为这个设置完成后token会自动更改 中过期时间,貌似我错了
based on this post, you have to do the following:根据这篇文章,您必须执行以下操作:
http post http://127.0.0.1:8000/api/token/ username=vitor password=123
请求令牌http post http://127.0.0.1:8000/api/token/ username=vitor password=123
http post http://127.0.0.1:8000/api/token/refresh/ refresh=REFRESHTOKEN
如果访问令牌过期(站点返回 403),则使用刷新令牌获取新的有效访问令牌http post http://127.0.0.1:8000/api/token/refresh/ refresh=REFRESHTOKEN
Note that the refresh token can also expire, then you would have to restart the flow.请注意,刷新令牌也可能过期,然后您必须重新启动流程。
EDIT: code snippets编辑:代码片段
pip install djangorestframework_simplejwt
REST_FRAMEWORK = {
...
'DEFAULT_AUTHENTICATION_CLASSES': (
...
'rest_framework_simplejwt.authentication.JWTAuthentication',
)
...
}
from django.urls import path
from rest_framework_simplejwt import views as jwt_views
urlpatterns = [
# Your URLs...
path('api/token/', jwt_views.TokenObtainPairView.as_view(), name='token_obtain_pair'),
path('api/token/refresh/', jwt_views.TokenRefreshView.as_view(), name='token_refresh'),
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.