Skip to content
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

关于 JWT 的理解 #83

Open
iiuhuy opened this issue Mar 12, 2020 · 0 comments
Open

关于 JWT 的理解 #83

iiuhuy opened this issue Mar 12, 2020 · 0 comments

Comments

@iiuhuy
Copy link
Owner

iiuhuy commented Mar 12, 2020

关于 JWT 的理解

JWT => JSON Web Token 的缩写, 是一种轻量级的用户与服务器信息床底规范, 相应规范的标准可以在 RFC 7519 查看, 官网在 jwt.io

jwt 是一个加密过的字符串, 由 Header, payload, signature 三部分组成, 并通过符号 . 对三部分进行拼接. 如 xxx.yyy.zzz

Header

Header 部分描述了相应的 JWT 的类型和相应的签名算法, 如:

{
  "alg": "HS256",
  "typ": "JWT"
}

payload

{ 
  "iss": "Online JWT Builder",
  "iat": 1416797419,
  "exp": 1448333419,
  "aud": "www.example.com",
  "sub": "jrocket@example.com",
  "GivenName": "Johnny",
  "Surname": "Rocket",
  "Email": "jrocket@example.com",
  "Role": [ "Manager", "Project Administrator" ]
}
  • iss: 该 JWT 的签发者,是否使用是可选的;
  • iat (issued at): 在什么时候签发的 (UNIX 时间),是否使用是可选的;
  • exp (expires): 什么时候过期,这里是一个 Unix 时间戳,是否使用是可选的;
  • aud: 接收该 JWT 的一方,是否使用是可选的;
  • sub: 该 JWT 所面向的用户,是否使用是可选的;

其他还有:

nbf (Not Before):如果当前时间在 nbf 里的时间之前,则 Token 不被接受;一般都会留一些余地,比如几分钟;,是否使用是可选的;

对上面的信息进行 base 编码得到了对应的字符串

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant