Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAuth : JWT 적용 및 Apple 로그인 구현 등 #48

Merged
merged 11 commits into from
Aug 14, 2023
Merged

Conversation

yooniversal
Copy link
Contributor

@yooniversal yooniversal commented Aug 14, 2023

OAuth

Apple 로그인 구현

Fittering 서비스에서 apple 로그인 기능을 이용할 수 있도록 구현했습니다.
apple은 기존에 구현한 google, kakao OAuth에서 사용하는 방식이나 응답 폼이 달라서 추가로 서비스 로직 및 클래스를 정의했습니다.
테스트까지 완료했습니다.

CORS 필터 설정

기존 CORS 설정으로는 소셜 로그인을 할 때 CORS 정책을 통과하지 못하는 문제가 있었습니다.
CORS 필터 CorsFilter를 가장 높은 우선순위로 설정 후 정의해주면서 해결할 수 있었습니다.

OAuth에 JWT 적용

기존 google, kakao 소셜 로그인은 세션으로 동작했지만 지금은 인증/인가를 JWT로 처리하도록 변경했기 때문에
각 개발 공식 문서를 참고해 API 함수 내부적으로 RestTemplate을 활용해 한 번 더 호출하면서 id_token를 응답으로 받아
사용자가 입력한 email을 추출해 직접 JWT를 생성하고 쿼리 스트링과 함께 /login으로 redirect 하도록 설정했습니다.
google, kakao, apple 서버에서 발급해주는 JWT를 사용하지 않고, 서버에서 직접 생성한 JWT를 사용합니다.
테스트까지 완료했습니다.

//카카오 소셜 로그인 API 예시
@GetMapping("/login/kakao")
public String kakaoServiceRedirect(@RequestParam String code) {
    URI uri = UriComponentsBuilder.fromUriString(KAKAO_TOKEN_URL)
            .build()
            .toUri();

    MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
    params.add("grant_type", KAKAO_GRANT_TYPE);
    params.add("client_id", KAKAO_CLIENT_ID);
    params.add("client_secret", KAKAO_CLIENT_SECRET);
    params.add("redirect_uri", KAKAO_REDIRECT_URI);
    params.add("code", code);
    KakaoServiceResponse response = restTemplate.postForObject(uri, params, KakaoServiceResponse.class); //API 호출
    ...
    return "redirect:" + MAIN_LOGIN_URL
                + "?token=" + jwtTokenProvider.createToken(user.getEmail(), user.getRoles());
}

References

@yooniversal yooniversal added 📬 API 서버 API 수정 ✅ Test Test whether it works as expected ✨ Feature 기능 개발 및 개선 labels Aug 14, 2023
@yooniversal yooniversal linked an issue Aug 14, 2023 that may be closed by this pull request
@yooniversal yooniversal removed the ✅ Test Test whether it works as expected label Aug 14, 2023
@yooniversal yooniversal merged commit 28d087c into main Aug 14, 2023
1 check passed
@yooniversal yooniversal deleted the 28-oauth2-apple branch August 14, 2023 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📬 API 서버 API 수정 ✨ Feature 기능 개발 및 개선
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OAuth2 추가 구현 및 설정
1 participant