Skip to content

Instantly share code, notes, and snippets.

@abhirockzz
Created March 18, 2016 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhirockzz/912a3d75bdb64c5d2111 to your computer and use it in GitHub Desktop.
Save abhirockzz/912a3d75bdb64c5d2111 to your computer and use it in GitHub Desktop.
Anatomy of a JSON Web Token (JWT)
//header
{
"alg": "HS256",
"typ": "JWT"
}
//payload/claims
{
"sub": "1234567890",
"name": "John Doe",
"admin": true
}
//the formula
encoded_part = base64Of(header) + "." base64Of(payload)
signature = signedUsingHS256WithSecret(encoded_part) //assume that algo is HS256 and secret key is 'secret'
JWT = encoded_part + "." + sigature
//the JWT ( notice the separator/period --> "." )
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 //base-64 encoded header
.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9 //base-64 encoded payload
.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ //the signature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment