๋ฐ˜์‘ํ˜•
json web token
์„ค๋ช…

JSON ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ† ํฐ ์ž์ฒด์— ์ •๋ณด๋“ค์„ ์ €์žฅํ•˜๊ณ  ์žˆ๋Š” ์›นํ† ํฐ.
claims์„ ์•ˆ์ „ํ•˜๊ฒŒ ์ „๋‹ฌํ•˜๋Š” ํ‘œ์ค€.
HMAC ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์‚ฌ์šฉ ํ•˜๊ฑฐ๋‚˜, RSA or ECDSA๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ณต๊ฐœ / ๊ฐœ์ธํ‚ค ์Œ์„ ์‚ฌ์šฉํ•˜์—ฌ ์„œ๋ช…์ด ๊ฐ€๋Šฅํ•จ.
๊ถŒํ•œ ๋ถ€์—ฌ ๋ฐ ์ •๋ณด๊ตํ™˜์‹œ์ ์—์„œ ์‚ฌ์šฉ.

โœณ๏ธŽ claims ?
JWT ์˜ PAYLOAD ๋ถ€๋ถ„์„ ๊ตฌ์„ฑํ•˜๊ณ  ๊ตํ™˜๋˜๋Š” ์ •๋ณด ์ง‘ํ•ฉ.

 

ํ† ํฐ์ƒ๊น€์ƒˆ
eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ0ZXN0IiwiYXV0aCI6IlJPTEVfVVNFUiIsImV4cCI6MTY0MDI2NjczOX0.A5bzyF4jkKVmdDzboK8_qsPbDh3qGO3v2lgcSp5K41CxmSgyDZlKxBfcZNiZ754S_IDhFOPO7m18bsBqhZgBMw

์œ„์™€ ๊ฐ™์€ ํ˜•ํƒœ๋กœ ์ƒ๊ฒผ์œผ๋ฉฐ, https://jwt.io/ ์‚ฌ์ดํŠธ์—์„œ ํ† ํฐ ์ •๋ณด๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

๊ตฌ์„ฑ๋ฐฉ์‹

HEADER, PAYLOAD, SIGNITURE ์œผ๋กœ ๊ตฌ์„ฑ๋œ๋‹ค. 
์ด ์„ธ๋ถ€๋ถ„์€ Base64url ์ธ์ฝ”๋”ฉ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ณ„๋„๋กœ ์ธ์ฝ”๋”ฉ๋˜๋ฉฐ JWT ์ƒ์„ฑ์„ ์œ„ํ•˜ ์ (.)์„ ์‚ฌ์šฉํ•˜์—ฌ ์—ฐ๊ฒฐ๋œ๋‹ค. 

var token = base64UrlEncoding(HEADER) + '.' + base64UrlEncoding(PAYLOAD) + '.' + base64UrlEncoding(SIGNITURE);

↓↓↓↓

var token = 
eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ0ZXN0IiwiYXV0aCI6IlJPTEVfVVNFUiIsImV4cCI6MTY0MDI2NjczOX0.A5bzyF4jkKVmdDzboK8_qsPbDh3qGO3v2lgcSp5K41CxmSgyDZlKxBfcZNiZ754S_IDhFOPO7m18bsBqhZgBMw

 

๊ฐ ๊ตฌ์„ฑ ์„ค๋ช…์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

HEADER signiture ์ •๋ณด๋ฅผ ํ•ด์‹ฑํ•˜๊ธฐ ์œ„ํ•œ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ •๋ณด๋“ค์ด ๋‹ด๊ฒจ์žˆ๋Š”๊ณณ.
HMAC, SHA256 or RSA ์™€ ๊ฐ™์€ ์„œ๋ช… ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋‘ ๋ถ€๋ถ„์œผ๋กœ ๊ตฌ์„ฑ๋จ.
PAYLOAD ์„œ๋ฒ„, ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์ฃผ๊ณ  ๋ฐ›๋Š” ์‹œ์Šคํ…œ์—์„œ ์‹ค์ œ๋กœ ์‚ฌ์šฉ๋  ์ •๋ณด์— ๋Œ€ํ•œ ๋‚ด์šฉ์ด ๋‹ด๊ฒจ์žˆ์Œ.
PAYLOAD claims ์€ 3๊ฐ€์ง€ ์œ ํ˜•์ด ์กด์žฌ

- registered claims: ํ•„์ˆ˜๋Š” ์•„๋‹ˆ์ง€๋งŒ ์ƒํ˜ธ ์šด์šฉ์„ ์œ„ํ•ด ๋ฏธ๋ฆฌ ์ •์˜๋œ ํด๋ ˆ์ž„(RFC 7519) ์ง‘ํ•ฉ (iss, exp, sub, aud..)

- public claims: jwt ์„ ์‚ฌ์šฉํ•˜๋Š” ์‚ฌ๋žŒ๋“ค์ด ๋งˆ์Œ๋Œ€๋กœ ์ •์˜. ์ถฉ๋Œ ๋ฐฉ์ง€ ์œ„ํ•ด ๋„ค์ž„์ŠคํŽ˜์ด์Šค๋ฅผ ํฌํ•จํ•˜๋Š” URL๋กœ ์ •์˜ ํ•„์š”

- private claims: ์‚ฌ์šฉ์— ๋™์˜ํ•˜๊ณ  ๋“ฑ๋ก๋œ ํด๋ ˆ์ž„์ด๋‚˜ ๊ณต๊ฐœ ํด๋ ˆ์ž„์ด ์•„๋‹Œ ๋‹น์‚ฌ์ž๊ฐ„์˜ ์ •๋ณด๋ฅผ ๊ณต์œ ํ•˜๊ธฐ ์œ„ํ•ด ์ƒ์„ฑ๋œ ๋งž์ถค ํด๋ ˆ์ž„
SIGNITURE ํ† ํฐ์˜ ์œ ํšจ์„ฑ ๊ฒ€์ฆ์„ ์œ„ํ•œ ๋ฌธ์ž์—ด. ์ด ๋ฌธ์ž์—ด๋กœ ์œ ํšจํ•œ ํ† ํฐ์ธ์ง€ ํ™•์ธํ•จ.
๋ฉ”์„ธ์ง€๊ฐ€ ๋ณ€๊ฒฝ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•˜๋Š”๋ฐ ์‚ฌ์šฉ.

 

 

๋™์ž‘๋ฐฉ์‹

jwt ํ† ํฐ ์ธ์ฆ ๋ฐฉ์‹ ๊ธฐ์ค€์œผ๋กœ ๊ทธ๋ ค๋ณธ๊ฒƒ์ด๋‹ค. (oauth2์˜ ํ—ˆ๊ฐ€๋Š” ์ƒ๋žต)

accessToken, refreshToken์ด jwt ์œผ๋กœ ๊ตฌ์„ฑ๋˜์–ด์žˆ๋‹ค.

 

์žฅ์ ๊ณผ ๋‹จ์ 
  • ์žฅ์ 
    ์ค‘์•™์˜ ์ธ์ฆ์„œ๋ฒ„, ๋ฐ์ดํ„ฐ ์Šคํ† ์–ด์— ๋Œ€ํ•œ ์˜์กด์„ฑ์ด ์—†๊ณ , ์‹œ์Šคํ…œ ์ˆ˜ํ‰ํ™•์žฅ์— ์œ ๋ฆฌํ•˜๋‹ค.

  • ๋‹จ์ 
    PAYLOAD ์ •๋ณด๊ฐ€ ๋งŽ์•„์ง€๋ฉด ๋„คํŠธ์›Œํฌ ์‚ฌ์šฉ๋Ÿ‰์ด ์ฆ๊ฐ€ํ•จ.
    ํ† ํฐ์ด ํด๋ผ์ด์–ธํŠธ์— ์ €์žฅ๋˜๊ธฐ์— ์„œ๋ฒ„์—์„œ ํด๋ผ์ด์–ธํŠธ์˜ ํ† ํฐ์„ ์กฐ์ž‘ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 


์ฐธ์กฐ

https://jwt.io/introduction

 

JWT.IO

JSON Web Tokens are an open, industry standard RFC 7519 method for representing claims securely between two parties.

jwt.io

https://ko.wikipedia.org/wiki/JSON_%EC%9B%B9_%ED%86%A0%ED%81%B0

 

JSON ์›น ํ† ํฐ - ์œ„ํ‚ค๋ฐฑ๊ณผ, ์šฐ๋ฆฌ ๋ชจ๋‘์˜ ๋ฐฑ๊ณผ์‚ฌ์ „

JSON ์›น ํ† ํฐ์ƒํƒœ์ธํ„ฐ๋„ท ํ‘œ์ค€์ตœ์ดˆ ์ถœํŒ์ผ2010๋…„ 12์›” 28์ผ (2010-12-28)๋งˆ์ง€๋ง‰ ๋ฒ„์ „RFC 75192015๋…„ 5์›”์กฐ์งIETF์•ฝ์–ดJWT JSON ์›น ํ† ํฐ(JSON Web Token, JWT, "jot”[1])์€ ์„ ํƒ์  ์„œ๋ช… ๋ฐ ์„ ํƒ์  ์•”ํ˜ธํ™”๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ

ko.wikipedia.org

https://velog.io/@kshired/Express%EC%97%90%EC%84%9C-JWT%EB%A1%9C-%EC%9D%B8%EC%A6%9D%EC%8B%9C%EC%8A%A4%ED%85%9C-%EA%B5%AC%ED%98%84%ED%95%98%EA%B8%B0-Access-Token%EA%B3%BC-Refresh-Token

 

Express์—์„œ JWT๋กœ ์ธ์ฆ์‹œ์Šคํ…œ ๊ตฌํ˜„ํ•˜๊ธฐ ( Access Token๊ณผ Refresh Token )

Express์—์„œ jwt๋ฅผ ์ด์šฉํ•˜์—ฌ access token์œผ๋กœ๋งŒ ์ธ์ฆ์„ ํ•˜๋Š” ๊ธ€์€ ๋งŽ์ด ์žˆ๋Š”๋ฐ, refresh token๊นŒ์ง€ ๊ตฌํ˜„ํ•œ ์ž๋ฃŒ๋Š” ๊ทธ๋ ‡๊ฒŒ ๋งŽ์ง€์•Š์•„ ์ด ๊ธ€์„ ์“ฐ๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.์ด ๊ธ€์€ ๊ตฌํ˜„์— ์น˜์ค‘๋˜์–ด ์žˆ์–ด, JWT์˜ ์ž์„ธํ•œ

velog.io

https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81%EB%B6%80%ED%8A%B8-jwt/dashboard

 

[๋ฌด๋ฃŒ] Spring Boot JWT Tutorial - ์ธํ”„๋Ÿฐ | ๊ฐ•์˜

Spring Boot, Spring Security, JWT๋ฅผ ์ด์šฉํ•œ ํŠœํ† ๋ฆฌ์–ผ์„ ํ†ตํ•ด ์ธ์ฆ๊ณผ ์ธ๊ฐ€์— ๋Œ€ํ•œ ๊ธฐ์ดˆ ์ง€์‹์„ ์‰ฝ๊ณ  ๋น ๋ฅด๊ฒŒ ํ•™์Šตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค., [์‚ฌ์ง„] ๋ณธ ๊ฐ•์˜๋Š” Spring Boot, Spring Security๋ฅผ ์ด์šฉํ•ด์„œ JWT ์ธ์ฆ๊ณผ ์ธ๊ฐ€๋ฅผ ์‰ฝ

www.inflearn.com

https://techdocs.akamai.com/api-gateway/docs/json-web-token-jwt-val#jwt-claims

 

JSON web token (JWT) validation

JSON web token is an open standard (RFC 7519) that defines a compact and self-contained method for securely transmitting JSON-encoded information between parties. With <<COMPANY_NICKNAME>>, you can use JWTs to quickly identify and authorize API consumers w

techdocs.akamai.com

 

๋ฐ˜์‘ํ˜•

'๊ฐœ๋ฐœ > etc' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

SSE (Server Sent Event)  (1) 2023.08.20
Vault  (1) 2023.02.07
ํ—ฅ์‚ฌ๊ณ ๋‚  ์•„ํ‚คํ…์ฒ˜ (Hexagonal Architecture)  (2) 2022.09.25
Rest API  (0) 2021.06.02
HTTP๊ด€๋ จ (https, spdy, ajax, websocket)  (0) 2018.12.09

+ Recent posts