-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sergey Chvalyuk <[email protected]>
- Loading branch information
Showing
7 changed files
with
120 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
84 changes: 84 additions & 0 deletions
84
airbyte-oauth/src/main/java/io/airbyte/oauth/flows/AmazonAdsOAuthFlow.java
This file contains 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,84 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.oauth.flows; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.google.common.collect.ImmutableMap; | ||
import io.airbyte.config.persistence.ConfigRepository; | ||
import io.airbyte.oauth.BaseOAuth2Flow; | ||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.net.http.HttpClient; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.function.Supplier; | ||
import org.apache.http.client.utils.URIBuilder; | ||
|
||
public class AmazonAdsOAuthFlow extends BaseOAuth2Flow { | ||
|
||
private static final String AUTHORIZE_URL = "https://www.amazon.com/ap/oa"; | ||
private static final String ACCESS_TOKEN_URL = "https://api.amazon.com/auth/o2/token"; | ||
|
||
public AmazonAdsOAuthFlow(final ConfigRepository configRepository, final HttpClient httpClient) { | ||
super(configRepository, httpClient); | ||
} | ||
|
||
public AmazonAdsOAuthFlow(final ConfigRepository configRepository, final HttpClient httpClient, final Supplier<String> stateSupplier) { | ||
super(configRepository, httpClient, stateSupplier); | ||
} | ||
|
||
/** | ||
* Depending on the OAuth flow implementation, the URL to grant user's consent may differ, | ||
* especially in the query parameters to be provided. This function should generate such consent URL | ||
* accordingly. | ||
* | ||
* @param definitionId The configured definition ID of this client | ||
* @param clientId The configured client ID | ||
* @param redirectUrl the redirect URL | ||
*/ | ||
@Override | ||
protected String formatConsentUrl(final UUID definitionId, | ||
final String clientId, | ||
final String redirectUrl, | ||
final JsonNode inputOAuthConfiguration) | ||
throws IOException { | ||
try { | ||
return new URIBuilder(AUTHORIZE_URL) | ||
.addParameter("client_id", clientId) | ||
.addParameter("scope", "profile") | ||
.addParameter("response_type", "code") | ||
.addParameter("redirect_uri", redirectUrl) | ||
.addParameter("state", getState()) | ||
.build().toString(); | ||
} catch (final URISyntaxException e) { | ||
throw new IOException("Failed to format Consent URL for OAuth flow", e); | ||
} | ||
} | ||
|
||
@Override | ||
protected Map<String, String> getAccessTokenQueryParameters(final String clientId, | ||
final String clientSecret, | ||
final String authCode, | ||
final String redirectUrl) { | ||
return ImmutableMap.<String, String>builder() | ||
// required | ||
.put("client_id", clientId) | ||
.put("redirect_uri", redirectUrl) | ||
.put("client_secret", clientSecret) | ||
.put("code", authCode) | ||
.put("grant_type", "authorization_code") | ||
.build(); | ||
} | ||
|
||
/** | ||
* Returns the URL where to retrieve the access token from. | ||
* | ||
*/ | ||
@Override | ||
protected String getAccessTokenUrl(final JsonNode inputOAuthConfiguration) { | ||
return ACCESS_TOKEN_URL; | ||
} | ||
|
||
} |
This file contains 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
1359d44
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SonarQube Report
SonarQube report for Airbyte Connectors Source Amazon Ads(#11430)
Measures
Detected Issues
Coverage (98.9%)