Skip to content

Commit

Permalink
🐛 Source Typeform: Fix single use refresh token authentication (airby…
Browse files Browse the repository at this point in the history
  • Loading branch information
artem1205 authored and jatinyadav-cc committed Feb 26, 2024
1 parent 7e42169 commit 9b74af7
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 26 deletions.
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

0 comments on commit 9b74af7

Please sign in to comment.