From ae08a88acf58608b919a6f98e5d6ba168c7edabc Mon Sep 17 00:00:00 2001 From: Prince Datta Date: Mon, 20 Feb 2023 11:31:27 +0530 Subject: [PATCH 1/5] adding changes for the grant type client credentials mechanism --- .../source/common/BaseHttpSourceConfig.java | 42 +++++++++++++--- .../http/source/common/http/HttpClient.java | 12 +++-- .../http/source/common/http/OAuthUtil.java | 30 ++++++++++- widgets/HTTP-batchsource.json | 50 +++++++++++++++---- 4 files changed, 110 insertions(+), 24 deletions(-) diff --git a/src/main/java/io/cdap/plugin/http/source/common/BaseHttpSourceConfig.java b/src/main/java/io/cdap/plugin/http/source/common/BaseHttpSourceConfig.java index 2343d13..25d92d0 100644 --- a/src/main/java/io/cdap/plugin/http/source/common/BaseHttpSourceConfig.java +++ b/src/main/java/io/cdap/plugin/http/source/common/BaseHttpSourceConfig.java @@ -118,6 +118,7 @@ public abstract class BaseHttpSourceConfig extends ReferencePluginConfig { public static final String PAGINATION_INDEX_PLACEHOLDER_REGEX = "\\{pagination.index\\}"; public static final String PAGINATION_INDEX_PLACEHOLDER = "{pagination.index}"; + public static final String PROPERTY_GRANT_TYPE = "grantType"; @Name(PROPERTY_URL) @Description("Url to fetch to the first page. The url must start with a protocol (e.g. http://).") @@ -442,6 +443,11 @@ public abstract class BaseHttpSourceConfig extends ReferencePluginConfig { @Description("Output schema. Is required to be set.") protected String schema; + @Nullable + @Name(PROPERTY_GRANT_TYPE) + @Description("Value of grant type to determine the OAuth mechanism") + protected String grantType; + protected BaseHttpSourceConfig(String referenceName) { super(referenceName); } @@ -719,6 +725,10 @@ public Schema getSchema() { schema, e, PROPERTY_SCHEMA); } } + @Nullable + public String getGrantType() { + return grantType; + } @Nullable public Map getHeadersMap() { @@ -798,7 +808,6 @@ public void validate(FailureCollector failureCollector) { String.format("URL value is not valid: '%s'", getUrl()), e, PROPERTY_URL); } } - // Validate Linear Retry Interval if (!containsMacro(PROPERTY_RETRY_POLICY) && getRetryPolicy() == RetryPolicy.LINEAR) { assertIsSet(getLinearRetryInterval(), PROPERTY_LINEAR_RETRY_INTERVAL, "retry policy is linear"); @@ -883,20 +892,22 @@ PAGINATION_INDEX_PLACEHOLDER, getPaginationType()), // Validate OAuth2 properties if (!containsMacro(PROPERTY_OAUTH2_ENABLED) && this.getOauth2Enabled()) { String reasonOauth2 = "OAuth2 is enabled"; - assertIsSet(getAuthUrl(), PROPERTY_AUTH_URL, reasonOauth2); assertIsSet(getTokenUrl(), PROPERTY_TOKEN_URL, reasonOauth2); assertIsSet(getClientId(), PROPERTY_CLIENT_ID, reasonOauth2); assertIsSet(getClientSecret(), PROPERTY_CLIENT_SECRET, reasonOauth2); - assertIsSet(getRefreshToken(), PROPERTY_REFRESH_TOKEN, reasonOauth2); + assertIsSet(getGrantType(), PROPERTY_GRANT_TYPE, reasonOauth2); + + // refresh token validate + if (refreshTokenGrantType()) { + assertIsSet(getAuthUrl(), PROPERTY_AUTH_URL, reasonOauth2); + assertIsSet(getRefreshToken(), PROPERTY_REFRESH_TOKEN, reasonOauth2); + } } // Validate Authentication properties AuthType authType = getAuthType(); switch (authType) { case OAUTH2: String reasonOauth2 = "OAuth2 is enabled"; - if (!containsMacro(PROPERTY_AUTH_URL)) { - assertIsSet(getAuthUrl(), PROPERTY_AUTH_URL, reasonOauth2); - } if (!containsMacro(PROPERTY_TOKEN_URL)) { assertIsSet(getTokenUrl(), PROPERTY_TOKEN_URL, reasonOauth2); } @@ -906,8 +917,16 @@ PAGINATION_INDEX_PLACEHOLDER, getPaginationType()), if (!containsMacro((PROPERTY_CLIENT_SECRET))) { assertIsSet(getClientSecret(), PROPERTY_CLIENT_SECRET, reasonOauth2); } - if (!containsMacro(PROPERTY_REFRESH_TOKEN)) { - assertIsSet(getRefreshToken(), PROPERTY_REFRESH_TOKEN, reasonOauth2); + if (!containsMacro(PROPERTY_GRANT_TYPE)) { + assertIsSet(getGrantType(), PROPERTY_GRANT_TYPE, reasonOauth2); + if (refreshTokenGrantType()) { + if (!containsMacro(PROPERTY_REFRESH_TOKEN)) { + assertIsSet(getRefreshToken(), PROPERTY_REFRESH_TOKEN, reasonOauth2); + } + if (!containsMacro(PROPERTY_AUTH_URL)) { + assertIsSet(getAuthUrl(), PROPERTY_AUTH_URL, reasonOauth2); + } + } } break; case SERVICE_ACCOUNT: @@ -941,6 +960,13 @@ PAGINATION_INDEX_PLACEHOLDER, getPaginationType()), } } + private boolean refreshTokenGrantType() { + if (getGrantType() == "refresh_token") { + return true; + } + return false; + } + private boolean validateServiceAccount(FailureCollector collector) { if (containsMacro(PROPERTY_NAME_SERVICE_ACCOUNT_FILE_PATH) || containsMacro(PROPERTY_NAME_SERVICE_ACCOUNT_JSON)) { return false; diff --git a/src/main/java/io/cdap/plugin/http/source/common/http/HttpClient.java b/src/main/java/io/cdap/plugin/http/source/common/http/HttpClient.java index 29b5a3e..6c7a8b9 100644 --- a/src/main/java/io/cdap/plugin/http/source/common/http/HttpClient.java +++ b/src/main/java/io/cdap/plugin/http/source/common/http/HttpClient.java @@ -136,9 +136,15 @@ private CloseableHttpClient createHttpClient() throws IOException { switch (authType) { case OAUTH2: - String accessToken = OAuthUtil.getAccessTokenByRefreshToken(HttpClients.createDefault(), config.getTokenUrl(), - config.getClientId(), config.getClientSecret(), - config.getRefreshToken()); + String accessToken; + if (config.getGrantType() == "refresh_token") { + accessToken = OAuthUtil.getAccessTokenByRefreshToken(HttpClients.createDefault(), config.getTokenUrl(), + config.getClientId(), config.getClientSecret(), + config.getRefreshToken(), config.getGrantType()); + } else { + accessToken = OAuthUtil.getAccessTokenByClientCredentials(HttpClients.createDefault(), config.getTokenUrl(), + config.getClientId(), config.getClientSecret(), config.getGrantType()); + } clientHeaders.add(new BasicHeader("Authorization", "Bearer " + accessToken)); break; case SERVICE_ACCOUNT: diff --git a/src/main/java/io/cdap/plugin/http/source/common/http/OAuthUtil.java b/src/main/java/io/cdap/plugin/http/source/common/http/OAuthUtil.java index b898aa0..1243df4 100644 --- a/src/main/java/io/cdap/plugin/http/source/common/http/OAuthUtil.java +++ b/src/main/java/io/cdap/plugin/http/source/common/http/OAuthUtil.java @@ -25,6 +25,7 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.client.utils.URIBuilder; import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.message.BasicHeader; import org.apache.http.util.EntityUtils; import java.io.ByteArrayInputStream; @@ -34,13 +35,14 @@ import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; +import java.util.Base64; /** * A class which contains utilities to make OAuth2 specific calls. */ public class OAuthUtil { public static String getAccessTokenByRefreshToken(CloseableHttpClient httpclient, String tokenUrl, String clientId, - String clientSecret, String refreshToken) + String clientSecret, String refreshToken, String grantType) throws IOException { URI uri; @@ -49,7 +51,7 @@ public static String getAccessTokenByRefreshToken(CloseableHttpClient httpclient .setParameter("client_id", clientId) .setParameter("client_secret", clientSecret) .setParameter("refresh_token", refreshToken) - .setParameter("grant_type", "refresh_token") + .setParameter("grant_type", grantType) .build(); } catch (URISyntaxException e) { throw new IllegalArgumentException("Failed to build token URI for OAuth2", e); @@ -92,5 +94,29 @@ public static String getAccessTokenByServiceAccount(BaseHttpSourceConfig config) } return accessToken; } + + public static String getAccessTokenByClientCredentials(CloseableHttpClient httpclient, String tokenUrl, + String clientId, String clientSecret, String grantType) + throws IOException { + URI uri; + try { + uri = new URIBuilder(tokenUrl).setParameter("grant_type", grantType).build(); + } catch (URISyntaxException e) { + throw new IllegalArgumentException("Failed to build token URI for OAuth2", e); + } + + HttpPost httppost = new HttpPost(uri); + httppost.addHeader(new BasicHeader("Authorization", "Basic " + getBase64EncodeValue(clientId, clientSecret))); + httppost.addHeader(new BasicHeader("Content-Type", "application/json")); + CloseableHttpResponse response = httpclient.execute(httppost); + String responseString = EntityUtils.toString(response.getEntity(), "UTF-8"); + + JsonElement jsonElement = JSONUtil.toJsonObject(responseString).get("access_token"); + return jsonElement.getAsString(); + } + + private static String getBase64EncodeValue(String clientId, String clientSecret) { + return Base64.getEncoder().encodeToString((clientId + ":" + clientSecret).getBytes(StandardCharsets.UTF_8)); + } } diff --git a/widgets/HTTP-batchsource.json b/widgets/HTTP-batchsource.json index 1f142ae..b7525c8 100644 --- a/widgets/HTTP-batchsource.json +++ b/widgets/HTTP-batchsource.json @@ -132,6 +132,18 @@ ] } }, + { + "widget-type": "select", + "label": "Grant Type", + "name": "grantType", + "widget-attributes" : { + "values": [ + "refresh_token", + "client_credentials" + ], + "default" : "refresh_token" + } + }, { "widget-type": "textbox", "label": "Auth URL", @@ -684,27 +696,26 @@ }, "show": [ { - "name": "authUrl", - "type": "property" - }, - { - "name": "tokenUrl", - "type": "property" + "widget-type": "textbox", + "label": "Token URL", + "name": "tokenUrl" }, { - "name": "clientId", - "type": "property" + "widget-type": "textbox", + "label": "Client ID", + "name": "clientId" }, { - "name": "clientSecret", - "type": "property" + "widget-type": "password", + "label": "Client Secret", + "name": "clientSecret" }, { "name": "scopes", "type": "property" }, { - "name": "refreshToken", + "name": "grantType", "type": "property" } ] @@ -780,6 +791,23 @@ "type": "property" } ] + }, + { + "name": "Grant Type Refresh Token", + "condition": { + "expression": "grantType == 'refresh_token' && authType == 'oAuth2'" + }, + "show": [ + { + "widget-type": "textbox", + "label": "Auth URL", + "name": "authUrl" + }, + { + "name": "refreshToken", + "type": "property" + } + ] } ] } From 621737553affc74748be0ba188fceb3515d679d0 Mon Sep 17 00:00:00 2001 From: Prince Datta Date: Thu, 23 Feb 2023 12:51:08 +0530 Subject: [PATCH 2/5] added enum for GrantType and made changes in the conditions accordingly and also added variables for parameters values. --- .../source/common/BaseHttpSourceConfig.java | 16 +++-- .../http/source/common/http/GrantType.java | 59 +++++++++++++++++++ .../http/source/common/http/HttpClient.java | 6 +- .../http/source/common/http/OAuthUtil.java | 14 ++--- widgets/HTTP-batchsource.json | 20 +++---- 5 files changed, 88 insertions(+), 27 deletions(-) create mode 100644 src/main/java/io/cdap/plugin/http/source/common/http/GrantType.java diff --git a/src/main/java/io/cdap/plugin/http/source/common/BaseHttpSourceConfig.java b/src/main/java/io/cdap/plugin/http/source/common/BaseHttpSourceConfig.java index 25d92d0..857855c 100644 --- a/src/main/java/io/cdap/plugin/http/source/common/BaseHttpSourceConfig.java +++ b/src/main/java/io/cdap/plugin/http/source/common/BaseHttpSourceConfig.java @@ -28,10 +28,7 @@ import io.cdap.plugin.http.source.common.error.ErrorHandling; import io.cdap.plugin.http.source.common.error.HttpErrorHandlerEntity; import io.cdap.plugin.http.source.common.error.RetryableErrorHandling; -import io.cdap.plugin.http.source.common.http.AuthType; -import io.cdap.plugin.http.source.common.http.HttpClient; -import io.cdap.plugin.http.source.common.http.KeyStoreType; -import io.cdap.plugin.http.source.common.http.OAuthUtil; +import io.cdap.plugin.http.source.common.http.*; import io.cdap.plugin.http.source.common.pagination.PaginationIteratorFactory; import io.cdap.plugin.http.source.common.pagination.PaginationType; import io.cdap.plugin.http.source.common.pagination.page.PageFormat; @@ -119,6 +116,13 @@ public abstract class BaseHttpSourceConfig extends ReferencePluginConfig { public static final String PAGINATION_INDEX_PLACEHOLDER_REGEX = "\\{pagination.index\\}"; public static final String PAGINATION_INDEX_PLACEHOLDER = "{pagination.index}"; public static final String PROPERTY_GRANT_TYPE = "grantType"; + public static final String PROPERTY_GRANT_TYPE_LABEL = "Grant type"; + + public static final String PARAMETER_CLIENT_ID = "client_id"; + public static final String PARAMETER_CLIENT_SECRET = "client_secret"; + public static final String PARAMETER_REFRESH_TOKEN = "refresh_token"; + public static final String PARAMETER_GRANT_TYPE = "grant_type"; + public static final String PARAMETER_ACCESS_TOKEN = "access_token"; @Name(PROPERTY_URL) @Description("Url to fetch to the first page. The url must start with a protocol (e.g. http://).") @@ -961,8 +965,10 @@ PAGINATION_INDEX_PLACEHOLDER, getPaginationType()), } private boolean refreshTokenGrantType() { - if (getGrantType() == "refresh_token") { + if (getGrantType() == GrantType.REFRESH_TOKEN.getValue()) { return true; + } else if (getGrantType() == GrantType.CLIENT_CREDENTIALS.getValue()) { + return false; } return false; } diff --git a/src/main/java/io/cdap/plugin/http/source/common/http/GrantType.java b/src/main/java/io/cdap/plugin/http/source/common/http/GrantType.java new file mode 100644 index 0000000..e1afa57 --- /dev/null +++ b/src/main/java/io/cdap/plugin/http/source/common/http/GrantType.java @@ -0,0 +1,59 @@ +/* + * Copyright © 2022 Cask Data, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package io.cdap.plugin.http.source.common.http; + +import io.cdap.plugin.http.source.common.BaseHttpSourceConfig; +import io.cdap.plugin.http.source.common.exceptions.InvalidPropertyTypeException; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Enum for different grant type methods. + */ +public enum GrantType { + REFRESH_TOKEN("refresh_token"), + CLIENT_CREDENTIALS("client_credentials"); + + private final String value; + + GrantType(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + /** + * Returns the GrantType. + * + * @param value the value is string type. + * @return The GrantType + */ + public static GrantType fromValue(String value) { + return Arrays.stream(GrantType.values()).filter(grantType -> grantType.getValue().equals(value)) + .findAny().orElseThrow(() -> new InvalidPropertyTypeException(BaseHttpSourceConfig.PROPERTY_GRANT_TYPE_LABEL, + value, getAllowedValues())); + } + + public static List getAllowedValues() { + return Arrays.stream(GrantType.values()).map(v -> v.getValue()) + .collect(Collectors.toList()); + } +} diff --git a/src/main/java/io/cdap/plugin/http/source/common/http/HttpClient.java b/src/main/java/io/cdap/plugin/http/source/common/http/HttpClient.java index 6c7a8b9..7b380ed 100644 --- a/src/main/java/io/cdap/plugin/http/source/common/http/HttpClient.java +++ b/src/main/java/io/cdap/plugin/http/source/common/http/HttpClient.java @@ -136,12 +136,12 @@ private CloseableHttpClient createHttpClient() throws IOException { switch (authType) { case OAUTH2: - String accessToken; - if (config.getGrantType() == "refresh_token") { + String accessToken = null; + if (config.getGrantType() == GrantType.REFRESH_TOKEN.getValue()) { accessToken = OAuthUtil.getAccessTokenByRefreshToken(HttpClients.createDefault(), config.getTokenUrl(), config.getClientId(), config.getClientSecret(), config.getRefreshToken(), config.getGrantType()); - } else { + } else if (config.getGrantType() == GrantType.CLIENT_CREDENTIALS.getValue()) { accessToken = OAuthUtil.getAccessTokenByClientCredentials(HttpClients.createDefault(), config.getTokenUrl(), config.getClientId(), config.getClientSecret(), config.getGrantType()); } diff --git a/src/main/java/io/cdap/plugin/http/source/common/http/OAuthUtil.java b/src/main/java/io/cdap/plugin/http/source/common/http/OAuthUtil.java index 1243df4..a7a5207 100644 --- a/src/main/java/io/cdap/plugin/http/source/common/http/OAuthUtil.java +++ b/src/main/java/io/cdap/plugin/http/source/common/http/OAuthUtil.java @@ -48,10 +48,10 @@ public static String getAccessTokenByRefreshToken(CloseableHttpClient httpclient URI uri; try { uri = new URIBuilder(tokenUrl) - .setParameter("client_id", clientId) - .setParameter("client_secret", clientSecret) - .setParameter("refresh_token", refreshToken) - .setParameter("grant_type", grantType) + .setParameter(BaseHttpSourceConfig.PARAMETER_CLIENT_ID, clientId) + .setParameter(BaseHttpSourceConfig.PARAMETER_CLIENT_SECRET, clientSecret) + .setParameter(BaseHttpSourceConfig.PARAMETER_REFRESH_TOKEN, refreshToken) + .setParameter(BaseHttpSourceConfig.PARAMETER_GRANT_TYPE, grantType) .build(); } catch (URISyntaxException e) { throw new IllegalArgumentException("Failed to build token URI for OAuth2", e); @@ -61,7 +61,7 @@ public static String getAccessTokenByRefreshToken(CloseableHttpClient httpclient CloseableHttpResponse response = httpclient.execute(httppost); String responseString = EntityUtils.toString(response.getEntity(), "UTF-8"); - JsonElement jsonElement = JSONUtil.toJsonObject(responseString).get("access_token"); + JsonElement jsonElement = JSONUtil.toJsonObject(responseString).get(BaseHttpSourceConfig.PARAMETER_ACCESS_TOKEN); return jsonElement.getAsString(); } @@ -100,7 +100,7 @@ public static String getAccessTokenByClientCredentials(CloseableHttpClient httpc throws IOException { URI uri; try { - uri = new URIBuilder(tokenUrl).setParameter("grant_type", grantType).build(); + uri = new URIBuilder(tokenUrl).setParameter(BaseHttpSourceConfig.PARAMETER_GRANT_TYPE, grantType).build(); } catch (URISyntaxException e) { throw new IllegalArgumentException("Failed to build token URI for OAuth2", e); } @@ -111,7 +111,7 @@ public static String getAccessTokenByClientCredentials(CloseableHttpClient httpc CloseableHttpResponse response = httpclient.execute(httppost); String responseString = EntityUtils.toString(response.getEntity(), "UTF-8"); - JsonElement jsonElement = JSONUtil.toJsonObject(responseString).get("access_token"); + JsonElement jsonElement = JSONUtil.toJsonObject(responseString).get(BaseHttpSourceConfig.PARAMETER_ACCESS_TOKEN); return jsonElement.getAsString(); } diff --git a/widgets/HTTP-batchsource.json b/widgets/HTTP-batchsource.json index b7525c8..a55c428 100644 --- a/widgets/HTTP-batchsource.json +++ b/widgets/HTTP-batchsource.json @@ -696,19 +696,16 @@ }, "show": [ { - "widget-type": "textbox", - "label": "Token URL", - "name": "tokenUrl" + "name": "tokenUrl", + "type": "property" }, { - "widget-type": "textbox", - "label": "Client ID", - "name": "clientId" + "name": "clientId", + "type": "property" }, { - "widget-type": "password", - "label": "Client Secret", - "name": "clientSecret" + "name": "clientSecret", + "type": "property" }, { "name": "scopes", @@ -799,9 +796,8 @@ }, "show": [ { - "widget-type": "textbox", - "label": "Auth URL", - "name": "authUrl" + "name": "authUrl", + "type": "property" }, { "name": "refreshToken", From d9e26b9665d5e7be37278444162de51c80a17238 Mon Sep 17 00:00:00 2001 From: Prince Datta Date: Thu, 23 Feb 2023 13:14:38 +0530 Subject: [PATCH 3/5] changed the year to 2023 in the certificate and checking the validation for refresh token directly --- .../cdap/plugin/http/source/common/BaseHttpSourceConfig.java | 4 ++-- .../io/cdap/plugin/http/source/common/http/GrantType.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/cdap/plugin/http/source/common/BaseHttpSourceConfig.java b/src/main/java/io/cdap/plugin/http/source/common/BaseHttpSourceConfig.java index 857855c..feccde8 100644 --- a/src/main/java/io/cdap/plugin/http/source/common/BaseHttpSourceConfig.java +++ b/src/main/java/io/cdap/plugin/http/source/common/BaseHttpSourceConfig.java @@ -902,7 +902,7 @@ PAGINATION_INDEX_PLACEHOLDER, getPaginationType()), assertIsSet(getGrantType(), PROPERTY_GRANT_TYPE, reasonOauth2); // refresh token validate - if (refreshTokenGrantType()) { + if (getGrantType() == GrantType.REFRESH_TOKEN.getValue()) { assertIsSet(getAuthUrl(), PROPERTY_AUTH_URL, reasonOauth2); assertIsSet(getRefreshToken(), PROPERTY_REFRESH_TOKEN, reasonOauth2); } @@ -923,7 +923,7 @@ PAGINATION_INDEX_PLACEHOLDER, getPaginationType()), } if (!containsMacro(PROPERTY_GRANT_TYPE)) { assertIsSet(getGrantType(), PROPERTY_GRANT_TYPE, reasonOauth2); - if (refreshTokenGrantType()) { + if (getGrantType() == GrantType.REFRESH_TOKEN.getValue()) { if (!containsMacro(PROPERTY_REFRESH_TOKEN)) { assertIsSet(getRefreshToken(), PROPERTY_REFRESH_TOKEN, reasonOauth2); } diff --git a/src/main/java/io/cdap/plugin/http/source/common/http/GrantType.java b/src/main/java/io/cdap/plugin/http/source/common/http/GrantType.java index e1afa57..5173dcd 100644 --- a/src/main/java/io/cdap/plugin/http/source/common/http/GrantType.java +++ b/src/main/java/io/cdap/plugin/http/source/common/http/GrantType.java @@ -1,5 +1,5 @@ /* - * Copyright © 2022 Cask Data, Inc. + * Copyright © 2023 Cask Data, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of From c26398de7bbd6b212de2f395be5aa99262376230 Mon Sep 17 00:00:00 2001 From: prince-cs Date: Thu, 23 Feb 2023 16:17:00 +0530 Subject: [PATCH 4/5] import order issues resolved and added the grant type in .md file. --- docs/HTTP-batchsource.md | 1 + .../plugin/http/source/common/BaseHttpSourceConfig.java | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/HTTP-batchsource.md b/docs/HTTP-batchsource.md index 0a21b1f..5325a4a 100644 --- a/docs/HTTP-batchsource.md +++ b/docs/HTTP-batchsource.md @@ -205,6 +205,7 @@ can be omitted as long as the field is present in schema. ### Authentication * **OAuth2** + * **Grant Type:** Value of grant type to determine the OAuth mechanism. * **Auth URL:** Endpoint for the authorization server used to retrieve the authorization code. * **Token URL:** Endpoint for the resource server, which exchanges the authorization code for an access token. * **Client ID:** Client identifier obtained during the Application registration process. diff --git a/src/main/java/io/cdap/plugin/http/source/common/BaseHttpSourceConfig.java b/src/main/java/io/cdap/plugin/http/source/common/BaseHttpSourceConfig.java index feccde8..f0531ae 100644 --- a/src/main/java/io/cdap/plugin/http/source/common/BaseHttpSourceConfig.java +++ b/src/main/java/io/cdap/plugin/http/source/common/BaseHttpSourceConfig.java @@ -28,7 +28,10 @@ import io.cdap.plugin.http.source.common.error.ErrorHandling; import io.cdap.plugin.http.source.common.error.HttpErrorHandlerEntity; import io.cdap.plugin.http.source.common.error.RetryableErrorHandling; -import io.cdap.plugin.http.source.common.http.*; +import io.cdap.plugin.http.source.common.http.AuthType; +import io.cdap.plugin.http.source.common.http.GrantType; +import io.cdap.plugin.http.source.common.http.KeyStoreType; +import io.cdap.plugin.http.source.common.http.OAuthUtil; import io.cdap.plugin.http.source.common.pagination.PaginationIteratorFactory; import io.cdap.plugin.http.source.common.pagination.PaginationType; import io.cdap.plugin.http.source.common.pagination.page.PageFormat; @@ -117,7 +120,6 @@ public abstract class BaseHttpSourceConfig extends ReferencePluginConfig { public static final String PAGINATION_INDEX_PLACEHOLDER = "{pagination.index}"; public static final String PROPERTY_GRANT_TYPE = "grantType"; public static final String PROPERTY_GRANT_TYPE_LABEL = "Grant type"; - public static final String PARAMETER_CLIENT_ID = "client_id"; public static final String PARAMETER_CLIENT_SECRET = "client_secret"; public static final String PARAMETER_REFRESH_TOKEN = "refresh_token"; From b36b7fc977e7f1cbb60c573f2b54cac611d5a8f4 Mon Sep 17 00:00:00 2001 From: prince-cs Date: Thu, 23 Feb 2023 16:18:45 +0530 Subject: [PATCH 5/5] removed the function to check the refresh token grant type instead checking it directly. --- .../plugin/http/source/common/BaseHttpSourceConfig.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/main/java/io/cdap/plugin/http/source/common/BaseHttpSourceConfig.java b/src/main/java/io/cdap/plugin/http/source/common/BaseHttpSourceConfig.java index f0531ae..3701c6e 100644 --- a/src/main/java/io/cdap/plugin/http/source/common/BaseHttpSourceConfig.java +++ b/src/main/java/io/cdap/plugin/http/source/common/BaseHttpSourceConfig.java @@ -966,15 +966,6 @@ PAGINATION_INDEX_PLACEHOLDER, getPaginationType()), } } - private boolean refreshTokenGrantType() { - if (getGrantType() == GrantType.REFRESH_TOKEN.getValue()) { - return true; - } else if (getGrantType() == GrantType.CLIENT_CREDENTIALS.getValue()) { - return false; - } - return false; - } - private boolean validateServiceAccount(FailureCollector collector) { if (containsMacro(PROPERTY_NAME_SERVICE_ACCOUNT_FILE_PATH) || containsMacro(PROPERTY_NAME_SERVICE_ACCOUNT_JSON)) { return false;