JWT
Table of Contents
Overview
jwtcomprisesHEADER,PAYLOAD,SIGNATURE.- Generally, its base64 encoded string is used as tokens.
- The recipient of jwt tokens should validate its signature.
- The recipient can serve some secured resources without managing sessions, through its payload.
- Mostly used as
id tokenof OpenID Connect. - There are a wide variety of libraries to handle
jwtacross programming languages.
Validation Process
- Verify the signature
- Validate Claims
- Token expiration (
exp) :: Normally, it's Unix timestamp. - Token issuer (
iss) :: the auth provider likeAuth0,AWS Cognitoetc. - Token audience (
aud) :: the resource server or its uri. Likehttps://resource-server.com/user
- Token expiration (
RS256 vs. HS256, jwks.json
- There are two popular ways to sign
jwt,RS256andHS256 RS256is asymmetric, which means that it uses public/private key pair.RS256is generally recommended.HS256is symmetric, on the other hand.HS256is generally not safe because the private key can easily be exposed to other parties.jwks.jsonis one way to manage public keys which are used when issuingjwt.jwks.jsonis provided by identity providers for third parties to validatejwt