구글, 네이버 로그인 세팅

김민주·2024년 6월 3일
spring boot 3.3.0
java 21

기본 email profile openid 3개 scope 연결
카카오도 연결할거니까 openid 제외하고 2개만 연결

oauth client id 생성
왼쪽menu
사용자 인증정보 -> 사용자 인증정보 만들기 -> oauth client id

승인된 redirection uri 설정

생성 완료


  • build.gradle 의존성 추가
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-security'

'spring-boot-starter-security'의존성은 로그인 인증을 받은 후 경로를 이용할 수 있는 것. 모든 경로에 대해서 로그인인증을 받기 전까지는 로그인or기본페이지만 보임

src/main/resources/ 의 application.yml 설정

spring:
  security:
    oauth2:
      client:
        registration:
          google:
            client-id:
            client-secret:
            scope:
              - email
              - profile
          naver:
            client-id:
            client-secret:
            redirect-uri:
            client-name: Naver
            authorization-grant-type: authorization_code
            scope:
              - name
        provider: # naver 추가로 작성
          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

https://github.com/6-people/findclothes/blob/dev/src/main/java/com/people/findclothes/domain/User.java
나머지 참고


redis 설정

brew services start redis
redis-cli -- redis 실행

application.yml

spring:
  data:
    redis:
      host: localhost
      port: 6379
      url: jdbc:redis://유저네임:비밀번호@호스트 이름:포트번호
      password: 비밀번호

참고

https://velog.io/@gmldus0008/Spring-Boot-Oauth2.0-%EC%86%8C%EC%85%9C-%EB%A1%9C%EA%B7%B8%EC%9D%B8kakao-naver-google#21-rest-api

profile
𝐃𝐨𝐧'𝐭 𝐛𝐞 𝐚 𝐩𝐫𝐨𝐜𝐫𝐚𝐬𝐭𝐢𝐧𝐚𝐭𝐨𝐫💫

0개의 댓글