一张图了解javaJwt

1.什么是javaJwt?html

JSON Web Tokens are an open, industry standard RFC 7519 method for representing claims securely between two parties.java

JWT.IO allows you to decode, verify and generate JWT.https://jwt.io/编程

javaJwt is library of jwt implemented by java网络

2.javaJwt的类结构编程语言

术语解释:code

一般在传输数据时,为了使数据传输更可靠,要把原始数据分批传输,而且在每一批数据的头和尾都加上必定的辅助信息,好比这一批数据量的大小,校验位等,这样就至关于给已经分批原始数据加一些外套,这些外套起到标示做用,使得原始数据不易丢失。
一批数据加上它的“外套”,就造成了传输通道中基本的传输单元,叫作数据帧或者数据包(有的地方数据帧和数据包不是同一律念好比网络传输)。这些数据帧中的记录信息的原始数据就是有效载荷数据,即payload data。
而消息体就是外套。即标记着原始数据的大小等的辅助信息。orm


1.The Header class represents the 1st part of the JWT, where the Header value is hold.jwt

2.The Payload class represents the 2nd part of the JWT, where the Payload value is hold.htm

3.The Signature class represents the 3rd part of the JWT, where the Signature value is hold.对象

4.The JWTDecoder class holds the decode method to parse a given JWT token into it's JWT representation.

5.The JWTVerifier class holds the verify method to assert that a given Token has not only a proper JWT format, but also it's signature matches.

6.The JWTCreator class holds the sign method to generate a complete JWT (with Signature) from a given Header and Payload content.

 7.The Claim class holds the value in a generic way so that it can be recovered in many representations.

根据JWT的标准,这些claims能够分为如下三种类型: 
a. Reserved claims(保留),它的含义就像是编程语言的保留字同样,属于JWT标准里面规定的一些claim。JWT标准里面定好的claim有:

  • iss(Issuser):表明这个JWT的签发主体;
  • sub(Subject):表明这个JWT的主体,即它的全部人;
  • aud(Audience):表明这个JWT的接收对象;
  • exp(Expiration time):是一个时间戳,表明这个JWT的过时时间;
  • nbf(Not Before):是一个时间戳,表明这个JWT生效的开始时间,意味着在这个时间以前验证JWT是会失败的;
  • iat(Issued at):是一个时间戳,表明这个JWT的签发时间;
  • jti(JWT ID):是JWT的惟一标识。

b. Public claims,略(不重要)

c. Private claims,这个指的就是自定义的claim。好比前面那个结构举例中的admin和name都属于自定的claim。这些claim跟JWT标准规定的claim区别在于:JWT规定的claim,JWT的接收方在拿到JWT以后,都知道怎么对这些标准的claim进行验证;而private claims不会验证,除非明确告诉接收方要对这些claim进行验证以及规则才行。

按照JWT标准的说明:保留的claims都是可选的,在生成payload不强制用上面的那些claim,你能够彻底按照本身的想法来定义payload的结构,不过这样搞根本不必:第一是,若是把JWT用于认证, 那么JWT标准内规定的几个claim就足够用了,甚至只须要其中一两个就能够了,假如想往JWT里多存一些用户业务信息,好比角色和用户名等,这却是用自定义的claim来添加;第二是,JWT标准里面针对它本身规定的claim都提供了有详细的验证规则描述,每一个实现库都会参照这个描述来提供JWT的验证明现,因此若是是自定义的claim名称,那么你用到的实现库就不会主动去验证这些claim。

参考文献:

【1】http://www.cnblogs.com/lyzg/p/6028341.html

相关文章
相关标签/搜索