2024-11-06T18:53:18.641+09:00 DEBUG 1 --- [nio-8080-exec-2] o.s.web.client.RestTemplate : HTTP POST https://kauth.kakao.com/oauth/token
2024-11-06T18:53:18.642+09:00 DEBUG 1 --- [nio-8080-exec-2] o.s.web.client.RestTemplate : Accept=[application/json, application/*+json]
2024-11-06T18:53:18.642+09:00 DEBUG 1 --- [nio-8080-exec-2] o.s.web.client.RestTemplate : Writing [{grant_type=[authorization_code], code=[nGrEGzz-UWfaGdR0y-h0CXlOTeRrVHZLNhZbLK8P_uN4W6ooB3r92QAAAAQKKw0fAAABkwDkjRW2xj-RG-1vuA], redirect_uri=[https://k1ec344612739a.user-app.krampoline.
com/api/login/oauth2/code/kakao], client_id=[0e2d82ca1274d3c102b162df9ef18a8f], client_secret=[ejUps9a8s1ombRsCeM2XkFuxNuO8LJrn, ejUps9a8s1ombRsCeM2XkFuxNuO8LJrn]}] as "application/x-www-form-urlencoded;charset=UTF-8"
2024-11-06T18:53:18.642+09:00 DEBUG 1 --- [nio-8080-exec-2] c.g.d.c.f.LoggingRequestInterceptor : ===== Request Begin =====
2024-11-06T18:53:18.642+09:00 DEBUG 1 --- [nio-8080-exec-2] c.g.d.c.f.LoggingRequestInterceptor : URI : https://kauth.kakao.com/oauth/token
2024-11-06T18:53:18.643+09:00 DEBUG 1 --- [nio-8080-exec-2] c.g.d.c.f.LoggingRequestInterceptor : Method : POST
2024-11-06T18:53:18.643+09:00 DEBUG 1 --- [nio-8080-exec-2] c.g.d.c.f.LoggingRequestInterceptor : Headers : [Accept:"application/json;charset=UTF-8", Content-Type:"application/x-www-form-urlencoded;charset=UTF-8", Content-Length:"362"]
2024-11-06T18:53:18.643+09:00 DEBUG 1 --- [nio-8080-exec-2] c.g.d.c.f.LoggingRequestInterceptor : Request body: grant_type=authorization_code&code=nGrEGzz-UWfaGdR0y-h0CXlOTeRrVHZLNhZbLK8P_uN4W6ooB3r92QAAAAQKKw0fAAABkwDkjRW2xj-RG-1vuA&redirect_uri=https%3A%2F%2Fk1ec344612739a.user-app.krampoli
ne.com%2Fapi%2Flogin%2Foauth2%2Fcode%2Fkakao&client_id=0e2d82ca1274d3c102b162df9ef18a8f&client_secret=ejUps9a8s1ombRsCeM2XkFuxNuO8LJrn&client_secret=ejUps9a8s1ombRsCeM2XkFuxNuO8LJrn
2024-11-06T18:53:18.643+09:00 DEBUG 1 --- [nio-8080-exec-2] c.g.d.c.f.LoggingRequestInterceptor : ===== Request End =====
2024-11-06T18:53:18.694+09:00 DEBUG 1 --- [nio-8080-exec-2] c.g.d.c.f.LoggingRequestInterceptor : ===== Response Begin =====
2024-11-06T18:53:18.695+09:00 DEBUG 1 --- [nio-8080-exec-2] c.g.d.c.f.LoggingRequestInterceptor : Status code : 200 OK
2024-11-06T18:53:18.695+09:00 DEBUG 1 --- [nio-8080-exec-2] c.g.d.c.f.LoggingRequestInterceptor : Status text : OK
2024-11-06T18:53:18.696+09:00 DEBUG 1 --- [nio-8080-exec-2] c.g.d.c.f.LoggingRequestInterceptor : Headers : [Date:"Wed, 06 Nov 2024 09:53:18 GMT", Content-Type:"application/json;charset=utf-8", Transfer-Encoding:"chunked", Connection:"keep-alive", Cache-Control:"no-cache, no-store, max-a
ge=0, must-revalidate", Pragma:"no-cache", Expires:"0", X-XSS-Protection:"1; mode=block", X-Frame-Options:"DENY", X-Content-Type-Options:"nosniff", Kakao:"Talk", Access-Control-Allow-Origin:"*", Access-Control-Allow-Methods:"GET, POST, OPTIONS", Access-Control-Allow-Headers:"Authorization, KA, Ori
gin, X-Requested-With, Content-Type, Accept"]
2024-11-06T18:53:18.696+09:00 DEBUG 1 --- [nio-8080-exec-2] c.g.d.c.f.LoggingRequestInterceptor : Response body: {"access_token":"ktG6F_T9oUC_SlOlwg8DrJl9ZgyFVtxfAAAAAQo9c5sAAAGTAOSNX9Q0RDl69jWm","token_type":"bearer","refresh_token":"I5rtimzdr2cqmBhaEGso5VMR-zc-IQUPAAAAAgo9c5sAAAGTAOSNW9Q0RD
l69jWm","expires_in":21599,"scope":"account_email profile_image profile_nickname","refresh_token_expires_in":5183999}
2024-11-06T18:53:18.696+09:00 DEBUG 1 --- [nio-8080-exec-2] c.g.d.c.f.LoggingRequestInterceptor : ===== Response End =====
2024-11-06T18:53:18.697+09:00 DEBUG 1 --- [nio-8080-exec-2] o.s.web.client.RestTemplate : Response 200 OK
2024-11-06T18:53:18.697+09:00 DEBUG 1 --- [nio-8080-exec-2] o.s.web.client.RestTemplate : Reading to [java.util.Map<java.lang.String, java.lang.Object>]
2024-11-06T18:53:18.704+09:00 DEBUG 1 --- [nio-8080-exec-2] o.s.web.client.RestTemplate : HTTP GET https://kapi.kakao.com/v2/user/me
2024-11-06T18:53:18.705+09:00 DEBUG 1 --- [nio-8080-exec-2] o.s.web.client.RestTemplate : Accept=[application/json, application/*+json]
2024-11-06T18:53:18.706+09:00 DEBUG 1 --- [nio-8080-exec-2] c.g.d.c.f.LoggingRequestInterceptor : ===== Request Begin =====
2024-11-06T18:53:18.706+09:00 DEBUG 1 --- [nio-8080-exec-2] c.g.d.c.f.LoggingRequestInterceptor : URI : https://kapi.kakao.com/v2/user/me
2024-11-06T18:53:18.706+09:00 DEBUG 1 --- [nio-8080-exec-2] c.g.d.c.f.LoggingRequestInterceptor : Method : GET
2024-11-06T18:53:18.706+09:00 DEBUG 1 --- [nio-8080-exec-2] c.g.d.c.f.LoggingRequestInterceptor : Headers : [Accept:"application/json", Authorization:"Bearer ktG6F_T9oUC_SlOlwg8DrJl9ZgyFVtxfAAAAAQo9c5sAAAGTAOSNX9Q0RDl69jWm", Content-Length:"0"]
2024-11-06T18:53:18.707+09:00 DEBUG 1 --- [nio-8080-exec-2] c.g.d.c.f.LoggingRequestInterceptor : Request body:
2024-11-06T18:53:18.707+09:00 DEBUG 1 --- [nio-8080-exec-2] c.g.d.c.f.LoggingRequestInterceptor : ===== Request End =====
2024-11-06T18:53:18.712+09:00 ERROR 1 --- [nio-8080-exec-2] c.g.d.d.u.oauth2.CustomFailureHandler : Social login failure - Request URI: /api/login/oauth2/code/kakao, User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/1
5E148 Safari/604.1, Error: [invalid_user_info_response] An error occurred while attempting to retrieve the UserInfo Resource: I/O error on GET request for "https://kapi.kakao.com/v2/user/me": Unable to tunnel through proxy. Proxy returns "HTTP/1.1 503 Service Unavailable"
2024-11-06T18:53:18.712+09:00 ERROR 1 --- [nio-8080-exec-2] c.g.d.d.u.oauth2.CustomFailureHandler : Root cause: I/O error on GET request for "https://kapi.kakao.com/v2/user/me": Unable to tunnel through proxy. Proxy returns "HTTP/1.1 503 Service Unavailable"
자꾸 사용자 정보 api 호출때 에러가 뜨네요. 혹시 이유를 알 수 있을까요
@Configuration
public class OAuth2Config {
@Bean
public RestTemplate oAuthRestTemplate() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("krmp-proxy.9rum.cc", 3128));
requestFactory.setProxy(proxy);
RestTemplate restTemplate = new RestTemplate(requestFactory);
// 로깅 인터셉터 추가
restTemplate.getInterceptors().add(new LoggingRequestInterceptor());
return restTemplate;
}
// Spring Security OAuth2 클라이언트가 액세스 토큰을 요청할 때 프록시 설정 등 커스텀 RestTemplate 설정을 적용
@Bean
public OAuth2AccessTokenResponseClient<OAuth2AuthorizationCodeGrantRequest> oAuth2AccessTokenResponseClient(
RestTemplate oAuthRestTemplate) {
return new CustomAuthorizationCodeTokenResponseClient(oAuthRestTemplate);
}
}
@Service
@Slf4j
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class CustomOAuth2UserService extends DefaultOAuth2UserService {
private final UserRepository userRepository;
private final RestTemplate oAuthRestTemplate;
@PostConstruct
public void init() {
this.setRestOperations(oAuthRestTemplate);
}
@Transactional
@Override
public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException {
OAuth2User oAuth2User = super.loadUser(userRequest);
String registrationId = userRequest.getClientRegistration().getRegistrationId();
if (registrationId == null) {
throw new OAuth2AuthenticationException("유효하지않는 OAuth2 제공자입니다.");
}
OAuth2Response oAuth2Response = new KaKaoResponse(oAuth2User.getAttributes());
User user = findOrCreateMember(oAuth2Response, registrationId);
return new CustomUserDetails(user, oAuth2User.getAttributes());
}
public class CustomAuthorizationCodeTokenResponseClient implements
OAuth2AccessTokenResponseClient<OAuth2AuthorizationCodeGrantRequest> {
private RestOperations restOperations;
private Converter<OAuth2AuthorizationCodeGrantRequest, RequestEntity<?>> requestEntityConverter = new CustomAuthorizationCodeGrantRequestEntityConverter();
public CustomAuthorizationCodeTokenResponseClient(RestOperations restOperations) {
this.restOperations = restOperations;
}
@Override
public OAuth2AccessTokenResponse getTokenResponse(OAuth2AuthorizationCodeGrantRequest authorizationGrantRequest) {
Assert.notNull(authorizationGrantRequest, "authorizationGrantRequest cannot be null");
// 올바른 컨버터 사용
RequestEntity<?> request = requestEntityConverter.convert(authorizationGrantRequest);
ResponseEntity<Map<String, Object>> response = restOperations.exchange(
request, new ParameterizedTypeReference<Map<String, Object>>() {
});
Map<String, Object> tokenResponseParameters = response.getBody();
return this.convertToOAuth2AccessTokenResponse(tokenResponseParameters);
}
.oauth2Login(oauth2 -> oauth2
.tokenEndpoint(tokenEndpointConfig -> tokenEndpointConfig
.accessTokenResponseClient(oAuth2AccessTokenResponseClient)
)
.userInfoEndpoint(userInfoEndpointConfig -> userInfoEndpointConfig
.userService(customOAuth2UserService)
)
.authorizationEndpoint(authorization -> authorization
.authorizationRequestRepository(httpCookieOAuth2AuthorizationRequestRepository)
)
.successHandler(customSuccessHandler)
.failureHandler(customFailureHandler)
)