Skip to content

Commit

Permalink
Add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dheyman committed Dec 4, 2024
1 parent dc55937 commit 857d8a2
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -80,16 +81,19 @@ 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<String> 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);
}

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()),
Expand All @@ -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);
Expand Down Expand Up @@ -130,8 +135,6 @@ private static CompletableFuture<String> setupRedirectURIServerForAuthorizationC
httpServer.createContext(
REDIRECT_URI_ENDPOINT,
exchange -> {
exchange.sendResponseHeaders(200, 0);
exchange.getResponseBody().close();
Map<String, String> urlParams =
URLEncodedUtils.parse(exchange.getRequestURI(), StandardCharsets.UTF_8).stream()
.collect(Collectors.toMap(NameValuePair::getName, NameValuePair::getValue));
Expand Down

0 comments on commit 857d8a2

Please sign in to comment.