π
[μ€νλ§ μνλ¦¬ν° OAuth2] OAuth 2.0 Social Login
1. νμΌ κ΅¬μ±
- κ° OAuth2 μλΉμ€ μ 곡μλ€μ μ°λμ ν΅ν΄ μΈμ¦ λ° μΈκ° κΈ°λ₯μ ꡬννκ³ κ³΅ν΅νλͺ©μ μΆμννλ€
- OpenID Connect Provider λ₯Ό μ§μνλ μλ²μ μ§μνμ§ μλ μλ²μ λνμ¬ μ€νλ§ μν리ν°μ μ°λ μ²λ¦¬λ₯Ό μν λ΄λΆμ리λ₯Ό μ΄ν΄νλ€
- OAuth2UserService λ₯Ό 컀μ€ν°λ§μ΄μ§νμ¬ μΈμ¦ μ΄ν νμκ°μ μ²λ¦¬λ₯Ό μν λΆκ° μλΉμ€λ₯Ό ꡬννλ€
- OAuth2User μ OidcUser μ²λ¦¬λ₯Ό ꡬλΆνμ¬ κ΅¬ννκ³ μ€νλ§ MVC μμ νμ λ³λ‘ μΈμ¦κ°μ²΄λ₯Ό μ°Έμ‘°νλ λ°©λ²μ μμλ³Έλ€
- Scope μ μ 보λ₯Ό κΆνμ λ³΄λ‘ λ§€ννλ μ리λ₯Ό νμ νκ³ μ΄λ₯Ό 컀μ€ν°λ§μ΄μ§νλ λ°©λ²μ μμλ³Έλ€
2. Google μ°λ
μ°λ μ μ°¨
- OAuth2 Client μ Google μΈκ°μλ²μμ μ°λμ ν΅ν΄ μΈμ¦/μΈκ° νλ‘μΈμ€λ₯Ό ꡬννλ€
- κ΅¬κΈ μλΉμ€μ μ κ· μλΉμ€λ₯Ό μμ±νλ€ - https://console.cloud.google.com/
-
application.yml μ€μ
spring: security: oauth2: client: registration: google: client-id: 823010453529-xxxxxxxxxxxxxxxxxxxxx client-secret: GOCSPX- xxxxxxxxxxxxxxxxxxxxx
3. Naver μ°λ
μ°λ μ μ°¨
- OAuth2 Client μ Naver μΈκ°μλ²μμ μ°λμ ν΅ν΄ μΈμ¦/μΈκ° νλ‘μΈμ€λ₯Ό ꡬννλ€
- λ€μ΄λ² API μμ μ κ· μλΉμ€λ₯Ό μμ±νλ€ - https://developers.naver.com/main/
-
application.yml μ€μ
spring: security: oauth2: client: provider: naver: authorization-uri: https://nid.naver.com/oauth2.0/authorize jwk-set-uri: https://openapi.naver.com/v1/nid/verify token-uri: https://nid.naver.com/oauth2.0/token user-info-uri: https://openapi.naver.com/v1/nid/me user-name-attribute: response registration: naver: client-id: ad6x8jw3fzuq- xxxxxxxxxxxxxxxxxxxxx client-secret: dG4- xxxxxxxxxxxxxxxxxxxxx authorization-grant-type: authorization_code client-name: naver-client-app redirect-uri: http://localhost:8081/login/oauth2/code/naver scope: profile,email
4. Keycloak μ°λ
μ°λ μ μ°¨
- OAuth2 Client μ Keycloak μΈκ°μλ²μμ μ°λμ ν΅ν΄ μΈμ¦/μΈκ° νλ‘μΈμ€λ₯Ό ꡬννλ€
- http://localhost:8080/
-
application.yml μ€μ
spring: security: oauth2: client: provider: keycloak: authorization-uri: http://localhost:8080/realms/oauth2/protocol/openid-connect/auth issuer-uri: http://localhost:8080/realms/oauth2 jwk-set-uri: http://localhost:8080/realms/oauth2/protocol/openid-connect/certs token-uri: http://localhost:8080/realms/oauth2/protocol/openid-connect/token user-info-uri: http://localhost:8080/realms/oauth2/protocol/openid-connect/userinfo user-name-attribute: preferred_username registration: keycloak: authorization-grant-type: authorization_code client-id: oauth2-xxxxxxxxxxxxxxxxxxxxx client-name: oauth2-client-app client-secret: CQueEWXZ-xxxxxxxxxxxxxxxxxxxxx redirect-uri: http://localhost:8081/login/oauth2/code/keycloak scope: profile,email
5. Form μΈμ¦ + Kakao μ°λ
μ°λ μ μ°¨
-
Form μΈμ¦κ³Ό OAuth2 μΈμ¦μ μ°κ³νμ¬ μλΉμ€νλ€
http.formLogin().loginPage("/login").loginProcessingUrl("/loginProc").defaultSuccessUrl("/").permitAll(); http.exceptionHandling().authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/login"));
- μΉ΄μΉ΄μ€ API μμ μ κ· μλΉμ€λ₯Ό μμ±νλ€ - https://developers.kakao.com/
- application.yml μ€μ
spring: security: oauth2: client: provider: kakao: issuer-uri: https://kauth.kakao.com 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: id registration: kakao: client-id: ad6x8jw3fzuq- xxxxxxxxxxxxxxxxxxxxx client-secret: dG4- xxxxxxxxxxxxxxxxxxxxx authorization-grant-type: authorization_code client-name: kakao-client-app redirect-uri: http://localhost:8081/login/oauth2/code/kakao scope: openid,profile,email
π μμ€
https://github.com/sk4cks/Spring-Security-Oauth2/tree/f539f23dcfeed196cfd60765b2e107c260973977
λκΈλ¨κΈ°κΈ°