-
Notifications
You must be signed in to change notification settings - Fork 29
[PLUGIN-1872] Added GrantType and Client Authentication for the HttpOauth2 #187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vikasrathee-cs
merged 1 commit into
data-integrations:develop
from
cloudsufi:httpOauth2Grant
Mar 19, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/java/io/cdap/plugin/http/common/OAuth2ClientAuthentication.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| * Copyright © 2025 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.common; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Enum encoding the handled Oauth2 Client Authentication | ||
| */ | ||
| public enum OAuth2ClientAuthentication implements EnumWithValue { | ||
| BODY("body", "Body"), | ||
| REQUEST_PARAMETER("request_parameter", "Request Parameter"); | ||
|
|
||
| private final String value; | ||
| private final String label; | ||
|
|
||
| OAuth2ClientAuthentication(String value, String label) { | ||
| this.value = value; | ||
| this.label = label; | ||
| } | ||
|
|
||
| /** | ||
| * Determines the OAuth2 client authentication method based on the provided input. | ||
| * | ||
| * <p>This method checks if the given client authentication type matches the predefined | ||
| * BODY authentication type. If it matches, the method returns the BODY authentication. Otherwise, | ||
| * it defaults to REQUEST_PARAMETER authentication.</p> | ||
| * | ||
| * @param clientAuthentication The client authentication type as a {@link String}. It can be | ||
| * either the value or the label of the BODY authentication method. | ||
| * @return {@link OAuth2ClientAuthentication} The corresponding authentication type. Returns | ||
| * {@code BODY} if the input matches its value or label; otherwise, returns | ||
| * {@code REQUEST_PARAMETER}. | ||
| */ | ||
| public static OAuth2ClientAuthentication getClientAuthentication(String clientAuthentication) { | ||
| if (Objects.equals(clientAuthentication, BODY.getValue()) || Objects.equals( | ||
| clientAuthentication, BODY.getLabel())) { | ||
| return BODY; | ||
| } else { | ||
| return REQUEST_PARAMETER; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String getValue() { | ||
| return value; | ||
| } | ||
|
|
||
| public String getLabel() { | ||
| return label; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return this.getValue(); | ||
| } | ||
| } |
68 changes: 68 additions & 0 deletions
68
src/main/java/io/cdap/plugin/http/common/OAuth2GrantType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * Copyright © 2025 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.common; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Enum encoding the handled Oauth2 Grant Types | ||
| */ | ||
| public enum OAuth2GrantType implements EnumWithValue { | ||
| REFRESH_TOKEN("refresh_token", "Refresh Token"), | ||
| CLIENT_CREDENTIALS("client_credentials", "Client Credentials"); | ||
|
|
||
| private final String value; | ||
| private final String label; | ||
|
|
||
| OAuth2GrantType(String value, String label) { | ||
| this.value = value; | ||
| this.label = label; | ||
| } | ||
|
|
||
| /** | ||
| * Determines the OAuth2 grant type based on the provided string value. | ||
| * | ||
| * <p>This method checks whether the given OAuth2 grant type string matches | ||
| * the CLIENT_CREDENTIALS grant type based on its value or label. If it matches, | ||
| * CLIENT_CREDENTIALS is returned; otherwise, REFRESH_TOKEN is returned as the default.</p> | ||
| * | ||
| * @param oauth2GrantType The OAuth2 grant type as a string. | ||
| * @return The corresponding {@link OAuth2GrantType}, either CLIENT_CREDENTIALS or REFRESH_TOKEN. | ||
| */ | ||
| public static OAuth2GrantType getGrantType(String oauth2GrantType) { | ||
Amit-CloudSufi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (Objects.equals(oauth2GrantType, CLIENT_CREDENTIALS.getValue()) || Objects.equals( | ||
| oauth2GrantType, CLIENT_CREDENTIALS.getLabel())) { | ||
| return CLIENT_CREDENTIALS; | ||
| } else { | ||
| return REFRESH_TOKEN; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String getValue() { | ||
| return value; | ||
| } | ||
|
|
||
| public String getLabel() { | ||
| return label; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return this.getValue(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.