Closed jkde7721 closed 3 months ago
네 확인했습니다!!
- 세진님께 계정 전달 받아서 테스트 한 후 연락 드리겠습니다.
- 이름 저장하는 타이밍이 애매하면 애플 회원가입 후 이름 입력받는 창을 넣는건 어떨까요?? (번거로울 것 같기도 합니다..)
- 여쭤보려고 하긴 했는데 약 리뷰탭 response dto에서 user_privacy 테이블에 있는 agerange랑 gender를 가져와서 내려주긴 해야 하거든요 / userservice쪽에는 userprivacy쪽 데이터를 가져오는 메소드가 없어서요..! 혹시 수정해주실 수 있나요? 아니면 직접 엔티티에서 getter 사용해서 가져오면 되는걸까요??
아 일단 포에이 서비스에 필요한 user_profile의 nickname 정보는 소셜 회원가입 후 직접 입력받긴 하는데(화면이 없네요... 일단 이거는 제가 디자인에 요청드릴께요), name(실명? 근데 일반 회원가입 시에도 정말 실제 이름인지 외부 api 호출하여 검증하는 로직은 없음) 정보가 정말 필요하다면 동일하게 진행하면 될 것 같습니다. (일단 제가 구현한 쪽은 user_privacy의 name 정보 사용하지 않습니다.)
그리고 아시겠지만 user_privacy의 age_range 타입은 문자열로 소셜 로그인 시 응답으로 내려온 값 그대로 가져다 저장해서 제멋대로? 생기기도 했고(없애도 될 것 같아요😂), 시간이 지남에 따라 10대 -> 20대가 될 수 있잖아요. 그래서 제 생각엔 birth 정보 가져다가 자바단에서 나이대 직접 계산하는 로직 필요할 것 같습니다. (UserPrivacy 엔티티 내부에 생성)
성별이랑 나이대 정보는 리뷰 작성자 ID로 UserPrivacy 엔티티 조회해서 getGender, calculateAgeRange 메소드 호출하면 되지 않을까 해요
💻 구현 내용
애플 로그인 구현
{host}/oauth2/authorization/apple
요청 시OAuth2LoginAuthenticationFilter
로 발급된 Auth Code와 함께 redirectOAuth2AuthorizationCodeAuthenticationProvider
에서 (유저 정보를 조회하기 위해) AT, RT 발급 API 호출위해OAuth2AccessTokenResponseClient
의 구현체인DefaultAuthorizationCodeTokenResponseClient
의존DefaultAuthorizationCodeTokenResponseClient
는 이전에 발급 받은 Auth Code와 application-oauth2.yml에 설정된 정보를 가지고 AT, RT 요청 위한RequestEntity
객체를 생성하기 위해Converter
(Converter<OAuth2AuthorizationCodeGrantRequest, RequestEntity<?>>
구현체)를 다시 의존⁉️ 네이버, 카카오, 구글의 경우
client-secret
값이 고정되어 있기 때문에 application-oauth2.yml에 설정된 값을 읽어와 적절한RequestEntity
객체를 스프링이 알아서 생성해주어 별도 설정 필요 없음(기본적으로ClientAuthenticationMethodValidatingRequestEntityConverter
객체 의존), but 애플의 경우team-id
,key-id
,client-id
등의 값을 가지고 JWT 형식의client-secret
을 직접 생성 후 요청해야 함 → 커스텀Converter
정의(SecurityConfig
내에서accessTokenResponseClient
빈 등록한 부분 참고)OAuth2UserServiceImpl
클래스의loadUser
메소드 호출 → 애플은 별도의 유저 정보 조회해오는 API 존재하지 않음⁉️ JWT 형식의 Id Token을 디코딩하여 payload의 유저 정보를 가져와야함 + 애플은 이 Id Token의 유효성을 검증할 것을 권장하는데 이 JWT 토큰을 검증하기 위해서는 키가 필요함 → 이 키를 조회해 오는 API가 또 따로 있음
디코딩된 Id Token Payload 예시
네이버, 카카오, 구글, 애플 별로 유저 정보 조회해오는 방식이 다 다름
DefaultOAuth2UserService
로 유저의 필요한 모든 정보 조회 가능 →NaverOAuth2UserAttributesServiceImpl
,KakaoOAuth2UserAttributesServiceImpl
객체 내에서 별도의 동작XDefaultOAuth2UserService
로 유저의 일부 정보 조회 가능(이름, 이메일 등) → 추가 정보(생년월일, 성별 등) 얻기 위해GoogleOAuth2UserAttributesServiceImpl
에서 별도의 People API 호출AppleOAuth2UserAttributesServiceImpl
에서 id 토큰 검증 후 토큰 디코딩하여 유저 정보 조회🛠️ 개발 오류 사항
OAuth2LoginAuthenticationFilter
로 redirect될 때) 이름 정보를 전달해줍니다. Spring OAuth2를 이용해 구현하려다 보니 유저 이름 정보 저장 타이밍이 애매해 애플 로그인 시에는user_privacy
테이블의name
컬럼에 빈 문자열이 들어갑니다. 일단 현재 서비스 로직상user_privacy
테이블 데이터를 사용할 일은 없어 애플 로그인 사용자의 이름을 저장하는 로직은 구현하지 않았습니다. 좋은 아이디어 있다면 알려주세요.🗣️ For 리뷰어
애플 로그인 테스트 방법
환경 변수가 많이 추가되었습니다. 노션 확인해주세요.
AuthKey_*.p8
키 파일이 필요합니다. 이것도 노션에 있고 gitignore에 파일 경로 추가해두었습니다. 꼭 지정한 경로에 파일 위치시켜 주시고, 절대!!! git에 올라가지 않도록 주의해주세요.애플의 경우 redirect uri 설정 시 localhost 및 http 프로토콜을 지정할 수 없습니다. 따라서 ngrok 이라는 툴을 이용해 https 프로토콜로 외부 호스팅?을 해주어야 하는데 다음 글 참고하여 설정해주세요. (별로 어렵지 않아요!)
Apple Developer Redirect URL 설정 방법
1234-123-123-123-123.ngrok-free.app
) + Return URLs(https://1234-123-123-123-123.ngrok-free.app/login/oauth2/code/apple
) 같은 형태로 추가 > Done > Continue > Save (복잡하면 그냥 저한테 ngrok URL 전달해주세요 제가 설정할께요)https://1234-123-123-123-123.ngrok-free.app/oauth2/authorization/apple
형태로 애플 로그인 요청 → ForA 앱의 JWT 토큰 발급소셜 로그인 모두 구현 완료되었습니다! 제 로컬에서 모두 테스트해보긴 했는데 네이버, 카카오, 구글, 애플 모두 정상적으로 로그인 및 회원가입 되는지 한번 확인해주세요.
참고
close #35