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

[BUG] [GGFE-126] refresh token #891

Merged
merged 23 commits into from
Jun 30, 2023
Merged

[BUG] [GGFE-126] refresh token #891

merged 23 commits into from
Jun 30, 2023

Conversation

42sungwook
Copy link
Contributor

@42sungwook 42sungwook commented Jun 27, 2023

๐Ÿ“Œ ๊ฐœ์š”

  • access token์ด ๋งŒ๋ฃŒ๋˜์—ˆ์„ ๋•Œ refresh token์„ ์‚ฌ์šฉํ•˜์—ฌ ์žฌ๋ฐœ๊ธ‰๋ฐ›๋Š” ๋กœ์ง ์˜ค๋ฅ˜ ์ˆ˜์ •

๐Ÿ’ป ์ž‘์—…์‚ฌํ•ญ

  • ๋ฐฑ์—์„œ ๋กœ๊ทธ์ธํ•  ๋•Œ ์ฟผ๋ฆฌ์— access token์„ ์ด์ œ ๋„˜๊ฒจ์ฃผ์ง€ ์•Š์•„ welcome modal์„ ๋„์›Œ์ฃผ๋Š” ๊ฒฝ์šฐ๋ฅผ ๋”ฐ๋กœ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด local storage์— login key ์ €์žฅ
  • axiosResponse hook์„ ๋งŒ๋“ค์–ด access token์ด ๋งŒ๋ฃŒ๋˜์—ˆ์„ ๋•Œ ์žฌ๋ฐœ๊ธ‰๋ฐ›๋Š” ๋กœ์ง ์ถ”๊ฐ€
  • access token ์žฌ๋ฐœ๊ธ‰๋„ ์‹คํŒจํ•  ๊ฒฝ์šฐ ๋กœ๊ทธ์•„์›ƒ

โœ… ๋ณ€๊ฒฝ๋กœ์ง

  • refresh token์€ ์กด์žฌํ•˜๊ณ  access token์€ ์กด์žฌํ•˜์ง€ ์•Š์„ ๋•Œ ๋กœ๊ทธ์ธ ์ƒํƒœ๋กœ ๋งŒ๋“ค๋ ค๊ณ  ์‹œ๋„ํ•ด๋ดค์œผ๋‚˜ ์ž˜์•ˆ๋˜๋„ค์š”..
  • ์ง€๊ธˆ์€ ๋กœ๊ทธ์ธํ•˜๋ฉด access token์„ local storage์— ๊ธฐํ•œ์—†์ด ์ €์žฅํ•ด์ฃผ๊ณ  ์žˆ์–ด์„œ refresh token์ด ์กด์žฌํ•˜๊ณ  access token์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š” ์ƒํ™ฉ์€ ์ง์ ‘ access๋งŒ ์ง€์šฐ์ง€ ์•Š๋Š” ์ด์ƒ ๋ฐœ์ƒํ•˜์ง€ ์•Š์„ ๊ฒƒ ๊ฐ™์•„์š”. (access token ๋งŒ๋ฃŒ๊ฐ€ ๋˜๋”๋ผ๋„ ๋งŒ๋ฃŒ๋œ token์€ local storage์— ์ €์žฅ๋˜์–ด ์žˆ๋Š” ์ƒํ™ฉ)
  • access token์ด ๋งŒ๋ฃŒ๋˜๋ฉด 401์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๊ณ  refresh token์œผ๋กœ ์žฌ๋ฐœ๊ธ‰๋˜๋Š” ๊ฒƒ์€ ํ™•์ธํ–ˆ์Šต๋‹ˆ๋‹ค. ์ž„์˜๋กœ access token์„ ์ง€์šฐ๊ณ  ๋‹ค๋ฅธ ํŽ˜์ด์ง€๋กœ ๊ฐ€๋ณด๋ฉด ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”. (ํ˜„์žฌ dev.42gg.kr ์‚ฌ์ดํŠธ์—์„œ ํ™•์ธ๊ฐ€๋Šฅ)

@42sungwook 42sungwook self-assigned this Jun 27, 2023
@42sungwook 42sungwook closed this Jun 28, 2023
@42sungwook 42sungwook reopened this Jun 30, 2023
Copy link
Contributor

@PHJoon PHJoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ƒˆ๋กœ๊ณ ์นจํ•˜๋ฉด ๋กœ๊ทธ์ธ ํŽ˜์ด์ง€๋กœ ๋Œ์•„๊ฐ€๋Š” ๋ฌธ์ œ๋„ ํ•ด๊ฒฐ๋˜๊ณ  local์—์„œ access ์ง€์šฐ๊ณ  ์ƒˆ๋กœ๊ณ ์นจํ•˜๋ฉด ๋‹ค์‹œ ํ† ํฐ ์ž˜ ๋ฐ›์•„์˜ค๋„ค์š” ๐Ÿ‘
๋กœ๊ทธ์•„์›ƒํ•˜๋ฉด refreshtoken์„ post์š”์ฒญ ๋ณด๋‚ด์„œ ์ฟ ํ‚ค์—์„œ ์ง€์šฐ๋Š” ๊ฑธ๊นŒ์š”? ๋กœ๊ทธ์•„์›ƒํ•˜๊ณ  ๋‚˜์„œ refreshtoken์ด ์ง€์›Œ์ง€๋Š” ์‚ฌ์ด์— accessToken ์š”์ฒญ์ด ๋ณด๋‚ด์ง€๋Š” ๊ฒƒ ๊ฐ™์•„์„œ ์งˆ๋ฌธ ๋‚จ๊น๋‹ˆ๋‹ค.
๋กœ๊ทธ์•„์›ƒํ•˜๊ณ  ๋‚˜๋ฉด refreshToken์€ ์ž˜ ์‚ฌ๋ผ์ง€๋Š”๋ฐ accessToken์ด ์‚ฌ๋ผ์กŒ๋‹ค๊ฐ€ ๋‹ค์‹œ ์ƒ๊ธฐ๋Š”๊ฑฐ ๊ฐ™์•„์„œ ํ™•์ธ ํ•œ๋ฒˆ๋งŒ ๋ถ€ํƒ๋“œ๋ ค์š”
๊ธฐ๋Šฅ์ƒ ๋ฌธ์ œ๋Š” ์—†๋Š”๊ฑฐ ๊ฐ™์•„์š”.
๋กœ๊ทธ์ธ access, refreshToken ์–ด๋ ค์šด ์ž‘์—… ๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค ๐Ÿ‘๐Ÿ‘

@42sungwook
Copy link
Contributor Author

์ƒˆ๋กœ๊ณ ์นจํ•˜๋ฉด ๋กœ๊ทธ์ธ ํŽ˜์ด์ง€๋กœ ๋Œ์•„๊ฐ€๋Š” ๋ฌธ์ œ๋„ ํ•ด๊ฒฐ๋˜๊ณ  local์—์„œ access ์ง€์šฐ๊ณ  ์ƒˆ๋กœ๊ณ ์นจํ•˜๋ฉด ๋‹ค์‹œ ํ† ํฐ ์ž˜ ๋ฐ›์•„์˜ค๋„ค์š” ๐Ÿ‘ ๋กœ๊ทธ์•„์›ƒํ•˜๋ฉด refreshtoken์„ post์š”์ฒญ ๋ณด๋‚ด์„œ ์ฟ ํ‚ค์—์„œ ์ง€์šฐ๋Š” ๊ฑธ๊นŒ์š”? ๋กœ๊ทธ์•„์›ƒํ•˜๊ณ  ๋‚˜์„œ refreshtoken์ด ์ง€์›Œ์ง€๋Š” ์‚ฌ์ด์— accessToken ์š”์ฒญ์ด ๋ณด๋‚ด์ง€๋Š” ๊ฒƒ ๊ฐ™์•„์„œ ์งˆ๋ฌธ ๋‚จ๊น๋‹ˆ๋‹ค. ๋กœ๊ทธ์•„์›ƒํ•˜๊ณ  ๋‚˜๋ฉด refreshToken์€ ์ž˜ ์‚ฌ๋ผ์ง€๋Š”๋ฐ accessToken์ด ์‚ฌ๋ผ์กŒ๋‹ค๊ฐ€ ๋‹ค์‹œ ์ƒ๊ธฐ๋Š”๊ฑฐ ๊ฐ™์•„์„œ ํ™•์ธ ํ•œ๋ฒˆ๋งŒ ๋ถ€ํƒ๋“œ๋ ค์š” ๊ธฐ๋Šฅ์ƒ ๋ฌธ์ œ๋Š” ์—†๋Š”๊ฑฐ ๊ฐ™์•„์š”. ๋กœ๊ทธ์ธ access, refreshToken ์–ด๋ ค์šด ์ž‘์—… ๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค ๐Ÿ‘๐Ÿ‘

์˜ค ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ๊นŒ๋จน๊ณ  ์žˆ์—ˆ์–ด์š”. ์ œ๊ฐ€ logoutํ•  ๋•Œ accesstoken์„ ์ง€์šฐ๊ณ  post ์š”์ฒญ์„ ๋ณด๋‚ด๋‹ˆ๊นŒ ์—๋Ÿฌ๊ฐ€ ๋‚œ๊ฑฐ์˜€์–ด์š”. ์ง€๊ธˆ ๋‹ค์‹œ ๊ณ ์ณค์Šต๋‹ˆ๋‹ค

Copy link
Contributor

@parksangmin1543 parksangmin1543 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์—ฐ๋™ํ•˜๊ธฐ ๋ถ€๋ถ„์—์„œ ์—ฐ๋™ํ•˜๊ธฐ๋ˆ„๋ฅด๊ณ  ํ•ด์ œ๋ฅผ ํ•˜๊ฑฐ๋‚˜ ํ•ด์ œํ›„ ์—ฐ๋™์„ ํ•˜๋Š” ๊ฒฝ์šฐ์— 401์—๋Ÿฌ๊ฐ€ ๋œจ๊ฑฐ๋‚˜ whitelabel error page๋กœ ๋„˜์–ด๊ฐ€๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.
์—ฐ๋™ํ•˜๊ธฐ๋ฅผ ๋ˆ„๋ฅผ๋•Œ 401์ด ๋œจ๊ฒŒ ๋˜๋ฉด ๋กœ๊ทธ์•„์›ƒํ›„ ์นด์นด์˜ค๋กœ๊ทธ์ธ์ด ๋ง‰ํžˆ๊ณ  ์—ฐ๋™ํ•ด์ œ์‹œ ๋กœ๊ทธ์ธํ• ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

@42sungwook 42sungwook merged commit a449f34 into main Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants