Skip to content

Commit

Permalink
Trello source: Add oAuth flow (airbytehq#6968)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro authored and schlattk committed Jan 4, 2022
1 parent d4b5b99 commit 3155994
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"sourceDefinitionId": "8da67652-004c-11ec-9a03-0242ac130003",
"name": "Trello",
"dockerRepository": "airbyte/source-trello",
"dockerImageTag": "0.1.0",
"dockerImageTag": "0.1.1",
"documentationUrl": "https://docs.airbyte.io/integrations/sources/trello"
}
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@
- sourceDefinitionId: 8da67652-004c-11ec-9a03-0242ac130003
name: Trello
dockerRepository: airbyte/source-trello
dockerImageTag: 0.1.0
dockerImageTag: 0.1.1
documentationUrl: https://docs.airbyte.io/integrations/sources/trello
sourceType: api
- sourceDefinitionId: 374ebc65-6636-4ea0-925c-7d35999a8ffc
Expand Down
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-trello/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ COPY source_trello ./source_trello
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.1.0
LABEL io.airbyte.version=0.1.1
LABEL io.airbyte.name=airbyte/source-trello
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ class SourceTrello(AbstractSource):
Source Trello fetch date from web-based, Kanban-style, list-making application.
"""

@staticmethod
def _get_authenticator(config: dict) -> TrelloAuthenticator:
key, token = config["key"], config["token"]
return TrelloAuthenticator(token=token, key=key)

def check_connection(self, logger, config) -> Tuple[bool, any]:
"""
Testing connection availability for the connector by granting the credentials.
Expand All @@ -193,7 +198,7 @@ def check_connection(self, logger, config) -> Tuple[bool, any]:
try:
url = f"{TrelloStream.url_base}members/me"

authenticator = TrelloAuthenticator(token=config["token"], key=config["key"])
authenticator = self._get_authenticator(config)

session = requests.get(url, headers=authenticator.get_auth_header())
session.raise_for_status()
Expand All @@ -203,6 +208,6 @@ def check_connection(self, logger, config) -> Tuple[bool, any]:
return False, e

def streams(self, config: Mapping[str, Any]) -> List[Stream]:
config["authenticator"] = TrelloAuthenticator(token=config["token"], key=config["key"])
config["authenticator"] = self._get_authenticator(config)

return [Actions(config), Boards(config), Cards(config), Checklists(config), Lists(config), Users(config)]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"title": "Trello Spec",
"type": "object",
"required": ["token", "key", "start_date"],
"additionalProperties": false,
"additionalProperties": true,
"properties": {
"token": {
"type": "string",
Expand All @@ -21,10 +21,19 @@
},
"start_date": {
"type": "string",
"title": "Start date",
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}Z$",
"description": "UTC date and time in the format 2017-01-25T00:00:00Z. Any data before this date will not be replicated.",
"examples": ["2021-03-01T00:00:00.000Z"]
}
}
},
"authSpecification": {
"auth_type": "oauth2.0",
"oauth2Specification": {
"rootObject": [],
"oauthFlowInitParameters": [],
"oauthFlowOutputParameters": [["token"], ["key"]]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ public TrelloOAuthFlow(ConfigRepository configRepository, HttpTransport transpor

public String getSourceConsentUrl(UUID workspaceId, UUID sourceDefinitionId, String redirectUrl) throws IOException, ConfigNotFoundException {
final JsonNode oAuthParamConfig = getSourceOAuthParamConfig(workspaceId, sourceDefinitionId);
return getConsetntUrl(oAuthParamConfig, redirectUrl);
return getConsentUrl(oAuthParamConfig, redirectUrl);
}

public String getDestinationConsentUrl(UUID workspaceId, UUID destinationDefinitionId, String redirectUrl)
throws IOException, ConfigNotFoundException {
final JsonNode oAuthParamConfig = getDestinationOAuthParamConfig(workspaceId, destinationDefinitionId);
return getConsetntUrl(oAuthParamConfig, redirectUrl);
return getConsentUrl(oAuthParamConfig, redirectUrl);
}

private String getConsetntUrl(JsonNode oAuthParamConfig, String redirectUrl) throws IOException, ConfigNotFoundException {
private String getConsentUrl(JsonNode oAuthParamConfig, String redirectUrl) throws IOException, ConfigNotFoundException {
final String clientKey = getClientIdUnsafe(oAuthParamConfig);
final String clientSecret = getClientSecretUnsafe(oAuthParamConfig);
final OAuthGetTemporaryToken oAuthGetTemporaryToken = new OAuthGetTemporaryToken(REQUEST_TOKEN_URL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void testGetSourceConcentUrl() throws IOException, InterruptedException,

@Test
public void testCompleteSourceAuth() throws IOException, InterruptedException, ConfigNotFoundException {
Map<String, String> expectedParams = Map.of("key", "test_client_id", "token", "test_token");
final Map<String, String> expectedParams = Map.of("key", "test_client_id", "token", "test_token");
final Map<String, Object> queryParams = Map.of("oauth_token", "token", "oauth_verifier", "verifier");
final Map<String, Object> returnedParams =
trelloOAuthFlow.completeSourceOAuth(workspaceId, definitionId, queryParams, REDIRECT_URL);
Expand Down
7 changes: 6 additions & 1 deletion airbyte-webapp/src/hooks/services/useConnectorAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ export function useRunOauthFlow(
const onOathGranted = useCallback(
async (event: MessageEvent) => {
// TODO: check if more secure option is required
if (event.origin === window.origin && event.data?.state) {
if (
event.origin === window.origin &&
// In case of oAuth 1.0a there would be no "state" field
// but it would be "oauth_verifier" parameter.
(event.data?.state || event.data?.oauth_verifier)
) {
await completeOauth(event.data);
}
},
Expand Down
1 change: 1 addition & 0 deletions docs/integrations/sources/trello.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ Please read [How to get your APIs Token and Key](https://developer.atlassian.com

| Version | Date | Pull Request | Subject |
| :--- | :--- | :--- | :--- |
| 0.1.1 | 2021-10-12 | [6968](https://github.com/airbytehq/airbyte/pull/6968) | Add oAuth flow support |
| 0.1.0 | 2021-08-18 | [5501](https://github.com/airbytehq/airbyte/pull/5501) | Release Trello CDK Connector |

0 comments on commit 3155994

Please sign in to comment.