Skip to content

Commit c08f6dd

Browse files
committed
estuary-cdk: OAuth2RotatingTokenSpec merged into OAuth2Spec
1 parent 8a13f4e commit c08f6dd

File tree

5 files changed

+14
-32
lines changed

5 files changed

+14
-32
lines changed

estuary-cdk/estuary_cdk/capture/common.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
CaptureBinding,
3030
ClientCredentialsOAuth2Credentials,
3131
OAuth2TokenFlowSpec,
32-
OAuth2RotatingTokenSpec,
3332
AuthorizationCodeFlowOAuth2Credentials,
3433
LongLivedClientCredentialsOAuth2Credentials,
3534
ResourceOwnerPasswordOAuth2Credentials,

estuary-cdk/estuary_cdk/flow.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class Checkpoint(BaseModel):
7474
class OAuth2TokenFlowSpec(BaseModel):
7575
accessTokenResponseMap: dict[str, str]
7676
accessTokenUrlTemplate: str
77+
additionalTokenExchangeBody: dict[str, str | int] = {}
7778

7879

7980
class OAuth2Spec(BaseModel):
@@ -83,10 +84,7 @@ class OAuth2Spec(BaseModel):
8384
accessTokenHeaders: dict[str, str]
8485
accessTokenResponseMap: dict[str, str]
8586
accessTokenUrlTemplate: str
86-
87-
88-
class OAuth2RotatingTokenSpec(OAuth2Spec):
89-
additionalTokenExchangeBody: dict[str, str | int] | None
87+
additionalTokenExchangeBody: dict[str, str | int] = {}
9088

9189

9290
class ConnectorSpec(BaseModel):

estuary-cdk/estuary_cdk/http.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
GoogleServiceAccount,
2424
GoogleServiceAccountSpec,
2525
LongLivedClientCredentialsOAuth2Credentials,
26-
OAuth2RotatingTokenSpec,
2726
OAuth2Spec,
2827
OAuth2TokenFlowSpec,
2928
ResourceOwnerPasswordOAuth2Credentials,
@@ -221,7 +220,7 @@ class AccessTokenResponse(BaseModel):
221220
refresh_token: str = ""
222221
scope: str = ""
223222

224-
oauth_spec: OAuth2Spec | OAuth2TokenFlowSpec | OAuth2RotatingTokenSpec | None
223+
oauth_spec: OAuth2Spec | OAuth2TokenFlowSpec | None
225224
credentials: (
226225
BaseOAuth2Credentials
227226
| RotatingOAuth2Credentials
@@ -368,26 +367,13 @@ async def _fetch_oauth2_token(
368367
f"Unsupported client credentials placement: {credentials.client_credentials_placement}."
369368
)
370369

371-
match credentials:
372-
case RotatingOAuth2Credentials():
373-
assert isinstance(self.oauth_spec, OAuth2RotatingTokenSpec)
374-
form["refresh_token"] = credentials.refresh_token
375-
376-
# Some providers require additional parameters within the form body, like
377-
# an `expires_in` to configure how long the access token remains valid.
378-
if self.oauth_spec.additionalTokenExchangeBody:
379-
form.update(self.oauth_spec.additionalTokenExchangeBody)
380-
381-
case BaseOAuth2Credentials():
382-
form["refresh_token"] = credentials.refresh_token
383-
case (
384-
ClientCredentialsOAuth2Credentials()
385-
| AuthorizationCodeFlowOAuth2Credentials()
386-
| ResourceOwnerPasswordOAuth2Credentials()
387-
):
388-
pass
389-
case _:
390-
raise TypeError(f"Unsupported credentials type: {type(credentials)}.")
370+
# Some providers require additional parameters within the form body, like
371+
# an `expires_in` to configure how long the access token remains valid.
372+
form.update(self.oauth_spec.additionalTokenExchangeBody)
373+
374+
if isinstance(credentials, BaseOAuth2Credentials):
375+
assert isinstance(self.oauth_spec, OAuth2Spec)
376+
form["refresh_token"] = credentials.refresh_token
391377

392378
response = await session.request(
393379
log,

source-outreach/source_outreach/models.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from estuary_cdk.capture.common import (
88
BaseDocument,
99
RotatingOAuth2Credentials,
10-
OAuth2RotatingTokenSpec,
10+
OAuth2Spec,
1111
ResourceConfig,
1212
ResourceState,
1313
)
@@ -91,7 +91,7 @@ def urlencode_field(field: str):
9191
}
9292

9393

94-
OAUTH2_SPEC = OAuth2RotatingTokenSpec(
94+
OAUTH2_SPEC = OAuth2Spec(
9595
provider="outreach",
9696
accessTokenBody=json.dumps(accessTokenBody),
9797
authUrlTemplate=(
@@ -111,7 +111,6 @@ def urlencode_field(field: str):
111111
accessTokenHeaders={
112112
"Content-Type": "application/json",
113113
},
114-
additionalTokenExchangeBody=None,
115114
)
116115

117116

source-zendesk-support-native/source_zendesk_support_native/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
BaseDocument,
99
LongLivedClientCredentialsOAuth2Credentials,
1010
RotatingOAuth2Credentials,
11-
OAuth2RotatingTokenSpec,
11+
OAuth2Spec,
1212
ResourceConfig,
1313
ResourceState,
1414
)
@@ -47,7 +47,7 @@ def urlencode_field(field: str):
4747
"expires_in": MAX_VALID_ACCESS_TOKEN_DURATION,
4848
}
4949

50-
OAUTH2_SPEC = OAuth2RotatingTokenSpec(
50+
OAUTH2_SPEC = OAuth2Spec(
5151
provider="zendesk",
5252
accessTokenBody=json.dumps(accessTokenBody),
5353
authUrlTemplate=(

0 commit comments

Comments
 (0)