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

feat: Receive Kakao Server Access Token (OAuth2) #5

Merged
merged 9 commits into from
Mar 18, 2024
Merged

Conversation

h-beeen
Copy link
Member

@h-beeen h-beeen commented Mar 16, 2024

PULL REQUEST

๐ŸŽ‹ ์ž‘์—… ์ค‘์ธ ๋ธŒ๋žœ์น˜

๐Ÿ”‘ ์ฃผ์š” ์ž‘์—…์‚ฌํ•ญ

  • Kakao Developer OAuth2 ํ‚ค ๊ฐ’ ์ถ”๊ฐ€
  • OAuth ์š”์ฒญ์„ Provider Path๋ฅผ ํ™œ์šฉํ•ด ํด๋ผ์ด์–ธํŠธ ๋ณ„๋กœ ๋ถ„๊ธฐ
  • ํ˜„์žฌ, Kakao OAuth2 ํด๋ผ์ด์–ธํŠธ์˜ providerId๋ฅผ ํ™œ์šฉํ•œ ํšŒ์›๊ฐ€์ž… ๋ฐ JWT Access/Refresh ํ† ํฐ ๋ถ€์—ฌ๊นŒ์ง€ ๊ตฌํ˜„

๐Ÿž (Optional) ์ฐธ๊ณ  ์ž๋ฃŒ

ํšŒ์›๊ฐ€์ž… ํ”Œ๋กœ์šฐ

  • ํด๋ผ์ด์–ธํŠธ๊ฐ€ https://api.vacgom.co.kr/v1/oauth/kakao/ ์—”๋“œํฌ์ธํŠธ ํ˜ธ์ถœ
  • ์„œ๋ฒ„์—์„œ kakao Client์— ๋งž๋Š” Kakao ๋กœ๊ทธ์ธ Uri๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ (Http Status 302)
  • ๋กœ๊ทธ์ธ Uri๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์ข…๋ฃŒ๋œ๋‹ค๋ฉด, ํ•ด๋‹น Kakao ProviderId ๊ธฐ๋ฐ˜์œผ๋กœ ํšŒ์›๊ฐ€์ž… or ๊ธฐ์กด ๊ฐ€์ž… ์œ ์ € ์ฐพ๊ธฐ
  • ํ•ด๋‹น ์œ ์ €๋ฅผ ๊ธฐ์ค€์œผ๋กœ JWT Access ํ† ํฐ ๋ฐœํ–‰ ํ›„ ์•„๋ž˜ ์‘๋‹ต ๋ฐ˜ํ™˜
{
  "member": {
    "memberId": "05d602f6-91f8-4ab0-8dc5-c6b6b71425ed", // UUID
    "role": "ROLE_TEMP_USER" // ROLE
  },
  "token": {
    "accessToken": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIwNWQ2MDJmNi05MWY4LTRhYjAtOGRjNS1jNmI2YjcxNDI1ZWQiLCJpYXQiOjE3MTA2MzE4NTMsImV4cCI6MTcxMDY0MDg1M30.hNG0CG5zdk9NetVRRMQ******",
    "refreshToken": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIwNWQ2MDJmNi05MWY4LTRhYjAtOGRjNS1jNmI2YjcxNDI1ZWQiLCJpYXQiOjE3MTA2MzE4NTMsImV4cCI6MTcxMTg0MTQ1M30.t96qYOQnVEJyBdGIWUy******"
  }
}
  • ์ดํ›„ ํด๋ผ์ด์–ธํŠธ ์š”์ฒญ์— ๋”ฐ๋ผ, ๋ฉ”์ธ ํŽ˜์ด์ง€ or ๋ฐฑ์‹  ์กฐํšŒ ํŽ˜์ด์ง€๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ๊ฐ€๋Šฅ (๊ตฌํ˜„์  ํ˜‘์˜ํ•ด์•ผํ•จ)

๊ด€๋ จ ์ด์Šˆ

๊ผญ ํ™•์ธํ•ด ์ฃผ์„ธ์š”!!

  • access token Validation ๋กœ์ง access token ๋กœ๊ทธ์ธ ์ถ”ํ›„ ๊ฐœ๋ฐœ ์˜ˆ์ • (refresh token์„ ํ™œ์šฉํ•œ ํ† ํฐ ์žฌ๋ฐœ๊ธ‰...๊ตณ์ด ํ•„์š”ํ• ๊นŒ์š”...?)
  • ์•„์ง java์˜ ๋Šช์— ๋ฒ—์–ด๋‚˜์ง€ ๋ชปํ•ด ์ด ์•„๋ฅธ๊ฑฐ๋ฆฌ๋Š” ์ฝ”ํ‹€๋ฆฐ ์•„๊ฐ€์˜ ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.
    ์ฝ”ํ‹€๋ฆฐ์Šค๋Ÿฝ์ง€ ์•Š์€ ๋ฌธ๋ฒ•์— ๋Œ€ํ•œ ๋ฆฌ๋ทฐ์™€ Suggestion ์ ˆ์ฐฌํ™˜์˜!!
  • ์ด๋ฒˆ ์ฝ”๋“œ๋Š” ์‹œํ๋ฆฌํ‹ฐ๋ฅผ ํ†ต์งธ๋กœ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด ๋ชฉํ‘œ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ฆฌ๋ทฐ ์–‘์ด ๋งŽ์„ ๊ฒƒ์œผ๋กœ ์ƒ๊ฐ๋ฉ๋‹ˆ๋‹ค.
    ๋‹ค์Œ ์ฝ”๋“œ๋ถ€ํ„ฐ๋Š” ์ž˜๊ฒŒ ์ชผ๊ฐœ์„œ ์†Œ๊ทœ๋ชจ PR๋กœ ๋ถ„๊ธฐํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค :)

@h-beeen h-beeen added the โœจ Feat ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒฝ์šฐ label Mar 16, 2024
@h-beeen h-beeen added this to the [Global] Security Logic milestone Mar 16, 2024
@h-beeen h-beeen requested a review from HyungJu March 16, 2024 13:14
@h-beeen h-beeen self-assigned this Mar 16, 2024
Base automatically changed from develop to master March 17, 2024 02:38
Copy link
Collaborator

@HyungJu HyungJu left a comment

Choose a reason for hiding this comment

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

๋„ˆ๋ฌด .. ๋„ˆ๋ฌด ์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค ..
์ œ๊ฐ€ ๊ฐํžˆ ๋ฌด์Šจ ๋ฆฌ๋ทฐ๋ฅผ ๋‚จ๊ฒจ๋„ ๋˜๋Š”์ง€๋Š” ๋ชจ๋ฅด๊ฒ ์ง€๋งŒ ใ… ใ… 

์ œ๊ฐ€ ๋ดค์„๋•Œ ๊ถ๊ธˆํ–ˆ๋˜ ์ ์ด๋‚˜, ๊ฐœ์„ ํ–ˆ์œผ๋ฉด ์ข‹๊ฒ ๋Š” ์ ๋“ค์„ ๊ฐ„๋‹จํžˆ ๋‚จ๊ฒจ๋ณด์•˜์Šต๋‹ˆ๋‹ค!

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.. ๐Ÿฅน

+) ์ด๊ฑฐ ์ž‘์—… ๋‹ค ํ•˜์‹œ๋ฉด ์ œ๊ฐ€ ํ˜•์ฃผ์‹ .. ํด๋ฆฐ ์•„ํ‚คํ…์ฒ˜๋กœ ๋ฆฌํŒฉํ† ๋ง์„ ํ•ด์„œ ๊ดœ์ฐฎ์„์ง€ ์˜๊ฒฌ์„ ํ•œ๋ฒˆ ์—ฌ์ญค๋ณด๊ณ  ์‹ถ์€๋ฐ ๊ทธ๋ž˜๋„ ๊ดœ์ฐฎ์œผ์‹ค๊นŒ์š” ..?!

@Id
@GeneratedValue
@Column(name = "rt_id")
private val id: Long? = null
Copy link
Collaborator

Choose a reason for hiding this comment

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

id๋„ ๋‹ค๋ฅธ ํ”„๋ผํผํ‹ฐ๋“ค ์ฒ˜๋Ÿผ ์ƒ์„ฑ์ž ์ž๋ฆฌ์—์„œ ์ •์˜ํ•˜์…”๋„ ๋ฌธ์ œ ์—†์Šต๋‹ˆ๋‹ค !

Copy link
Collaborator

Choose a reason for hiding this comment

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

๊ทธ๋ฆฌ๊ณ  RefreshToken ์—”ํ‹ฐํ‹ฐ๋Š” BaseEntity ์ƒ์†์„ ์•ˆ๋ฐ›๊ณ  ์žˆ๋Š”๋ฐ ์˜๋„๋œ ๊ฒƒ์ธ์ง€๋„ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค !!

Copy link
Member Author

@h-beeen h-beeen Mar 17, 2024

Choose a reason for hiding this comment

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

@HyungJu ๊ถ๊ธˆํ•œ ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค!!
์ƒ์„ฑ์ž๋ฅผ ํ†ตํ•ด RefreshToken์„ ์ƒ์„ฑํ•˜๋ ค๊ณ  ํ•  ๋•Œ,
id์™€ ๊ฐ™์€ GeneratedValue Property๋ฅผ null๋กœ ํ• ๋‹นํ•ด ์ž‘์—…ํ•˜๋‚˜์š”?
๊ฐ์ฒด ์ƒ์„ฑ ํŒŒ๋ผ๋ฏธํ„ฐ์— null์„ ๋„ฃ๋Š”๊ฒŒ ์–ด์ƒ‰ํ•ด์„œ ๋ถ„๋ฆฌํ•ด๋ณด์•˜๋Š”๋ฐ, ์š” ๋ถ€๋ถ„๋„ ์˜๊ฒฌ ๋ถ€ํƒ๋“œ๋ฆด๊ฒŒ์š”!!

Copy link
Member Author

@h-beeen h-beeen Mar 17, 2024

Choose a reason for hiding this comment

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

๊ทธ๋ฆฌ๊ณ  RefreshToken ์—”ํ‹ฐํ‹ฐ๋Š” BaseEntity ์ƒ์†์„ ์•ˆ๋ฐ›๊ณ  ์žˆ๋Š”๋ฐ ์˜๋„๋œ ๊ฒƒ์ธ์ง€๋„ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค !!

RefreshToken์—ญ์‹œ BaseEntity ์ƒ์†์„ ๋ฐ›์•„์•ผ ๋งž์Šต๋‹ˆ๋‹ค!
์š” ๋ถ€๋ถ„๋„ ๋ฐ˜์˜ํ•ด๋‘˜๊ฒŒ์š”!!
p.s.Redis ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜ ์—ผ๋‘์ค‘..

Copy link
Collaborator

@HyungJu HyungJu Mar 17, 2024

Choose a reason for hiding this comment

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

@HyungJu ๊ถ๊ธˆํ•œ ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค!! ์ƒ์„ฑ์ž๋ฅผ ํ†ตํ•ด RefreshToken์„ ์ƒ์„ฑํ•˜๋ ค๊ณ  ํ•  ๋•Œ, id์™€ ๊ฐ™์€ GeneratedValue Property๋ฅผ null๋กœ ํ• ๋‹นํ•ด ์ž‘์—…ํ•˜๋‚˜์š”? ๊ฐ์ฒด ์ƒ์„ฑ ํŒŒ๋ผ๋ฏธํ„ฐ์— null์„ ๋„ฃ๋Š”๊ฒŒ ์–ด์ƒ‰ํ•ด์„œ ๋ถ„๋ฆฌํ•ด๋ณด์•˜๋Š”๋ฐ, ์š” ๋ถ€๋ถ„๋„ ์˜๊ฒฌ ๋ถ€ํƒ๋“œ๋ฆด๊ฒŒ์š”!!

์‚ฌ์‹ค ์ „ Domain Model -> Entity ๊ฐ„ ๋ณ€ํ™˜์„ ํ• ๋•Œ id๋„ ํ•จ๊ป˜ ๋งคํ•‘์„ ํ•ด์ค˜์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— .. ๊ทธ๋ ‡๊ฒŒ ํ•˜๊ณ  ์žˆ์–ด์š”
image
(์ด๋ฏธ์ง€ ์ฐธ์กฐ)

์•„๋‹ˆ๋ฉด named argument๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์กฐ๊ธˆ ๋ณด๊ธฐ ์ข‹๊ฒŒ ํ‘œํ˜„ํ• ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค ! (named argument๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด default value๊ฐ€ ์ง€์ •๋˜์–ด ์žˆ์„๋•Œ ํ•ด๋‹น argument๋Š” ์ƒ๋žตํ•  ์ˆ˜ ์žˆ์–ด์š”)
image

Copy link
Member Author

Choose a reason for hiding this comment

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

์˜คํ˜ธ ์ด ๋ถ€๋ถ„์€ ์ฒ˜์Œ ์ ‘ํ•˜๋Š” ์ •๋ณด์ธ๋ฐ์š”..
์–ด๋–ค ๋Š๋‚Œ์ธ์ง€๋Š” ์•Œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
์š” ๋ถ€๋ถ„๋„ #8 PR์—์„œ ๋ฐ˜์˜ํ•ด๋ณผ๊ฒŒ์š”!!

@HyungJu
Copy link
Collaborator

HyungJu commented Mar 17, 2024

์ œ๊ฐ€ ๋ฆฌ๋ทฐ ํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ๋” ๋ฐฐ์›Œ์™€์„œ ๋‹ค์Œ ๋ฆฌ๋ทฐ๋Š” ์ข€ ๋” ์ž˜ .. ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค .. ํ•ญ์ƒ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ..

@h-beeen h-beeen linked an issue Mar 17, 2024 that may be closed by this pull request
@HyungJu
Copy link
Collaborator

HyungJu commented Mar 17, 2024

(refresh token์„ ํ™œ์šฉํ•œ ํ† ํฐ ์žฌ๋ฐœ๊ธ‰...๊ตณ์ด ํ•„์š”ํ• ๊นŒ์š”...?)
-> ์ €๋„ ๊ต‰์žฅํžˆ ๋™์˜ํ•˜๋Š” ๊ฒƒ์ด .. ! ์ง€๊ธˆ ๋‹จ๊ณ„์—์„œ๋Š” ๊ธธ์ด๊ฐ€ ์ ๋‹นํžˆ ๊ธด ์—‘์„ธ์Šค ํ† ํฐ๋งŒ ๋ฐœ๊ธ‰ํ•ด๋„ ๋ฌด๋ฆฌ๋Š” ์—†์–ด๋ณด์ž…๋‹ˆ๋‹ค .. !

h-beeen added 2 commits March 18, 2024 20:12
* feat: JWT ์—ฐ๋™ ์™„๋ฃŒ ๋ฐ ๊ตฌ์กฐ ๊ฐœ์„ 

* feat: OAuth2 ๊ตฌํ˜„ ์™„๋ฃŒ

* feat: ์ฝ”ํ‹€๋ฆฐ์Šค๋Ÿฌ์šด ๋ฌธ๋ฒ• ์ˆ˜์ •
@h-beeen h-beeen changed the base branch from master to develop March 18, 2024 11:22
@h-beeen h-beeen merged commit abd5688 into develop Mar 18, 2024
1 check passed
@h-beeen h-beeen deleted the feat/#1 branch March 18, 2024 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
โœจ Feat ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒฝ์šฐ
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Spring Security & Oauth2 ๊ตฌํ˜„
2 participants