Skip to content

OAuth2.0 ๊ณต๋ถ€๐Ÿ”ฅ

Jiwon Yum edited this page Jun 9, 2022 · 5 revisions

image

JWT ํ† ํฐ

  • ์œ ์ €์ƒํƒœ๋ฅผ ํฌํ•จํ•˜์—ฌ ์•”ํ˜ธํ™”ํ•œ ํ† ํฐ์œผ๋กœ, ์ด๋Š” ์‚ฌ์šฉ์ž ์ธ์ฆ ์‹œ ์˜๋ฏธ์žˆ๋Š” ํ† ํฐ์ด ๋œ๋‹ค (์ด๋ฅผ ํ†ตํ•ด ์‚ฌ์šฉ์ž ์ธ์ฆ์ด ๊ฐ€๋Šฅํ•˜๊ธฐ ๋•Œ๋ฌธ)
  • ๋”ฐ๋ผ์„œ ํด๋ผ์ด์–ธํŠธ๊ฐ€ JWT์™€ ํ•จ๊ป˜ ๋ฆฌ์†Œ์Šค๋ฅผ ์š”์ฒญํ•˜๋ฉด JWT์˜ ์œ ํšจ์„ฑ์„ ํŒ๋‹จํ•˜๋ฉด ๋œ๋‹ค

OAuth์™€ JWT๋ฅผ ํ™œ์šฉํ•œ ๋กœ๊ทธ์ธ ํ”„๋กœ์„ธ์Šค

  1. ํด๋ผ์ด์–ธํŠธ๊ฐ€ OAuth ์„œ๋ฒ„์— ๋กœ๊ทธ์ธ์„ ์š”์ฒญํ•˜๋ฉด, ์ธ์ฆ ๊ณผ์ •์„ ํ†ตํ•ด OAuth ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ํ† ํฐ ๋ฐ ์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ ์ „๋‹ฌ๋ฐ›๋Š”๋‹ค
  2. ์ธ์ฆ์ด ์™„๋ฃŒ๋œ ํด๋ผ์ด์–ธํŠธ๋Š” ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ JWT ํ† ํฐ์„ ๋ฐ›๋Š”๋‹ค
  3. ์ดํ›„ ํด๋ผ์ด์–ธํŠธ๋Š” resource๋ฅผ ์š”์ฒญํ•  ๋•Œ๋งˆ๋‹ค ํ—ค๋”์— JWT ํ† ํฐ์„ ํฌํ•จํ•ด์„œ ์š”์ฒญํ•˜๊ฒŒ ๋œ๋‹ค
  4. ์„œ๋ฒ„๋Š” ์ „๋‹ฌ๋ฐ›์€ ํ—ค๋” ์† JWTํ† ํฐ์˜ ์œ ํšจ์„ฑ์„ ๊ฒ€์‚ฌํ•˜์—ฌ, ์œ ํšจํ•œ ๊ฒฝ์šฐ ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ, ์ฆ‰ resource๋ฅผ ์ „๋‹ฌํ•œ๋‹ค

ํ† ํฐ ์žฌ๋ฐœ๊ธ‰

  • ์—‘์„ธ์Šค ํ† ํฐ์„ ์žฌ๋ฐœ๊ธ‰ ๋ฐ›์œผ๋ ค๋ฉด ํด๋ผ์ด์–ธํŠธ ์ธก์—์„œ ๋ฆฌํ”„๋ ˆ์‹œ ํ† ํฐ๊ณผ ์—‘์„ธ์Šค ํ† ํฐ์„ ๋ชจ๋‘ ๋‹ด์•„์„œ api ์š”์ฒญ์„ ํ•ด์•ผํ•œ๋‹ค!
  • ๊ทธ๋Ÿผ ์„œ๋ฒ„์—์„œ ๋ฐ›์€ ํ† ํฐ๋“ค์˜ ์œ ํšจ์„ฑ๊ณผ ์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ ํ™•์ธํ•˜์—ฌ ์žฌ๋ฐœ๊ธ‰์„ ํ•ด์ฃผ๋Š” ๊ฒƒ์ด๋‹ค

redis ๋กœ๊ทธ์•„์›ƒ

  • redis๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋กœ๊ทธ์•„์›ƒ์„ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒฝ์šฐ์—๋Š” ์šฐ์„  redis์—์„œ ์ €์žฅํ•œ refreshToken ์ •๋ณด๋ฅผ ์‚ญ์ œํ•œ๋‹ค
  • ๊ทธ๋ฆฌ๊ณ  ์•„์ง ์œ ํšจ๊ธฐ๊ฐ„์ด ๋‚จ์•„์žˆ๋Š” accessToken์˜ ๊ฒฝ์šฐ ์‚ญ์ œ๊ฐ€ ๋ถˆ๊ฐ€๋Šฅํ•˜๊ธฐ ๋•Œ๋ฌธ์— redis๋‚ด์— ํ•ด๋‹น ์—‘์„ธ์Šค ํ† ํฐ์„ black list๋กœ ์˜ฌ๋ ค๋‘์–ด ํ•ด๋‹น ํ† ํฐ์„ ํ†ตํ•ด ๋กœ๊ทธ์ธ์„ ํ•˜๋Š” ๊ฒฝ์šฐ ์ด๋ฅผ ๋ง‰๋Š” ๋กœ์ง์„ ๋กœ๊ทธ์ธ ๋กœ์ง์— ์ถ”๊ฐ€๋กœ ๊ตฌํ˜„ํ•ด๋‘”๋‹ค

๊ณ ๋ฏผํ–ˆ๋˜ ๊ตฌํ˜„ ์ˆœ์„œ

  1. developer.kakao.com ์—์„œ ์ธ์ฆ ์ •๋ณด ๋ฐ›๊ธฐ : redirect url, client key? ์ •๋ณด
  2. User, UserRepository ํด๋ž˜์Šค ์ƒ์„ฑ - ์‚ฌ์šฉ์ž ์ •๋ณด ์ €์žฅ
  3. Spring security ์„ค์ •, dependency ์ถ”๊ฐ€ : gradle security config ํด๋ž˜์Šค ์ƒ์„ฑ
  4. CustomOAuth2UserService ํด๋ž˜์Šค ์ƒ์„ฑ - ํšŒ์› ๊ฐ€์ž…, ์ •๋ณด ์ˆ˜์ • ๋“ฑ ๋กœ์ง ๊ตฌํ˜„
  5. OAuthAttributes ํด๋ž˜์Šค ์ƒ์„ฑ -> DTO
  6. ๋กœ๊ทธ์•„์›ƒ ๊ตฌํ˜„
  7. Controller ์ƒ์„ฑ..? - /oauth/authorization/kakao