-
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
🎉 Asana source: Add oauth init flow parameters support #6832
Merged
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 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
3 changes: 3 additions & 0 deletions
3
airbyte-integrations/bases/source-acceptance-test/CHANGELOG.md
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
2 changes: 1 addition & 1 deletion
2
airbyte-integrations/connectors/source-asana/integration_tests/invalid_config.json
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"access_token": "<wrong_access_token>" | ||
"credentials": { "personal_access_token": "<wrong_access_token>" } | ||
} |
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
36 changes: 36 additions & 0 deletions
36
airbyte-integrations/connectors/source-asana/source_asana/oauth.py
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,36 @@ | ||
# | ||
# Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
from typing import Tuple | ||
|
||
import requests | ||
from airbyte_cdk.sources.streams.http.auth import Oauth2Authenticator | ||
|
||
|
||
class AsanaOauth2Authenticator(Oauth2Authenticator): | ||
""" | ||
Unlike most Oauth services that accept oauth parameters in form of json | ||
encoded body, Asana's oauth token endpoint expects oauth parameters to be | ||
in form-encoded post body. | ||
https://developers.asana.com/docs/oauth | ||
""" | ||
|
||
def refresh_access_token(self) -> Tuple[str, int]: | ||
""" | ||
Override base refresh_access_token method to send form-encoded oauth | ||
parameters over POST request body. | ||
Returns: | ||
Tuple of access token and expiration time in seconds | ||
""" | ||
data = { | ||
"client_id": (None, self.client_id), | ||
"client_secret": (None, self.client_secret), | ||
"grant_type": (None, "refresh_token"), | ||
"refresh_token": (None, self.refresh_token), | ||
} | ||
|
||
response = requests.post(self.token_refresh_endpoint, files=data) | ||
response.raise_for_status() | ||
response_body = response.json() | ||
return response_body["access_token"], response_body["expires_in"] |
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,15 +4,73 @@ | |
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "Asana Spec", | ||
"type": "object", | ||
"required": ["access_token"], | ||
"additionalProperties": false, | ||
"additionalProperties": true, | ||
"properties": { | ||
"access_token": { | ||
"type": "string", | ||
"title": "Personal Access Token", | ||
"description": "Asana Personal Access Token (generate yours <a href=\"https://app.asana.com/0/developer-console\">here</a>).", | ||
"airbyte_secret": true | ||
"credentials": { | ||
"title": "Authentication mechanism", | ||
"description": "Choose how to authenticate to Github", | ||
"type": "object", | ||
"oneOf": [ | ||
{ | ||
"type": "object", | ||
"title": "Authenticate with Personal Access Token", | ||
"required": ["personal_access_token"], | ||
"properties": { | ||
"option_title": { | ||
"type": "string", | ||
"title": "Credentials title", | ||
"description": "PAT Credentials", | ||
"const": "PAT Credentials" | ||
}, | ||
"personal_access_token": { | ||
"type": "string", | ||
"title": "Personal Access Token", | ||
"description": "Asana Personal Access Token (generate yours <a href=\"https://app.asana.com/0/developer-console\">here</a>).", | ||
"airbyte_secret": true | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "object", | ||
"title": "Authenticate via Asana (Oauth)", | ||
"required": ["client_id", "client_secret", "refresh_token"], | ||
"properties": { | ||
"option_title": { | ||
"type": "string", | ||
"title": "Credentials title", | ||
"description": "OAuth Credentials", | ||
"const": "OAuth Credentials" | ||
}, | ||
"client_id": { | ||
"type": "string", | ||
"title": "", | ||
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.
|
||
"description": "", | ||
"airbyte_secret": true | ||
}, | ||
"client_secret": { | ||
"type": "string", | ||
"title": "", | ||
"description": "", | ||
"airbyte_secret": true | ||
}, | ||
"refresh_token": { | ||
"type": "string", | ||
"title": "", | ||
"description": "", | ||
"airbyte_secret": true | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"authSpecification": { | ||
"auth_type": "oauth2.0", | ||
"oauth2Specification": { | ||
"rootObject": ["credentials", 1], | ||
"oauthFlowInitParameters": [["client_id"], ["client_secret"]], | ||
"oauthFlowOutputParameters": [["refresh_token"]] | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
airbyte-integrations/connectors/source-asana/unit_tests/test_oauth.py
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,31 @@ | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
# Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
import pytest | ||||||||||||||||||||||||||||||
import requests_mock | ||||||||||||||||||||||||||||||
from source_asana.oauth import AsanaOauth2Authenticator | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
@pytest.fixture | ||||||||||||||||||||||||||||||
def req_mock(): | ||||||||||||||||||||||||||||||
with requests_mock.Mocker() as mock: | ||||||||||||||||||||||||||||||
yield mock | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
def test_oauth(req_mock): | ||||||||||||||||||||||||||||||
URL = "https://example.com" | ||||||||||||||||||||||||||||||
TOKEN = "test_token" | ||||||||||||||||||||||||||||||
req_mock.post(URL, json={"access_token": TOKEN, "expires_in": 3600}) | ||||||||||||||||||||||||||||||
a = AsanaOauth2Authenticator( | ||||||||||||||||||||||||||||||
token_refresh_endpoint=URL, | ||||||||||||||||||||||||||||||
client_secret="client_secret", | ||||||||||||||||||||||||||||||
client_id="client_id", | ||||||||||||||||||||||||||||||
refresh_token="refresh_token", | ||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||
token = a.get_access_token() | ||||||||||||||||||||||||||||||
Comment on lines
+20
to
+26
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.
Suggested change
|
||||||||||||||||||||||||||||||
assert token == TOKEN | ||||||||||||||||||||||||||||||
assert "multipart/form-data;" in req_mock.last_request.headers["Content-Type"] | ||||||||||||||||||||||||||||||
assert "client_secret" in req_mock.last_request.body.decode() | ||||||||||||||||||||||||||||||
assert "client_id" in req_mock.last_request.body.decode() | ||||||||||||||||||||||||||||||
assert "refresh_token" in req_mock.last_request.body.decode() |
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
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 we remove "required" param?
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.
for backward compatability, see my another hotfix PR for github with explanatory comment #6833 (comment)
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.
IMO, I like the option of canceling the config check during the read method more than removing the required field from the specification.