springboot google oauth2 관련 설정

sangeun jo·2022년 6월 18일
0

사내결재사이트

목록 보기
1/7

I. 클라이언트 ID 설정

승인된 리다이렉션 URI
http://localhost:8080/login/oauth2/code/google
스프링부트에서는 반드시 이 주소로 적어야 한다.

  • 종종 http://localhost:8080/authorize/oauth2/code/google로 리다이렉션 되는 경우가 있어서 이 주소도 추가했다.

II. scope 설정

  1. 구글 oauth2 용 설정파일 생성
    resources/application-oauth.properties
spring.security.oauth2.client.registration.google.client-id=829901496470-54rufes6a8ur76os805ptftkgh2fb816.apps.googleusercontent.com
spring.security.oauth2.client.registration.google.client-secret=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
spring.security.oauth2.client.registration.google.scope=profile,email
  1. 설정 파일 적용
    resources/application.properties
spring.profiles.include=oauth

여기까지만 나와있는 예제들이 많다.
구글 드라이브나 구글 시트 권한 추가하는 법

scope=profile,email, https://www.googleapis.com/auth/drive, https://www.googleapis.com/auth/spreadsheets

그냥 여기에서 원하는 스콥 찾아서 주소 전부 다 적으면 된다.

https://www.googleapis.com/auth/userinfo.email은email만 적으니까
https://www.googleapis.com/auth/drive는 drive만 적으면 되는 줄 알았는데 아니었다.

III. 로그인 할 때마다 매번 리프레시토큰 받아오기

resources/application.properties

spring.security.oauth2.client.provider.google.authorization-uri=https://accounts.google.com/o/oauth2/v2/auth?prompt=consent&access_type=offline
profile
코더가 아니라 개발자가 되자

0개의 댓글