[미니프로젝트] 소셜 로그인 설정

김동혁·2025년 12월 7일

미니프로젝트

목록 보기
9/16

구글, 카카오, 네이버 소셜 로그인을 진행하기 위해서는 각각 앱 등록 페이지에 들어가서 키 발급 등의 작업을 해주어야 한다
카카오 OAuth2
네이버 OAuth2
구글 OAuth2

application.yml 설정

앱 등록을 모두 마쳤으면 인텔리제이로 돌아와 application.yml에 oauth2 설정을 해주어야 한다
주의할 점은 카카오는 다른 소셜과 다르게 client-authentication-method: client_secret_post 설정을 해주어야 한다고 한다
구글 서비스는 provider 항목이 없어도 자동으로 설정된다고 한다

각 서비스 별 설정해야 하는 scope는 위의 링크에 더 자세히 나와있다

spring:
  application:
    name: login-mini
    
  security:
    oauth2:
      client:
        registration:
          naver:
            client-name: naver
            client-id: REST API 키
            client-secret: CLIENT SECRET 키
            redirect-uri: http://localhost:8080/login/oauth2/code/naver
            authorization-grant-type: authorization_code
            scope:
              - name
              - email
          google:
            client-name: google
            client-id: REST API 키
            client-secret: CLIENT SECRET 키
            redirect-uri: http://localhost:8080/login/oauth2/code/google
            authorization-grant-type: authorization_code
            scope:
              - profile
              - email
          kakao:
            client-name: kakao
            client-id: REST API 키
            client-secret: CLIENT SECRET 키
            redirect-uri: http://localhost:8080/login/oauth2/code/kakao
            authorization-grant-type: authorization_code
            client-authentication-method: client_secret_post
            scope:
              - profile_nickname
              - account_email

        provider:
          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

          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: id

각 항목 별 설명은 다음과 같다

#registration
spring.security.oauth2.client.registration.서비스명.client-name=서비스명
spring.security.oauth2.client.registration.서비스명.client-id=서비스에서 발급 받은 아이디
spring.security.oauth2.client.registration.서비스명.client-secret=서비스에서 발급 받은 비밀번호
spring.security.oauth2.client.registration.서비스명.redirect-uri=서비스에 등록한 우리쪽 로그인 성공 URI
spring.security.oauth2.client.registration.서비스명.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.서비스명.scope=리소스 서버에서 가져올 데이터 범위

#provider
spring.security.oauth2.client.provider.서비스명.authorization-uri=서비스 로그인 창 주소
spring.security.oauth2.client.provider.서비스명.token-uri=토큰 발급 서버 주소
spring.security.oauth2.client.provider.서비스명.user-info-uri=사용자 정보 획득 주소
spring.security.oauth2.client.provider.서비스명.user-name-attribute=응답 데이터 변수

0개의 댓글