Skip to content
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 Typeform: Fix single use refresh token authentication #33345

Merged
merged 8 commits into from Dec 14, 2023
4 changes: 2 additions & 2 deletions airbyte-integrations/connectors/source-typeform/metadata.yaml
Expand Up @@ -6,11 +6,11 @@ data:
hosts:
- api.typeform.com
connectorBuildOptions:
baseImage: docker.io/airbyte/python-connector-base:1.1.0@sha256:bd98f6505c6764b1b5f99d3aedc23dfc9e9af631a62533f60eb32b1d3dbab20c
baseImage: docker.io/airbyte/python-connector-base:1.2.0@sha256:c22a9d97464b69d6ef01898edf3f8612dc11614f05a84984451dde195f337db9
connectorSubtype: api
connectorType: source
definitionId: e7eff203-90bf-43e5-a240-19ea3056c474
dockerImageTag: 1.2.1
dockerImageTag: 1.2.2
dockerRepository: airbyte/source-typeform
documentationUrl: https://docs.airbyte.com/integrations/sources/typeform
githubIssueLabel: source-typeform
Expand Down
Expand Up @@ -20,9 +20,7 @@ class TypeformAuthenticator(DeclarativeAuthenticator):
oauth2: DeclarativeSingleUseRefreshTokenOauth2Authenticator

def __new__(cls, token_auth, oauth2, config, *args, **kwargs):
if config["credentials"]["access_token"]:
return token_auth
return oauth2
return token_auth if config["credentials"]["auth_type"] == "access_token" else oauth2


@dataclass
Expand Down
Expand Up @@ -26,6 +26,7 @@ definitions:
client_id: "{{ config['credentials']['client_id'] }}"
client_secret: "{{ config['credentials']['client_secret'] }}"
refresh_token: "{{ config['credentials']['refresh_token'] }}"
refresh_token_updater: {}
requester:
type: HttpRequester
url_base: https://api.typeform.com/
Expand Down
Expand Up @@ -6,8 +6,8 @@


def test_typeform_authenticator():
config = {"credentials": {"access_token": "access_token", "client_id": None, "client_secret": None}}
oauth_config = {"credentials": {"access_token": None, "client_id": "client_id", "client_secret": "client_secret"}}
config = {"credentials": {"auth_type": "access_token", "access_token": "access_token"}}
oauth_config = {"credentials": {"auth_type": "oauth2.0", "access_token": None, "client_id": "client_id", "client_secret": "client_secret"}}

class TokenProvider:
def get_token(self) -> str:
Expand All @@ -16,12 +16,12 @@ def get_token(self) -> str:
auth = TypeformAuthenticator(
token_auth=BearerAuthenticator(config=config, token_provider=TokenProvider(), parameters={}),
config=config,
oauth2=DeclarativeSingleUseRefreshTokenOauth2Authenticator(connector_config=config, token_refresh_endpoint="/new_token")
oauth2=DeclarativeSingleUseRefreshTokenOauth2Authenticator(connector_config=oauth_config, token_refresh_endpoint="/new_token")
)
assert isinstance(auth, BearerAuthenticator)

oauth = TypeformAuthenticator(
token_auth=BearerAuthenticator(config=oauth_config, token_provider=TokenProvider(), parameters={}),
token_auth=BearerAuthenticator(config=config, token_provider=TokenProvider(), parameters={}),
config=oauth_config,
oauth2=DeclarativeSingleUseRefreshTokenOauth2Authenticator(connector_config=oauth_config, token_refresh_endpoint="/new_token")
)
Expand Down
Expand Up @@ -45,20 +45,3 @@ def test_stream_slices(form_ids, parent_stream_configs, expected_slices):
slices = list(router.stream_slices())

assert slices == expected_slices

@pytest.mark.parametrize("token_auth, oauth2, config, expected", [
(
"token_auth",
None,
{"credentials": { "auth_type": True, "access_token": True }},
"token_auth"
),
(
None,
"oauth2",
{"credentials": { "auth_type": False, "access_token": False}},
"oauth2"
)
])
def test_new_typeformauthenticator(token_auth, oauth2, config, expected):
assert TypeformAuthenticator(token_auth, oauth2, config) == expected
1 change: 1 addition & 0 deletions docs/integrations/sources/typeform.md
Expand Up @@ -90,6 +90,7 @@ API rate limits \(2 requests per second\): [https://developer.typeform.com/get-s

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:---------------------------------------------------------|:------------------------------------------------------------------------------------------------|
| 1.2.2 | 2023-12-12 | [33345](https://github.com/airbytehq/airbyte/pull/33345) | Fix single use refresh token authentication |
| 1.2.1 | 2023-12-04 | [32775](https://github.com/airbytehq/airbyte/pull/32775) | Add 499 status code handling |
| 1.2.0 | 2023-11-29 | [32745](https://github.com/airbytehq/airbyte/pull/32745) | Add `response_type` field to `responses` schema |
| 1.1.2 | 2023-10-27 | [31914](https://github.com/airbytehq/airbyte/pull/31914) | Fix pagination for stream Responses |
Expand Down