简体   繁体   English

何时在 DRF 中的 jwt 中调用 gettoken、刷新令牌和验证令牌?

[英]When to call gettoken, refresh token and verify token by user in jwt in DRF?

I have been using built in token authentication for my projects in Django rest framework.我一直在 Django rest 框架中为我的项目使用内置令牌身份验证 But now I am shifting to simple jwt .但现在我正在转向简单的 jwt But I am confused on one thing.但我对一件事感到困惑。

In Token Authentication user if logged in from front end returns a token, but in jwt documentation I have seen three requests as follows:在令牌身份验证用户中,如果从前端登录会返回一个令牌,但在 jwt 文档中我看到了三个请求,如下所示:

urlpatterns = [    
url(r'^auth-jwt/', obtain_jwt_token),     
url(r'^auth-jwt-refresh/', refresh_jwt_token),     
url(r'^auth-jwt-verify/', verify_jwt_token),
 ]

I dont quite understand these requests.我不太明白这些要求。 As a normal user, when a user visits a site he doesn't ask to get token, refresh token and verify token, he simply logs in and uses the features of the site.作为普通用户,当用户访问一个站点时,他不要求获取令牌、刷新令牌和验证令牌,他只需登录并使用该站点的功能。 So, I am asking when these requests are made?所以,我问这些请求是什么时候提出的?

I hope I have explained well.我希望我已经解释得很好。

The usual flow of JWT authentication goes likes this: JWT 身份验证的通常流程如下:

  1. The client will send a POST request with the authentication credentials, which need to be verified.客户端将发送一个POST请求,其中包含需要验证的身份验证凭据。 If the credentials are valid the server needs to return JWT Token and a refresh token.如果凭据有效,则服务器需要返回 JWT 令牌和刷新令牌。 This process is handled by the url(r'^auth-jwt/', obtain_jwt_token) URL.这个过程由url(r'^auth-jwt/', obtain_jwt_token) URL 处理。

  2. The token returned after authentication is a short-lived token and to continue the user session, the client needs to get a new token using the refresh token.认证后返回的令牌是一个短暂的令牌,并且要继续用户 session,客户端需要使用刷新令牌获取新令牌。 This is done by url(r'^auth-jwt-refresh/', refresh_jwt_token) URL.这是由url(r'^auth-jwt-refresh/', refresh_jwt_token) URL 完成的。

The third URL is not always required.并不总是需要第三个 URL。 You can use it to validate your JWT token in case it's required by your application.您可以使用它来验证您的 JWT 令牌,以防您的应用程序需要它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM