-
Notifications
You must be signed in to change notification settings - Fork 0
Session & Token #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Token基于 token 认证方式,不需要在服务端去保留用户的认证信息或者会话信息。这就意味着基于 token 认证机制的应用不需要去考虑用户在哪一台服务器登录了,这就为应用的扩展提供了便利。
JSON Web Token(缩写 JWT)是 token 认证的一种具体实现。 JWT 的原理JWT 的原理是,服务器认证以后,生成一个 JSON 对象,发回给用户,就像下面这样。 {
"姓名": "张三",
"角色": "管理员",
"到期时间": "2018年7月1日0点0分"
} 以后,用户与服务端通信的时候,都要发回这个 JSON 对象。服务器完全只靠这个对象认定用户身份。为了防止用户篡改数据,服务器在生成这个对象的时候,会加上签名。 JWT 的数据结构JWT 工作流程
可以把它放在 Cookie 里面自动发送,但是这样不能跨域,所以更好的做法是放在 HTTP 请求的头信息
总结
参考资料 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HTTP 协议是无状态协议,所以服务器端必须部署相关的逻辑来保持用户的认证状态。
目前主流有两种 Session 和 Token
The text was updated successfully, but these errors were encountered: