前端应用程序中的JWT身份验证流程?

时间:2020-04-26 16:18:59

标签: javascript spring rest jwt auth0

我有一个简单的CRUD Java Spring-boot REST API,它连接到MongoDB,以保存/获取有关用户扑克统计信息的信息。该API当前不受JWT保护。

API如下所示:

GET - /users/{userId}/games : gets all games relating to a user
GET - /users/{userId}/games/{roundId} : get a specific game relating to a user
POST - /users/{userId}/games/ : create a game
DELETE - /users/{userId}/games/{roundId} : Delete a game
PATCH - /users/{userId}/games/{roundId} : edit a game

我正在向Web应用程序添加前端,我正在学习JavaScript,但尚未开始学习特定的框架。

在开始开发应用程序的前端之前,我想验证下面的Authorisation/Authentication流是否正确/有效?

1. User presses login button on client (e.g express/angular app) - this hits the /login endpoint
2. Auth0 redirects client to /authorise endpoint and displays login page for User
3. Auth0 verifies username and password against DB to check if a valid user
4. If login is successful: Auth0 redirects back to a specific page on the client with a JWT Token
5. Client Application stores the JWT to use in future requests
5. This JWT can then be used to make REST API calls to Java REST API

1 个答案:

答案 0 :(得分:1)

是的,仅此而已,只需考虑几件事:

  • 获取用户,以在客户端上显示用户名
  • 您如何在客户端上存储JWT令牌
  • 如果您想使用社交登录,则变得更加棘手

我会考虑使用客户端框架,以完成所有这些工作。