From ce1eab6d7a4221da6bbe882077e13a8558300dc8 Mon Sep 17 00:00:00 2001 From: Alec Huang Date: Thu, 21 Mar 2024 14:47:09 -0700 Subject: [PATCH] Fix refreshToken flow. --- .../snowflake/ingest/connection/OAuthClient.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/snowflake/ingest/connection/OAuthClient.java b/src/main/java/net/snowflake/ingest/connection/OAuthClient.java index 9f94912a5..bc2b64089 100644 --- a/src/main/java/net/snowflake/ingest/connection/OAuthClient.java +++ b/src/main/java/net/snowflake/ingest/connection/OAuthClient.java @@ -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()); } @@ -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; }