📄️ 3.1 Preface
We need to implement user session management functions, including login and user information retrieval. JWT is a modern solution for user authentication, transmitted through HTTP headers, not relying on Cookies and supporting cross-domain. JWT consists of Header, Payload, and Signature and is widely used in frontend-backend separation projects.
📄️ 3.2 Login
The login function generates a Token upon successful verification by receiving the username and password. Using the GoFrame framework, it adheres to the development principle of Three Boards, including Api generation Controller, and writing core Logic logic. The JwtKey is used to generate the signature, and the Token is valid for six hours. The core logic is invoked in the Controller to implement the login function, and the interface is tested to ensure functionality.
📄️ 3.3 Get User Information
The user information API requires login to access and uniformly validates the token's validity through middleware. The GoFrame framework provides a flexible middleware mechanism supporting pre-and post-request operations. The Auth middleware verifies the token in an HTTP request, extracts user information in Logic by parsing the token, and accesses the user information API through API and Controller definitions for access control and authentication.
📄️ 3.4 Summary
With GoFrame, accomplish user session management, implementing login and user information retrieval. Understand GoFrame in depth through token generation and user information interface declaration. Introduce middleware for user permission authentication applied in grouped routing. When using JWT, address the logout issue with blacklist and whitelist mechanisms, discussing their pros, cons, and implementation methods.