Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[๐Ÿ‡ Assignment/#6] Week6_Seminar_์‹ค์Šต๊ณผ์ œ ๊ตฌํ˜„ #22

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

junggyo1020
Copy link
Contributor

@junggyo1020 junggyo1020 commented Jun 3, 2024

๐Ÿ“„ Work Description

โœจ ๋กœ๊ทธ์ธ์„ ์ง„ํ–‰ํ•  ๋•Œ AccessToken๊ณผ Refresh Token์„ ํ•จ๊ป˜ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋กœ์ง ๊ตฌํ˜„ โœจ
โœจ Redis๋ฅผ ํ™œ์šฉํ•ด Refresh Token์œผ๋กœ Access Token์„ ์žฌ๋ฐœ๊ธ‰ ๋ฐ›๋Š” ๋กœ์ง ๊ตฌํ˜„ โœจ

1๏ธโƒฃ ํšŒ์›๊ฐ€์ž… : JWT ์ธ์ฆ ํ•„ํ„ฐ๋ฅผ ๊ฑฐ์น˜์ง€ ์•Š์Œ

  • ํšŒ์›๊ฐ€์ž… ์‹œ JWT ์ธ์ฆ ํ•„ํ„ฐ๋ฅผ ๊ฑฐ์น˜์ง€ ์•Š๊ณ , ์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๋ฉฐ ์—‘์„ธ์Šค ํ† ํฐ์„ ๋ฐœ๊ธ‰ํ•œ๋‹ค. ํšŒ์›๊ฐ€์ž… API๋Š” ๊ณต๊ฐœ๋˜์–ด ์žˆ์–ด์•ผ ํ•˜๋ฏ€๋กœ ์ธ์ฆ ํ•„ํ„ฐ๋ฅผ ์ œ์™ธํ•˜๊ณ  ๊ตฌํ˜„ํ•œ๋‹ค.

2๏ธโƒฃ ๋กœ๊ทธ์ธ : JWT ์ธ์ฆ ํ•„ํ„ฐ๋ฅผ ๊ฑฐ์น˜์ง€ ์•Š์Œ

  • ๋กœ๊ทธ์ธ ์‹œ ์‚ฌ์šฉ์ž ์ž๊ฒฉ ์ฆ๋ช…์„ ํ™•์ธํ•˜๊ณ , ์—‘์„ธ์Šค ํ† ํฐ๊ณผ ๋ฆฌํ”„๋ ˆ์‹œ ํ† ํฐ์„ ๋ฐœ๊ธ‰ํ•œ๋‹ค. ๋ฐœ๊ธ‰๋œ ๋ฆฌํ”„๋ ˆ์‹œ ํ† ํฐ์€ Redis์— ์ €์žฅํ•˜๋„๋ก ๊ตฌํ˜„ํ•œ๋‹ค.

3๏ธโƒฃ ๋ธ”๋กœ๊ทธ ์ƒ์„ฑ : JWT ์ธ์ฆ ํ•„ํ„ฐ๋ฅผ ๊ฑฐ์นจ

  • ๋ธ”๋กœ๊ทธ ์ƒ์„ฑ API๋Š” ์ธ์ฆ๋œ ์‚ฌ์šฉ์ž๋งŒ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋„๋ก JWT ์ธ์ฆ ํ•„ํ„ฐ๋ฅผ ํ†ต๊ณผํ•ด์•ผ ํ•œ๋‹ค.

4๏ธโƒฃ ํ† ํฐ ์žฌ๋ฐœ๊ธ‰ : JWT ์ธ์ฆ ํ•„ํ„ฐ๋ฅผ ๊ฑฐ์น˜์ง€ ์•Š์Œ

  • ๋ฆฌํ”„๋ ˆ์‹œ ํ† ํฐ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ƒˆ๋กœ์šด ์—‘์„ธ์Šค ํ† ํฐ์„ ๋ฐœ๊ธ‰๋ฐ›๋Š” API๋Š” ์ธ์ฆ ํ•„ํ„ฐ๋ฅผ ๊ฑฐ์น˜์ง€ ์•Š์•„์•ผ ํ•œ๋‹ค.

๐Ÿ“‹ ํšŒ์›๊ฐ€์ž… ๋ฐ ๋กœ๊ทธ์ธ ์‹œ ํ† ํฐ ๋ฐœ๊ธ‰ ๋ฐ ์ €์žฅ

  • ํšŒ์›๊ฐ€์ž… ์‹œ Refresh Token์„ ๋ฐœ๊ธ‰ํ•  ์ˆ˜ ์žˆ๋„๋ก UserJoinResponse์— ์ฝ”๋“œ ์ถ”๊ฐ€ํ•˜๊ธฐ
  • MemberService ์ˆ˜์ •ํ•˜๊ธฐ
  • JwtTokenProvider์— Refresh Token ๊ด€๋ จ ์ฝ”๋“œ ์ถ”๊ฐ€ํ•˜๊ธฐ
  • ๋กœ๊ทธ์ธ ๋กœ์ง ๊ตฌํ˜„์„ ์œ„ํ•œ LoginRequest, LoginResponse (record ํ˜•์‹) ๊ตฌํ˜„ํ•˜๊ธฐ
  • ๋กœ๊ทธ์ธ ์‹œ ์‚ฌ์šฉ์ž์˜ ์ž๊ฒฉ์„ ํ™•์ธํ•˜๋Š” ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง(AuthService) ๊ตฌํ˜„ํ•˜๊ธฐ
  • AuthController ๊ตฌํ˜„ํ•˜๊ธฐ
  • Postman์œผ๋กœ API ํ…Œ์ŠคํŠธ ํ•˜๊ธฐ

๐Ÿ“ ๋ธ”๋กœ๊ทธ ์ƒ์„ฑ ์‹œ JWT ์ธ์ฆ ํ•„ํ„ฐ๋ฅผ ๊ฑฐ์น˜๋„๋ก ๊ตฌํ˜„

  • SecurityConfig์—์„œ JWT ์ธ์ฆ์„ ๊ฑฐ์น˜์ง€ ์•Š๋Š” ์ฃผ์†Œ๋ฅผ AUTH_WHITE_LIST์— ์ถ”๊ฐ€ํ•˜๊ธฐ(Swagger ์ฃผ์†Œ ํฌํ•จ)

๐Ÿ“‹ Redis๋ฅผ ํ™œ์šฉํ•ด Refresh Token์œผ๋กœ Access Token์„ ์žฌ๋ฐœ๊ธ‰ ๋ฐ›๋Š” ๋กœ์ง ๊ตฌํ˜„

  • RefreshTokenRequest ๊ตฌํ˜„ํ•˜๊ธฐ
  • Refresh Token ์žฌ๋ฐœ๊ธ‰ ๋ฐ›๋Š” ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง(AuthService)๊ณผ, ์ถ”๊ฐ€์ ์œผ๋กœ ์กด์žฌํ•˜๋Š” ํ† ํฐ์ธ์ง€ ํ™•์ธํ•˜๋Š” ์—๋Ÿฌ์ฒ˜๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ๊ตฌํ˜„ํ•˜๊ธฐ
  • AuthController์— Refresh Token ์žฌ๋ฐœ๊ธ‰ ๊ด€๋ จ ์ฝ”๋“œ ์ถ”๊ฐ€ํ•˜๊ธฐ

๐Ÿ“ท Screenshot

ํด๋ž˜์Šค ๊ตฌ์กฐ

image image

๐Ÿ“‹ ํšŒ์›๊ฐ€์ž… ๋ฐ ๋กœ๊ทธ์ธ ์‹œ ํ† ํฐ ๋ฐœ๊ธ‰ ๋ฐ ์ €์žฅ

1. ํšŒ์›๊ฐ€์ž… ์‹œ Refresh Token์„ ๋ฐœ๊ธ‰ํ•  ์ˆ˜ ์žˆ๋„๋ก UserJoinResponse์— ์ฝ”๋“œ ์ถ”๊ฐ€ํ•˜๊ธฐ

image

2. MemberService ์ˆ˜์ •ํ•˜๊ธฐ(refreshToken ๊ด€๋ จ ๋กœ์ง + ๋ฉค๋ฒ„ ๊ฐ€์ž… ์‹œ password๋„ ํ•จ๊ป˜ ๋ฐ›์•„์˜ค๋„๋ก ์ฝ”๋“œ ์ถ”๊ฐ€)

image

3. JwtTokenProvider์— Refresh Token ๊ด€๋ จ ์ฝ”๋“œ ์ถ”๊ฐ€ํ•˜๊ธฐ

image

4. ๋กœ๊ทธ์ธ ๋กœ์ง ๊ตฌํ˜„์„ ์œ„ํ•œ LoginRequest, LoginResponse (record ํ˜•์‹) ๊ตฌํ˜„ํ•˜๊ธฐ

image image

5. ๋กœ๊ทธ์ธ ์‹œ ์‚ฌ์šฉ์ž์˜ ์ž๊ฒฉ์„ ํ™•์ธํ•˜๋Š” ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง(AuthService) ๊ตฌํ˜„ํ•˜๊ธฐ

image

6. AuthController ๊ตฌํ˜„ํ•˜๊ธฐ

image

๐Ÿ“‹ Redis๋ฅผ ํ™œ์šฉํ•ด Refresh Token์œผ๋กœ Access Token์„ ์žฌ๋ฐœ๊ธ‰ ๋ฐ›๋Š” ๋กœ์ง ๊ตฌํ˜„

RefreshTokenRequest ๊ตฌํ˜„ํ•˜๊ธฐ

image

1. Refresh Token ์žฌ๋ฐœ๊ธ‰ ๋ฐ›๋Š” ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง(AuthService)๊ณผ, ์ถ”๊ฐ€์ ์œผ๋กœ ์กด์žฌํ•˜๋Š” ํ† ํฐ์ธ์ง€ ํ™•์ธํ•˜๋Š” ์˜ˆ์™ธ์ฒ˜๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ๊ตฌํ˜„ํ•˜๊ธฐ

image

2. AuthController์— Refresh Token ์žฌ๋ฐœ๊ธ‰ ๊ด€๋ จ ์ฝ”๋“œ ์ถ”๊ฐ€ํ•˜๊ธฐ

image

์˜ˆ์™ธ์ฒ˜๋ฆฌ

exception ๊ตฌ์กฐ

image

ErrorMessage.java

image

Swagger ํ…Œ์ŠคํŠธ

1. ๋ฉค๋ฒ„ ์ƒ์„ฑ ์‹œ RefreshToken๋„ ํ•จ๊ป˜ ๋ฐ˜ํ™˜

image

2. ๋กœ๊ทธ์ธ ์‹œ ์‚ฌ์šฉ์ž ์ด๋ฆ„์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ

image

3. ๋กœ๊ทธ์ธ ์‹œ ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์ผ์น˜ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ

image

4. ๋กœ๊ทธ์ธ ์„ฑ๊ณต

image

5. Refresh Token์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ

image

6. Refresh Token ์žฌ๋ฐœ๊ธ‰ ์„ฑ๊ณต

image
# ๐Ÿ’ฌ To Reviewer
- 6์ฃผ์ฐจ ๋‚ด์šฉ์ด ๋งŽ๊ณ  ์–ด๋ ค์›Œ์„œ ์ข€ ๋” ์™„๋ฒฝํ•˜๊ฒŒ ์ดํ•ดํ•œ ํ›„์— ์ง„ํ–‰์„ ํ•˜๋ ค๋‹ค๋ณด๋‹ˆ ์‹œ๊ฐ„์ด ์ข€ ์˜ค๋ž˜ ๊ฑธ๋ ธ์Šต๋‹ˆ๋‹ค
- Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed:
  org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis] with root cause 
  ์ด๋Ÿฐ ์—๋Ÿฌ๊ฐ€ ๋– ์„œ ๋ณด๋‹ˆ redis-server๋กœ ์‹คํ–‰์„ ์•ˆํ•˜๊ณ  ์ง„ํ–‰์„ ํ•ด์„œ ์ƒ๊ธด ์˜ค๋ฅ˜์ธ๊ฒƒ์„ ๋’ค๋Šฆ๊ฒŒ ๊นจ๋‹ฌ์•˜์Šต๋‹ˆ๋‹คใ…Žใ…Ž;;; 
  ์—ฌ๋Ÿฌ๋ถ„์€ ๊ผญ redis-cli ping์œผ๋กœ redis ์‹คํ–‰ ์—ฌ๋ถ€ ํ™•์ธํ•ด๋ณด์‹œ๊ธธ...
- ์ €๋Š” Swagger ๋ฅผ ๋ถ™์—ฌ์„œ ์ง„ํ–‰ํ–ˆ๋Š”๋ฐ ์ฒ˜์Œ์—๋Š” Swagger์ž์ฒด๊ฐ€ ์ธ์ฆ์ด ์•ˆ๋˜์–ด์žˆ์–ด์„œ ์ ‘์†์ด ๋ถˆ๊ฐ€ํ•œ ์—๋Ÿฌ๊ฐ€ ์ƒ๊ฒผ์—ˆ๋Š”๋ฐ์š”. 
  ๊ทธ๋ž˜์„œ ์ €๋Š” Swagger๊ด€๋ จ ์ฃผ์†Œ๋ฅผ ๋ชจ๋‘ Auth_WHITE_LIST์— ์ถ”๊ฐ€ํ•˜์˜€์Šต๋‹ˆ๋‹ค..!
- ์ฝ”๋“œ์— ์—๋Ÿฌ๋‚˜ ๊ถ๊ธˆํ•œ์ , ํ˜น์€ ๋” ์ข‹์€ ๊ฐœ์„ ๋ฐฉ์•ˆ์ด ์žˆ๋‹ค๋ฉด ์–ธ์ œ๋“ ์ง€ ์ฝ”๋ฉ˜ํŠธ ๋‚จ๊ฒจ์ฃผ์„ธ์š”!!! ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค๐Ÿถ

@junggyo1020 junggyo1020 added ๐Ÿถ ์ •๊ต Seminar Seminar ๊ด€๋ จ ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค ๐Ÿ“– Assignment Assignment Code labels Jun 3, 2024
@junggyo1020 junggyo1020 self-assigned this Jun 3, 2024
@hyerinhwang-sailin
Copy link

๊ณผ์ œํ•˜๋Š๋ผ ๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค!! pr์—์„œ ๊ณ ๋ฏผ์˜ ์‹œ์ž‘๋ถ€ํ„ฐ ๊ตฌํ˜„๊นŒ์ง€์˜ ์‚ฌ๊ณ  ํ๋ฆ„์ด ๋‹ค ๋ณด์—ฌ์„œ ์ด๋Ÿฐ ๊ฒŒ pr์˜ ์ •์„์ธ๊ฐ€ ๊ฐํƒ„ํ•˜๊ณ  ๊ฐ‘๋‹ˆ๋‹ค!
์ €๋Š” ๋ฉค๋ฒ„ ๊ฐ€์ž…์—์„œ์˜ ํ† ํฐ ๊ด€๋ จ ๋กœ์ง๋งŒ ๊ตฌํ˜„ํ–ˆ๋Š”๋ฐ ์ •๊ต๋‹˜ ์ฝ”๋“œ ๋ณด๋ฉด์„œ ์ €๋„ ๋กœ๊ทธ์ธ๊นŒ์ง€ ๊ตฌํ˜„ํ•ด๋ด์•ผ๊ฒ ์Šต๋‹ˆ๋‹ค.. ๋งŽ์ด ๋ฐฐ์›Œ๊ฐ€์š”๐Ÿ‘

@jun3327
Copy link

jun3327 commented Jun 5, 2024

๊ณผ์ œํ•˜์‹œ๋Š๋ผ ๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค! ๊ณผ์ œํ•˜๋ฉด์„œ ํ† ํฐํ•˜๊ณ  ๋กœ๊ทธ์ธ ๊ด€๋ จ ๋กœ์ง์„ ์–ด๋–ค ์‹์œผ๋กœ ๋ฌถ๊ณ  ๋˜ ์ฝ”๋“œ์ƒ์œผ๋กœ ์–ด๋–ป๊ฒŒ ๋ถ„๋ฆฌํ•ด์•ผ๋ ์ง€ ๊ณ ๋ฏผ ๋งŽ์ดํ–ˆ์—ˆ๋Š”๋ฐ, ์ •๊ต๋‹˜ ํ•˜์‹  ๊ฒƒ ์ฒ˜๋Ÿผ AuthController, AuthService์— ๊ด€๋ จ ๋กœ์ง ๋ถ„๋ฆฌ ํ•˜๋Š”๊ฒŒ ๊น”๋”ํ•ด ๋ณด์ด๋„ค์š”..! ๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹น

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
๐Ÿถ ์ •๊ต ๐Ÿ“– Assignment Assignment Code Seminar Seminar ๊ด€๋ จ ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants