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

2017.3.24 - JWT #14

Open
stephenLYZ opened this issue Mar 26, 2017 · 0 comments
Open

2017.3.24 - JWT #14

stephenLYZ opened this issue Mar 26, 2017 · 0 comments

Comments

@stephenLYZ
Copy link
Owner

stephenLYZ commented Mar 26, 2017

JWT介绍

JSON Web Token(JWT)是一个开放的标准(RFC 7519),该标准定义了一个在两者之间安全的使用 JSON 对象传递信息的方式。可以在以下场景中使用:

  • 登录验证。 一旦用户登录之后,每个后续的请求将包含 JWT,通过这个令牌允许用户访问路由、服务和资源。单点登录就是一个例子
  • 信息交流。JSON Web Token 是在不同部分传递信息的好方法,因为它们可以被签署,例如使用 public/private key,可以确定的是发送者是谁。

JWT的组成:

Header

由两部分构成: token的type,以及加密的算法:

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

Payload

包含三种类型的claims: reserved,public,private.

{
  "sub": "1234567890",
  "name": "John Doe",
  "admin": true
}

Signature

需要提供header编码, payload编码, 密匙, 加密算法:

HMACSHA256(
  base64UrlEncode(header) + "." +
  base64UrlEncode(payload),
  secret)

一个JWT一般长这样: xxx.yyy.zzz.

legacy-app-auth-5

下图显示了JWT是如何工作的:

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