Skip to content

Commit

Permalink
Fix refreshToken flow.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-alhuang committed Mar 21, 2024
1 parent 18855bb commit ce1eab6
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/main/java/net/snowflake/ingest/connection/OAuthClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,14 @@ public void refreshToken() {
if (respBody.has(ACCESS_TOKEN) && respBody.has(EXPIRES_IN)) {
// Trim surrounding quotation marks
String newAccessToken = respBody.get(ACCESS_TOKEN).toString().replaceAll("^\"|\"$", "");

oAuthCredential.get().setAccessToken(newAccessToken);
oAuthCredential.get().setExpiresIn(respBody.get(EXPIRES_IN).getAsInt());
} else {
throw new SFException(
ErrorCode.OAUTH_REFRESH_TOKEN_ERROR,
"Refresh access token fail with response: " + respBodyString);
return;
}
}
throw new SFException(
ErrorCode.OAUTH_REFRESH_TOKEN_ERROR,
"Refresh access token fail with response: " + respBodyString);
} catch (IOException e) {
throw new SFException(ErrorCode.OAUTH_REFRESH_TOKEN_ERROR, e.getMessage());
}
Expand All @@ -115,10 +114,7 @@ private HttpUriRequest makeRefreshTokenRequest() {
payload.entrySet().stream()
.map(e -> e.getKey() + "=" + e.getValue())
.collect(Collectors.joining("&"));

final StringEntity entity =
new StringEntity(payloadString, ContentType.APPLICATION_FORM_URLENCODED);
post.setEntity(entity);
post.setEntity(new StringEntity(payloadString, ContentType.APPLICATION_FORM_URLENCODED));

return post;
}
Expand Down

0 comments on commit ce1eab6

Please sign in to comment.