diff --git a/src/main/java/net/snowflake/client/core/auth/oauth/AuthorizationCodeFlowAccessTokenProvider.java b/src/main/java/net/snowflake/client/core/auth/oauth/AuthorizationCodeFlowAccessTokenProvider.java index df2fc4780..5e763d882 100644 --- a/src/main/java/net/snowflake/client/core/auth/oauth/AuthorizationCodeFlowAccessTokenProvider.java +++ b/src/main/java/net/snowflake/client/core/auth/oauth/AuthorizationCodeFlowAccessTokenProvider.java @@ -72,6 +72,7 @@ public String getAccessToken(SFLoginInput loginInput) throws SFException { AuthorizationCode authorizationCode = requestAuthorizationCode(loginInput, pkceVerifier); return exchangeAuthorizationCodeForAccessToken(loginInput, authorizationCode, pkceVerifier); } catch (Exception e) { + logger.debug("Error during OAuth authorization code flow: " + e.getMessage()); throw new RuntimeException(e); } } @@ -80,9 +81,10 @@ private AuthorizationCode requestAuthorizationCode( SFLoginInput loginInput, CodeVerifier pkceVerifier) throws SFException, IOException { AuthorizationRequest request = buildAuthorizationRequest(loginInput, pkceVerifier); URI authorizeRequestURI = request.toURI(); + logger.debug("Executing authorization code request to: " + authorizeRequestURI.getAuthority() + authorizeRequestURI.getPath()); HttpServer httpServer = createHttpServer(loginInput); CompletableFuture codeFuture = setupRedirectURIServerForAuthorizationCode(httpServer); - logger.debug("Waiting for authorization code on " + buildRedirectUri(loginInput) + "..."); + logger.debug("Waiting for authorization code redirection to " + buildRedirectUri(loginInput) + "..."); return letUserAuthorize(authorizeRequestURI, codeFuture, httpServer); } @@ -90,6 +92,8 @@ private String exchangeAuthorizationCodeForAccessToken( SFLoginInput loginInput, AuthorizationCode authorizationCode, CodeVerifier pkceVerifier) { try { TokenRequest request = buildTokenRequest(loginInput, authorizationCode, pkceVerifier); + URI requestUri = request.getEndpointURI(); + logger.debug("Requesting access token from: " + requestUri.getAuthority() + requestUri.getPath()); String tokenResponse = HttpUtil.executeGeneralRequest( convertToBaseRequest(request.toHTTPRequest()), @@ -100,6 +104,7 @@ private String exchangeAuthorizationCodeForAccessToken( loginInput.getHttpClientSettingsKey()); TokenResponseDTO tokenResponseDTO = objectMapper.readValue(tokenResponse, TokenResponseDTO.class); + logger.debug("Received OAuth access token from: " + requestUri.getAuthority() + requestUri.getPath()); return tokenResponseDTO.getAccessToken(); } catch (Exception e) { throw new RuntimeException(e); @@ -130,8 +135,6 @@ private static CompletableFuture setupRedirectURIServerForAuthorizationC httpServer.createContext( REDIRECT_URI_ENDPOINT, exchange -> { - exchange.sendResponseHeaders(200, 0); - exchange.getResponseBody().close(); Map urlParams = URLEncodedUtils.parse(exchange.getRequestURI(), StandardCharsets.UTF_8).stream() .collect(Collectors.toMap(NameValuePair::getName, NameValuePair::getValue));