Skip to content

JWT Token

Usage of JWT Tokens:

  1. Authorization
  2. Information Exchange

JWT tokens consist of 3 parts separated by a period ( . ).

  1. Header
  2. Payload
  3. Signature

The JWT typically looks like:

aaaa.bbbb.cccc
JWT Structurevalues
Headeralg: signing algorithm being used, such as HMAC SHA256 or RSA
typ: type of the token (e.g. JWT)
PayloadClaims. Claims are statements about an entity (typically, the user) and additional data.
There are three types of claims: registered, public, and private claims.
SignatureTo create the signature part you have to take the encoded header, the encoded payload, a secret, the algorithm specified in the header, and sign that.
{
"alg": "HS256",
"typ": "JWT"
}

Payload

{
"sub": "1234567890",
"name": "John Doe",
"iat": 1516239022
}

Registered claims

registered claims
”iss” (Issuer) ClaimIdentifies the principal that issued the JWT.
The processing of this claim is generally application specific.
The “iss” value is a case-sensitive string containing a StringOrURI value.
”sub” (Subject) ClaimIdentifies the principal that is the subject of the JWT.
”aud” (Audience) ClaimIdentifies the recipients that the JWT is intended for.
”exp” (Expiration Time) ClaimIdentifies the expiration time on or after which the JWT MUST NOT be accepted for processing.
”nbf” (Not Before) ClaimIdentifies the time before which the JWT MUST NOT be accepted for processing
”iat” (Issued At) Claimidentifies the time at which the JWT was issued
”jti” (JWT ID) ClaimProvides a unique identifier for the JWT
The “jti” claim can be used to prevent the JWT from being replayed.

”jti” claim

The “jti” (JWT ID) claim provides a unique identifier for the JWT. The identifier value MUST be assigned in a manner that ensures that there is a negligible probability that the same value will be accidentally assigned to a different data object; if the application uses multiple issuers, collisions MUST be prevented among values produced by different issuers as well.
The “jti” claim can be used to prevent the JWT from being replayed.

Public claims

Private claims

Reference