created by Aha00aAha00a at 2018-12-24
last modified by Aha00aAha00a at 2023-08-22
revision: 13

JWT

JSON Web Token

  • https://jwt.io/
  • https://tools.ietf.org/html/rfc7519
    Abstract
    
       JSON Web Token (JWT) is a compact, URL-safe means of representing
       claims to be transferred between two parties.  The claims in a JWT
       are encoded as a JSON object that is used as the payload of a JSON
       Web Signature (JWS) structure or as the plaintext of a JSON Web
       Encryption (JWE) structure, enabling the claims to be digitally
       signed or integrity protected with a Message Authentication Code
       (MAC) and/or encrypted.

발음은.. [jot] 이라고 한다.. 그냥 🇰🇷 한국에서는 한글자씩 읽기로 한다..

1. Structure

header.payload.signature
{
  "typ": "JWT",
  "alg": "HS256"
}
  • typ: type. JWT
  • alg: algorithm
  • Base64로 인코딩하여 padding(=)을 제거한다.

1.2. Payload

  • claim들을 담는다
  • claim의 종류
    • registered claim
      • iss: Issuer.
      • sub: Subject.
      • aud: Audience.
      • exp: Expiration Time. NumericDate value.
      • nbf: Not Before. NumericDate value.
      • iat: Issued At. NumericDate value.
      • jti: JWT ID.
    • public claim
    • private claim

1.3. Signature

header + '.' + payload를 해싱한 값

1.4. Example

  • Encoded
    eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
    • Header
      {
        "alg": "HS256",
        "typ": "JWT"
      }
    • Payload
      {
        "sub": "1234567890",
        "name": "John Doe",
        "iat": 1516239022
      }
    • Signature
      HMACSHA256(
        base64UrlEncode(header) + "." +
        base64UrlEncode(payload),
        your-256-bit-secret
      )

3. Signed Cookie와의 비교

  • 먹어보는 중.. JWT AccessToken RefreshToken에 정리할 예정.. --2021-04-21
  • exp와 nbf를 활용할 수 있을 것 같긴 하다. 보통 직접 구현했지.. 아직 먹어보지 않았으므로 한번 먹어보는것도 괜찮을 것 같다. --2021-04-17
  • Signed Cookie를 JWT로 바꿔도, 보안상 이점이 커지지 않는다. --2020-11-19
  • Signed Cookie는 말 그대로 Cookie로 전송하게 되는데, JWT는 어떤 두 당사자(two parties)간에라도 어떤 방식으로든지 (query-string, request-body, request-header) 전달가능하다. --2020-11-19

4. Releated Web Pages

5. See Also

5.2. Adjacent Pages

≤ 32
all
1.0x
1.0x
80
-120
ON
0/0
0/0
0.00
0
0 / 0
1.00x