-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
🎉 Source Amazon Ads: Implement OAuth2.0 #11430
Merged
Merged
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1359d44
Added support OAuth2.0
grubberr ec12083
fix amazon-ads.md
grubberr 710b897
fix oauth2.0 scope -> "advertising::campaign_management"
grubberr bf18c4b
we don't need scope on exchange refresh -> access token
grubberr 7c07ba9
spec.json fixed
grubberr 01cac75
Merge branch 'master' into grubberr/11417-source-amazon-ads
grubberr b754c3c
Merge branch 'master' into grubberr/11417-source-amazon-ads
grubberr ac5491b
Merge branch 'master' into grubberr/11417-source-amazon-ads
grubberr bd530ce
enum removed
grubberr 247af37
bump version 0.1.4 -> 0.1.5
grubberr ce417c5
Merge branch 'master' into grubberr/11417-source-amazon-ads
grubberr b246b29
"additionalProperties": true
grubberr 9022d2e
AmazonAdsOAuthFlowTest.java added
grubberr ff4b28f
Merge branch 'master' into grubberr/11417-source-amazon-ads
grubberr 76bbc88
Merge branch 'master' into grubberr/11417-source-amazon-ads
grubberr e18d4ae
revert version to check auto-bump
grubberr 0c1ed16
auto-bump connector version
octavia-squidington-iii 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
from typing import List | ||
|
||
from airbyte_cdk.models import AdvancedAuth, AuthFlowType, OAuthConfigSpecification | ||
from pydantic import BaseModel, Field | ||
from source_amazon_ads.constants import AmazonAdsRegion | ||
|
||
|
@@ -12,6 +13,8 @@ class AmazonAdsConfig(BaseModel): | |
class Config: | ||
title = "Amazon Ads Spec" | ||
|
||
auth_type: str = Field(default="oauth2.0", const=True, order=0) | ||
|
||
client_id: str = Field( | ||
name="Client ID", | ||
description=( | ||
|
@@ -28,19 +31,6 @@ class Config: | |
airbyte_secret=True, | ||
) | ||
|
||
# Amazon docs don't describe which of the below scopes to use under what circumstances so | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make sure additionalproperties=true so existing configs don't break |
||
# we default to the first but allow the user to override it | ||
scope: str = Field( | ||
"advertising::campaign_management", | ||
name="Client scope", | ||
examples=[ | ||
"cpc_advertising:campaign_management", | ||
], | ||
description=( | ||
"By default its advertising::campaign_management," | ||
" but customers may need to set scope to cpc_advertising:campaign_management." | ||
), | ||
) | ||
refresh_token: str = Field( | ||
name="Oauth refresh token", | ||
description=( | ||
|
@@ -93,3 +83,30 @@ def schema(cls, **kvargs): | |
schema["properties"]["region"].pop("allOf", None) | ||
schema["properties"]["region"].pop("$ref", None) | ||
return schema | ||
|
||
|
||
advanced_auth = AdvancedAuth( | ||
auth_flow_type=AuthFlowType.oauth2_0, | ||
predicate_key=["auth_type"], | ||
predicate_value="oauth2.0", | ||
oauth_config_specification=OAuthConfigSpecification( | ||
complete_oauth_output_specification={ | ||
"type": "object", | ||
"additionalProperties": False, | ||
"properties": {"refresh_token": {"type": "string", "path_in_connector_config": ["refresh_token"]}}, | ||
}, | ||
complete_oauth_server_input_specification={ | ||
"type": "object", | ||
"additionalProperties": False, | ||
"properties": {"client_id": {"type": "string"}, "client_secret": {"type": "string"}}, | ||
}, | ||
complete_oauth_server_output_specification={ | ||
"type": "object", | ||
"additionalProperties": False, | ||
"properties": { | ||
"client_id": {"type": "string", "path_in_connector_config": ["client_id"]}, | ||
"client_secret": {"type": "string", "path_in_connector_config": ["client_secret"]}, | ||
}, | ||
}, | ||
), | ||
) |
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a unit test for this please? |
||
|
||
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", "advertising::campaign_management") | ||
.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
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.
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.
why was scope removed?
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.
According to amazon auth docs we need only scope to get
refresh_token
.and we don't need scope to exchange
refresh_token
->access_token
.It means scope is useless here because we already have
refresh_token
as connector input parameter.I this PR I moved
scope
from python side to Java sidebecause we need scope only on stage where we get
refresh_token