JSON Web Token

JSON Web Token (JWT, sometimes pronounced [1]) is a JSON-based open standard (RFC 7519) for creating access tokens that assert some number of claims. For example, a server could generate a token that has the claim "logged in as admin" and provide that to a client. The client could then use that token to prove that it is logged in as admin. The tokens are signed by one party's private key (usually the server's), so that both parties (the other already being, by some suitable and trustworthy means, in possession of the corresponding public key) are able to verify that the token is legitimate. The tokens are designed to be compact, URL-safe and usable especially in web browser single sign-on (SSO) context. JWT claims can be typically used to pass identity of authenticated users between an identity provider and a service provider, or any other type of claims as required by business processes.[2][3]

JWT relies on other JSON-based standards: JWS (JSON Web Signature) RFC 7515 and JWE (JSON Web Encryption) RFC 7516.[4][5][6]


JWTs generally have three parts: a header, a payload, and a signature. The header identifies which algorithm is used to generate the signature, and looks something like this:

header = '{"alg":"HS256","typ":"JWT"}'

HS256 indicates that this token is signed using HMAC-SHA256.

The payload contains the claims to make:

payload = '{"loggedInAs":"admin","iat":1422779638}'

As suggested in the JWT spec, a timestamp called iat (issued at) is installed.

The signature is calculated by base64url encoding the header and payload and concatenating them with a period as a separator:

key           = 'secretkey'
unsignedToken = encodeBase64Url(header) + '.' + encodeBase64Url(payload)
signature     = HMAC-SHA256(key, unsignedToken) 

To put it all together, the signature is base64url encoded. The three separate parts are concatenated using periods:

token = encodeBase64Url(header) + '.' + encodeBase64Url(payload) + '.' + encodeBase64Url(signature) # token is now: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJsb2dnZWRJbkFzIjoiYWRtaW4iLCJpYXQiOjE0MjI3Nzk2Mzh9.gzSraSYS8EXBxLN_oWnFSRgCzcmJmMjLiuyu5CSpyHI 

The output is three Base64url strings separated by dots that can be easily passed in HTML and HTTP environments, while being more compact compared to XML-based standards such as SAML. Typical cryptographic algorithms used are HMAC with SHA-256 (HS256) and RSA signature with SHA-256 (RS256). JWA (JSON Web Algorithms) RFC 7518 introduces many more for both authentication and encryption.[7]


In authentication, when the user successfully logs in using their credentials, a JSON Web Token will be returned and must be saved locally (typically in local or session storage, but cookies can also be used), instead of the traditional approach of creating a session in the server and returning a cookie.

Whenever the user wants to access a protected route or resource, the user agent should send the JWT, typically in the Authorization header using the Bearer schema. The content of the header might look like the following:

Authorization: Bearer eyJhbGci...<snip>...yu5CSpyHI

This is a stateless authentication mechanism as the user state is never saved in server memory. The server's protected routes will check for a valid JWT in the Authorization header, and if it is present, the user will be allowed to access protected resources. As JWTs are self-contained, all the necessary information is there, reducing the need to query the database multiple times.

Standard fields

The Internet drafts define the following standard fields ("claims") that can be used inside a JWT claim set:

code name description
iss Issuer Identifies principal that issued the JWT.
sub Subject Identifies the subject of the JWT.
aud Audience Identifies the recipients that the JWT is intended for. Each principal intended to process the JWT must identify itself with a value in the audience claim. If the principal processing the claim does not identify itself with a value in the aud claim when this claim is present, then the JWT must be rejected
exp Expiration time Identifies the expiration time on or after which the JWT must not be accepted for processing. The value should be in NumericDate[8][9] format.
nbf Not before Identifies the time on which the JWT will start to be accepted for processing.
iat Issued at Identifies the time at which the JWT was issued.
jti JWT ID Case sensitive unique identifier of the token even among different issuers.

The following fields can be used in authentication headers:

code name description
typ Token type If present, it is recommended to set this to JWT.
cty Content type If nested signing or encryption is employed, it is recommended to set this to JWT, otherwise omit this field[1].
alg Message authentication code algorithm The issuer can freely set an algorithm to verify the signature on the token. However, some supported algorithms are insecure[10].
All other headers introduced by JWS and JWE[5][6].


JWT implementations exist for


"Critical vulnerabilities" have been described with the JWT algorithm.[10] These include: allowing the client (attacker) to specify the signature verification method, and deliberate confusion of the encryption method.

Developers can address many of these vulnerabilities with proper design of their applications. [31] These include: never let the JWT header alone drive verification; know the algorithms; use an appropriate key size.


  1. ^ a b John, Bradley; Nat, Sakimura; Michael, Jones. "JSON Web Token (JWT)". tools.ietf.org. Retrieved . 
  2. ^ Sevilleja, Chris. "The Anatomy of a JSON Web Token". Retrieved . 
  3. ^ "Atlassian Connect Documentation". developer.atlassian.com. Retrieved . 
  4. ^ "draft-ietf-oauth-json-web-token-32 - JSON Web Token (JWT)". tools.ietf.org. Retrieved . 
  5. ^ a b "draft-ietf-jose-json-web-signature-41 - JSON Web Signature (JWS)". tools.ietf.org. Retrieved . 
  6. ^ a b "draft-ietf-jose-json-web-encryption-40 - JSON Web Encryption (JWE)". tools.ietf.org. Retrieved . 
  7. ^ "draft-ietf-jose-json-web-algorithms-40 - JSON Web Algorithms (JWA)". tools.ietf.org. Retrieved . 
  8. ^ John, Bradley,; Nat, Sakimura,; Michael, Jones,. "JSON Web Token (JWT)". tools.ietf.org. Retrieved . 
  9. ^ John, Bradley,; Nat, Sakimura,; Michael, Jones,. "JSON Web Token (JWT)". tools.ietf.org. Retrieved . 
  10. ^ a b McLean, Tim (March 31, 2015). "Critical vulnerabilities in JSON Web Token libraries". Auth0. Retrieved . 
  11. ^ libjwt on github.com
  12. ^ cljwt on github.com
  13. ^ "dgrijalva/jwt-go". GitHub. Retrieved . 
  14. ^ jwt-dotnet on github.com
  15. ^ ocaml-jwt on github.com
  16. ^ Crypt::JWT on cpan.org
  17. ^ JSON-WebToken on github.com
  18. ^ lcobucci/jwt on github.com
  19. ^ "jpadilla/pyjwt". GitHub. Retrieved . 
  20. ^ ruby-jwt on github.com
  21. ^ frank_jwt on github.com
  22. ^ jwt-scala on github.com
  23. ^ [1] on github.com
  24. ^ "liquidz/clj-jwt". GitHub. Retrieved . 
  25. ^ "bryanjos/joken". GitHub. Retrieved . 
  26. ^ "jwt: JSON Web Token (JWT) decoding and encoding". Hackage. Retrieved . 
  27. ^ auth0/java-jwt on github.com
  28. ^ "kjur/jsrsasign". GitHub. Retrieved . 
  29. ^ "SkyLothar/lua-resty-jwt". GitHub. Retrieved . 
  30. ^ "jsonwebtoken". npm. Retrieved . 
  31. ^ "Common JWT security vulnerabilities and how to avoid them". Retrieved . 

External links

  • jwt.io - specialized website about JWT with tools and documentation, maintained by Auth0
  • Spring Boot JWT Auth - Integrating JWT authentication with Spring framework

  This article uses material from the Wikipedia page available here. It is released under the Creative Commons Attribution-Share-Alike License 3.0.



Connect with defaultLogic
What We've Done
Led Digital Marketing Efforts of Top 500 e-Retailers.
Worked with Top Brands at Leading Agencies.
Successfully Managed Over $50 million in Digital Ad Spend.
Developed Strategies and Processes that Enabled Brands to Grow During an Economic Downturn.
Taught Advanced Internet Marketing Strategies at the graduate level.

Manage research, learning and skills at defaultLogic. Create an account using LinkedIn or facebook to manage and organize your Digital Marketing and Technology knowledge. defaultLogic works like a shopping cart for information -- helping you to save, discuss and share.

Visit defaultLogic's partner sites below:
PopFlock.com : Music Genres | Musicians | Musical Instruments | Music Industry
NCR Works : Retail Banking | Restaurant Industry | Retail Industry | Hospitality Industry

  Contact Us