๐ŸŽฎ [SPRING BOOT] | ์†Œ์…œ ๋กœ๊ทธ์ธ (ํŽ˜์ด์Šค๋ถ, ๊ตฌ๊ธ€ , ์นด์นด์˜ค , ๋„ค์ด๋ฒ„)

4
post-thumbnail

์‚ฌ์ง„์ถœ์ฒ˜


  • ์ƒˆ๋กœ๋น„๋ธ”๋กœ๊ทธ์˜ ์Šคํ”„๋ง ๋ถ€ํŠธ๋กœ OAuth2 ๊ตฌํ˜„(ํŽ˜์ด์Šค๋ถ, ๊ตฌ๊ธ€, ์นด์นด์˜ค, ๋„ค์ด๋ฒ„)๊ธ€์„ ์ฐธ๊ณ ํ•˜์‹œ๋ฉด ๋„์›€์ด ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

์ง€์‹๊ณผ ๊ฟ€ํŒ์ด ๋„˜์น˜๋Š” "์ƒˆ๋กœ๋น„" ๋ธ”๋กœ๊ทธ ๋ฐฉ๋ฌธํ•˜๊ธฐ
"์Šคํ”„๋ง ๋ถ€ํŠธ๋กœ OAuth2 ๊ตฌํ˜„(ํŽ˜์ด์Šค๋ถ, ๊ตฌ๊ธ€, ์นด์นด์˜ค, ๋„ค์ด๋ฒ„)" ๊ธ€ ๋ณด๋Ÿฌ๊ฐ€๊ธฐ


๐ŸŸกโ— ํ•˜์ง€๋งŒ ๊ธ€์˜ ๋‚ด์šฉ๊ณผ ์‚ฌ์ง„์€ ๋ชจ๋‘ ๋ฐ•๋„ํ ๊ฐ•์‚ฌ๋‹˜์˜ ๊ฐ•์˜ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. โ—๐ŸŸก


๐Ÿ”น ์นด์นด์˜คํ†ก

  • https://developers.kakao.com/ ๋กœ๊ทธ์ธ

  • redirect URI
    ์Šคํ”„๋ง ๋ถ€ํŠธ์˜ ์‹œํ๋ฆฌํ‹ฐ๋ฅผ ์“ฐ๊ณ  ์žˆ์–ด์„œ
    yamlํŒŒ์ผ์—์„œ ์„ค์ •ํ•œ redirect-uri ๋ถ€๋ถ„์„ ์ ์–ด์•ผ ํ•œ๋‹ค

  • ๋™์˜ ํ•ญ๋ชฉ
    ์ด๋ฉ”์ผ์€ ํ•„์ˆ˜๋™์˜๊ฐ€ ์•„๋‹ˆ๋ผ์„œ ๊ทธ๋ƒฅ ์‚ฌ์šฉ์•ˆํ•˜๊ณ , ์นด์นด์˜คํ†ก ๋กœ๊ทธ์ธ ์‚ฌ์šฉ์ž์ผ ๊ฒฝ์šฐ์—๋Š” ๋˜๋Š” ๋ชจ๋“  ์†Œ์…œ๋กœ๊ทธ์ธ ์‚ฌ์šฉ์ž๋“ค์—๊ฒŒ๋Š” ์ด๋ฉ”์ผ ์ •๋ณด๋ฅผ ์ถ”๊ฐ€ ์ž…๋ ฅํ•˜๊ฒŒ ๋งŒ๋“ค์–ด์•ผ ํ•  ๊ฒƒ ๊ฐ™๋‹ค

๐Ÿ”น ๋„ค์ด๋ฒ„

  • https://developers.naver.com/main/ ๋กœ๊ทธ์ธ

  • ์„œ๋น„์Šค URL
    - ๋ฃจํŠธ ์ฃผ์†Œ or ๊ตฌ๋งคํ•œ ๋„๋ฉ”์ธ

  • Callback URL

    • redirect URI
      ์Šคํ”„๋ง ๋ถ€ํŠธ์˜ ์‹œํ๋ฆฌํ‹ฐ๋ฅผ ์“ฐ๊ณ  ์žˆ์–ด์„œ
      yamlํŒŒ์ผ์—์„œ ์„ค์ •ํ•œ redirect-uri ๋ถ€๋ถ„์„ ์ ์–ด์•ผ ํ•œ๋‹ค












๐Ÿ”น ํŽ˜์ด์Šค๋ถ

  • https://developers.facebook.com/ ๋กœ๊ทธ์ธ
  • https://jsikim1.tistory.com/114
  • ํŽ˜์ด์Šค๋ถ > ๋‚ด ์•ฑ > ์•ฑ ๋งŒ๋“ค๊ธฐ
  • Facebook ๋กœ๊ทธ์ธ > ๋น ๋ฅธ ์‹œ์ž‘ > ์•ฑ ๋งŒ๋“ค๊ธฐ
      1. ์›น์‚ฌ์ดํŠธ์— ๋Œ€ํ•ด Facebook์— ์•Œ๋ฆฌ๊ธฐ (์„ค์ •)
      1. JavaScript์šฉ Facebook SDK ์„ค์ • (๋„˜์–ด๊ฐ€๊ธฐ)
      1. ๋กœ๊ทธ์ธ ์ƒํƒœ ํ™•์ธ (๋„˜์–ด๊ฐ€๊ธฐ)
      1. Facebook ๋กœ๊ทธ์ธ ๋ฒ„ํŠผ ์ถ”๊ฐ€ (๋„˜์–ด๊ฐ€๊ธฐ)
      1. ๋‹ค์Œ๋‹จ๊ณ„ (๋„˜์–ด๊ฐ€๊ธฐ)
    • ์œ ํšจํ•œ ๋ฆฌ๋‹ค๋ ‰์…˜ (๋„˜์–ด๊ฐ€๊ธฐ)








๐Ÿ”น ๊ตฌ๊ธ€

  • https://console.developers.google.com/?pli=1 ๋กœ๊ทธ์ธ

  • ์Šน์ธ๋œ ๋„๋ฉ”์ธ : ์ง„์งœ ๋„๋ฉ”์ธ๋งŒ ํ•˜๋ฉด๋œ๋‹ค. ๋กœ์ปฌ ํ˜ธ์ŠคํŠธ๋ฉด ๋„˜์–ด๊ฐ€๋ฉด ๋œ๋‹ค.

  • ๋ฒ”์œ„, ํ…Œ์ŠคํŠธ ์‚ฌ์šฉ์ž ๊ทธ๋ƒฅ ๋„˜์–ด๊ฐ€๋ฉด ๋œ๋‹ค.

  • ์Šน์ธ๋œ ๋ฆฌ๋‹ค๋ ‰์…˜ URL

    • ๊ธฐ๋ณธ URL ์ ์œผ๋ฉด ๋œ๋‹ค. ๋ฐ”๊พธ๊ณ  ์‹ถ๋‹ค๋ฉด yamlํŒŒ์ผ์—์„œ ์ƒˆ๋กœ ์„ค์ •ํ•œ๋‹ค.
    • ๊ธฐ๋ณธ URL : uri /login/oauth2/code/
    • ๊ตฌ๊ธ€ , ํŽ˜์ด์Šค๋ถ, ๊นƒํ—ˆ๋ธŒ, ํŠธ์œ„ํ„ฐ๋Š” ๊ธฐ๋ณธ์„ธํŒ… ๋˜์–ด์žˆ์–ด์„œ ๋”ฐ๋กœ ์„ค์ • ์•ˆํ•ด์ค˜๋„ ๋œ๋‹ค. ํ•˜์ง€๋งŒ ๊ตญ๋‚ด๋Š” ํ•ด์•ผํ•œ๋‹ค.



















๐Ÿ”น ์†Œ์Šค

  security:
      oauth2:
        client:
          registration:
            google:
              client-id: your-client-id
              client-secret: your-client-secret
              redirectUri: "{baseUrl}/oauth2/callback/{registrationId}"
              scope:
                - profile
                - email
            facebook:
              client-id: your-client-id
              client-secret: your-client-secret
              redirectUri: "{baseUrl}/oauth2/callback/{registrationId}"
            kakao:
              authorization-grant-type: authorization_code
              client-id: your-client-id
              client-secret: your-client-secret
              redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}"
              scope:
                - profile
                - account_email
              client-authentication-method: POST
              client-name: Kakao
            naver:
              authorization-grant-type: authorization_code
              client-id: your-client-id
              client-secret: your-client-secret
              redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}"
              scope: name,email,profile_image
              client-name: Naver

          provider:
            kakao:
              authorization-uri: https://kauth.kakao.com/oauth/authorize
              token-uri: https://kauth.kakao.com/oauth/token
              user-info-uri: https://kapi.kakao.com/v2/user/me
              user-name-attribute: properties
              # JSON ํ˜•ํƒœ์—์„œ "properties"๋ผ๋Š” key๊ฐ’์— ํ•ด๋‹นํ•˜๋Š” value์— ํšŒ์› ์ •๋ณด๊ฐ€ ๋‹ด๊ฒจ์ ธ์žˆ๋‹ค.
            naver:
              authorization-uri: https://nid.naver.com/oauth2.0/authorize
              token-uri: https://nid.naver.com/oauth2.0/token
              user-info-uri: https://openapi.naver.com/v1/nid/me
              user-name-attribute: response
              # JSON ํ˜•ํƒœ์—์„œ "response"๋ผ๋Š” key๊ฐ’์— ํ•ด๋‹นํ•˜๋Š” value์— ํšŒ์› ์ •๋ณด๊ฐ€ ๋‹ด๊ฒจ์ ธ์žˆ๋‹ค.

๐Ÿ”น ์‹œํ๋ฆฌํ‹ฐ ์—…๋ฐ์ดํŠธ

  • CustomUserPrincipalํด๋ž˜์Šค์˜ implements์— OAuth2Userํด๋ž˜์Šค ์ถ”๊ฐ€

๐Ÿ”น Pom.xml ์—…๋ฐ์ดํŠธ

  • oauth2-client ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ถ”๊ฐ€

๐Ÿ”น DB ์—…๋ฐ์ดํŠธ

  • provider์ปฌ๋Ÿผ ์ถ”๊ฐ€ , ๊ธฐ๋ณธ๊ฐ’์€ local๋กœ ์„ค์ •

profile
๋ช‡ ๋ฒˆ์„ ๋„˜์–ด์ ธ๋„ ์•ž์œผ๋กœ ๊ณ„์† ๋‚˜์•„๊ฐ€์ž

0๊ฐœ์˜ ๋Œ“๊ธ€