Skip to content

Commit

Permalink
Merge pull request #290 from team9502/dev
Browse files Browse the repository at this point in the history
fix: 구글 로그인 오류 메시지를 더 자세히 출력하여 문제를 진단 [배포]
  • Loading branch information
EUNCHAEv1006 authored Jul 2, 2024
2 parents 324923c + bef2ec7 commit 8988bf8
Showing 1 changed file with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,37 +98,39 @@ private String getEmailFromCode(String code) {
}

private String getAccessToken(String code) {
try {
restTemplate.setMessageConverters(Arrays.asList(new FormHttpMessageConverter(), new StringHttpMessageConverter(StandardCharsets.UTF_8)));
restTemplate.setMessageConverters(Arrays.asList(new FormHttpMessageConverter(), new StringHttpMessageConverter(StandardCharsets.UTF_8)));

String accessTokenUrl = "https://oauth2.googleapis.com/token";
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
String accessTokenUrl = "https://oauth2.googleapis.com/token";
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("code", code);
params.add("client_id", clientId);
params.add("client_secret", clientSecret);
params.add("redirect_uri", redirectUri);
params.add("grant_type", "authorization_code");
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("code", code);
params.add("client_id", clientId);
params.add("client_secret", clientSecret);
params.add("redirect_uri", redirectUri); // 리디렉션 URI 확인
params.add("grant_type", "authorization_code");

HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(params, headers);
ResponseEntity<String> response = restTemplate.postForEntity(accessTokenUrl, request, String.class);
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(params, headers);
ResponseEntity<String> response = restTemplate.postForEntity(accessTokenUrl, request, String.class);

if (response.getStatusCode() == HttpStatus.OK) {
if (response.getStatusCode() == HttpStatus.OK) {
try {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(response.getBody());
return jsonNode.get("access_token").asText();
} else {
System.out.println("Error Response: " + response.getBody());
throw new RuntimeException("액세스 토큰 요청 실패");
} catch (Exception e) {
throw new RuntimeException("액세스 토큰 추출 실패", e);
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("액세스 토큰 추출 실패: " + e.getMessage(), e);
} else {
System.out.println("Response Status: " + response.getStatusCode());
System.out.println("Response Body: " + response.getBody());
System.out.println("redirectUri: " + redirectUri);
throw new RuntimeException("액세스 토큰 요청 실패: " + response.getBody());
}
}


private User createUser(SocialLoginRequestDTO requestDTO, SocialType socialType, String email) {
User newUser = User.builder()
.email(email)
Expand Down

0 comments on commit 8988bf8

Please sign in to comment.