Skip to content

Commit c16ab54

Browse files
authored
Merge branch 'main' into christo/sanitize-error-message
2 parents d982ffe + 76b5306 commit c16ab54

File tree

7 files changed

+212
-37
lines changed

7 files changed

+212
-37
lines changed

airbyte_cdk/sources/declarative/auth/oauth.py

+26
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ class DeclarativeOauth2Authenticator(AbstractOauth2Authenticator, DeclarativeAut
5656
token_expiry_is_time_of_expiration: bool = False
5757
access_token_name: Union[InterpolatedString, str] = "access_token"
5858
access_token_value: Optional[Union[InterpolatedString, str]] = None
59+
client_id_name: Union[InterpolatedString, str] = "client_id"
60+
client_secret_name: Union[InterpolatedString, str] = "client_secret"
5961
expires_in_name: Union[InterpolatedString, str] = "expires_in"
62+
refresh_token_name: Union[InterpolatedString, str] = "refresh_token"
6063
refresh_request_body: Optional[Mapping[str, Any]] = None
64+
grant_type_name: Union[InterpolatedString, str] = "grant_type"
6165
grant_type: Union[InterpolatedString, str] = "refresh_token"
6266
message_repository: MessageRepository = NoopMessageRepository()
6367

@@ -69,8 +73,15 @@ def __post_init__(self, parameters: Mapping[str, Any]) -> None:
6973
)
7074
else:
7175
self._token_refresh_endpoint = None
76+
self._client_id_name = InterpolatedString.create(self.client_id_name, parameters=parameters)
7277
self._client_id = InterpolatedString.create(self.client_id, parameters=parameters)
78+
self._client_secret_name = InterpolatedString.create(
79+
self.client_secret_name, parameters=parameters
80+
)
7381
self._client_secret = InterpolatedString.create(self.client_secret, parameters=parameters)
82+
self._refresh_token_name = InterpolatedString.create(
83+
self.refresh_token_name, parameters=parameters
84+
)
7485
if self.refresh_token is not None:
7586
self._refresh_token: Optional[InterpolatedString] = InterpolatedString.create(
7687
self.refresh_token, parameters=parameters
@@ -83,6 +94,9 @@ def __post_init__(self, parameters: Mapping[str, Any]) -> None:
8394
self.expires_in_name = InterpolatedString.create(
8495
self.expires_in_name, parameters=parameters
8596
)
97+
self.grant_type_name = InterpolatedString.create(
98+
self.grant_type_name, parameters=parameters
99+
)
86100
self.grant_type = InterpolatedString.create(self.grant_type, parameters=parameters)
87101
self._refresh_request_body = InterpolatedMapping(
88102
self.refresh_request_body or {}, parameters=parameters
@@ -122,18 +136,27 @@ def get_token_refresh_endpoint(self) -> Optional[str]:
122136
return refresh_token_endpoint
123137
return None
124138

139+
def get_client_id_name(self) -> str:
140+
return self._client_id_name.eval(self.config) # type: ignore # eval returns a string in this context
141+
125142
def get_client_id(self) -> str:
126143
client_id: str = self._client_id.eval(self.config)
127144
if not client_id:
128145
raise ValueError("OAuthAuthenticator was unable to evaluate client_id parameter")
129146
return client_id
130147

148+
def get_client_secret_name(self) -> str:
149+
return self._client_secret_name.eval(self.config) # type: ignore # eval returns a string in this context
150+
131151
def get_client_secret(self) -> str:
132152
client_secret: str = self._client_secret.eval(self.config)
133153
if not client_secret:
134154
raise ValueError("OAuthAuthenticator was unable to evaluate client_secret parameter")
135155
return client_secret
136156

157+
def get_refresh_token_name(self) -> str:
158+
return self._refresh_token_name.eval(self.config) # type: ignore # eval returns a string in this context
159+
137160
def get_refresh_token(self) -> Optional[str]:
138161
return None if self._refresh_token is None else str(self._refresh_token.eval(self.config))
139162

@@ -146,6 +169,9 @@ def get_access_token_name(self) -> str:
146169
def get_expires_in_name(self) -> str:
147170
return self.expires_in_name.eval(self.config) # type: ignore # eval returns a string in this context
148171

172+
def get_grant_type_name(self) -> str:
173+
return self.grant_type_name.eval(self.config) # type: ignore # eval returns a string in this context
174+
149175
def get_grant_type(self) -> str:
150176
return self.grant_type.eval(self.config) # type: ignore # eval returns a string in this context
151177

airbyte_cdk/sources/declarative/declarative_component_schema.yaml

+46-19
Original file line numberDiff line numberDiff line change
@@ -1047,20 +1047,41 @@ definitions:
10471047
type:
10481048
type: string
10491049
enum: [OAuthAuthenticator]
1050+
client_id_name:
1051+
title: Client ID Property Name
1052+
description: The name of the property to use to refresh the `access_token`.
1053+
type: string
1054+
default: "client_id"
1055+
examples:
1056+
- custom_app_id
10501057
client_id:
10511058
title: Client ID
10521059
description: The OAuth client ID. Fill it in the user inputs.
10531060
type: string
10541061
examples:
10551062
- "{{ config['client_id }}"
10561063
- "{{ config['credentials']['client_id }}"
1064+
client_secret_name:
1065+
title: Client Secret Property Name
1066+
description: The name of the property to use to refresh the `access_token`.
1067+
type: string
1068+
default: "client_secret"
1069+
examples:
1070+
- custom_app_secret
10571071
client_secret:
10581072
title: Client Secret
10591073
description: The OAuth client secret. Fill it in the user inputs.
10601074
type: string
10611075
examples:
10621076
- "{{ config['client_secret }}"
10631077
- "{{ config['credentials']['client_secret }}"
1078+
refresh_token_name:
1079+
title: Refresh Token Property Name
1080+
description: The name of the property to use to refresh the `access_token`.
1081+
type: string
1082+
default: "refresh_token"
1083+
examples:
1084+
- custom_app_refresh_value
10641085
refresh_token:
10651086
title: Refresh Token
10661087
description: Credential artifact used to get a new access token.
@@ -1094,6 +1115,13 @@ definitions:
10941115
default: "expires_in"
10951116
examples:
10961117
- expires_in
1118+
grant_type_name:
1119+
title: Grant Type Property Name
1120+
description: The name of the property to use to refresh the `access_token`.
1121+
type: string
1122+
default: "grant_type"
1123+
examples:
1124+
- custom_grant_type
10971125
grant_type:
10981126
title: Grant Type
10991127
description: Specifies the OAuth2 grant type. If set to refresh_token, the refresh_token needs to be provided as well. For client_credentials, only client id and secret are required. Other grant types are not officially supported.
@@ -2204,15 +2232,15 @@ definitions:
22042232
Pertains to the fields defined by the connector relating to the OAuth flow.
22052233
22062234
Interpolation capabilities:
2207-
- The variables placeholders are declared as `{my_var}`.
2208-
- The nested resolution variables like `{{my_nested_var}}` is allowed as well.
2235+
- The variables placeholders are declared as `{{my_var}}`.
2236+
- The nested resolution variables like `{{ {{my_nested_var}} }}` is allowed as well.
22092237
22102238
- The allowed interpolation context is:
2211-
+ base64Encoder - encode to `base64`, {base64Encoder:{my_var_a}:{my_var_b}}
2212-
+ base64Decorer - decode from `base64` encoded string, {base64Decoder:{my_string_variable_or_string_value}}
2213-
+ urlEncoder - encode the input string to URL-like format, {urlEncoder:https://test.host.com/endpoint}
2214-
+ urlDecorer - decode the input url-encoded string into text format, {urlDecoder:https%3A%2F%2Fairbyte.io}
2215-
+ codeChallengeS256 - get the `codeChallenge` encoded value to provide additional data-provider specific authorisation values, {codeChallengeS256:{state_value}}
2239+
+ base64Encoder - encode to `base64`, {{ {{my_var_a}}:{{my_var_b}} | base64Encoder }}
2240+
+ base64Decorer - decode from `base64` encoded string, {{ {{my_string_variable_or_string_value}} | base64Decoder }}
2241+
+ urlEncoder - encode the input string to URL-like format, {{ https://test.host.com/endpoint | urlEncoder}}
2242+
+ urlDecorer - decode the input url-encoded string into text format, {{ urlDecoder:https%3A%2F%2Fairbyte.io | urlDecoder}}
2243+
+ codeChallengeS256 - get the `codeChallenge` encoded value to provide additional data-provider specific authorisation values, {{ {{state_value}} | codeChallengeS256 }}
22162244
22172245
Examples:
22182246
- The TikTok Marketing DeclarativeOAuth spec:
@@ -2221,12 +2249,12 @@ definitions:
22212249
"type": "object",
22222250
"additionalProperties": false,
22232251
"properties": {
2224-
"consent_url": "https://ads.tiktok.com/marketing_api/auth?{client_id_key}={{client_id_key}}&{redirect_uri_key}={urlEncoder:{{redirect_uri_key}}}&{state_key}={{state_key}}",
2252+
"consent_url": "https://ads.tiktok.com/marketing_api/auth?{{client_id_key}}={{client_id_value}}&{{redirect_uri_key}}={{ {{redirect_uri_value}} | urlEncoder}}&{{state_key}}={{state_value}}",
22252253
"access_token_url": "https://business-api.tiktok.com/open_api/v1.3/oauth2/access_token/",
22262254
"access_token_params": {
2227-
"{auth_code_key}": "{{auth_code_key}}",
2228-
"{client_id_key}": "{{client_id_key}}",
2229-
"{client_secret_key}": "{{client_secret_key}}"
2255+
"{{ auth_code_key }}": "{{ auth_code_value }}",
2256+
"{{ client_id_key }}": "{{ client_id_value }}",
2257+
"{{ client_secret_key }}": "{{ client_secret_value }}"
22302258
},
22312259
"access_token_headers": {
22322260
"Content-Type": "application/json",
@@ -2244,7 +2272,6 @@ definitions:
22442272
required:
22452273
- consent_url
22462274
- access_token_url
2247-
- extract_output
22482275
properties:
22492276
consent_url:
22502277
title: Consent URL
@@ -2253,8 +2280,8 @@ definitions:
22532280
The DeclarativeOAuth Specific string URL string template to initiate the authentication.
22542281
The placeholders are replaced during the processing to provide neccessary values.
22552282
examples:
2256-
- https://domain.host.com/marketing_api/auth?{client_id_key}={{client_id_key}}&{redirect_uri_key}={urlEncoder:{{redirect_uri_key}}}&{state_key}={{state_key}}
2257-
- https://endpoint.host.com/oauth2/authorize?{client_id_key}={{client_id_key}}&{redirect_uri_key}={urlEncoder:{{redirect_uri_key}}}&{scope_key}={urlEncoder:{{scope_key}}}&{state_key}={{state_key}}&subdomain={subdomain}
2283+
- https://domain.host.com/marketing_api/auth?{{client_id_key}}={{client_id_value}}&{{redirect_uri_key}}={{{{redirect_uri_value}} | urlEncoder}}&{{state_key}}={{state_value}}
2284+
- https://endpoint.host.com/oauth2/authorize?{{client_id_key}}={{client_id_value}}&{{redirect_uri_key}}={{{{redirect_uri_value}} | urlEncoder}}&{{scope_key}}={{{{scope_value}} | urlEncoder}}&{{state_key}}={{state_value}}&subdomain={{subdomain}}
22582285
scope:
22592286
title: Scopes
22602287
type: string
@@ -2269,7 +2296,7 @@ definitions:
22692296
The DeclarativeOAuth Specific URL templated string to obtain the `access_token`, `refresh_token` etc.
22702297
The placeholders are replaced during the processing to provide neccessary values.
22712298
examples:
2272-
- https://auth.host.com/oauth2/token?{client_id_key}={{client_id_key}}&{client_secret_key}={{client_secret_key}}&{auth_code_key}={{auth_code_key}}&{redirect_uri_key}={urlEncoder:{{redirect_uri_key}}}
2299+
- https://auth.host.com/oauth2/token?{{client_id_key}}={{client_id_value}}&{{client_secret_key}}={{client_secret_value}}&{{auth_code_key}}={{auth_code_value}}&{{redirect_uri_key}}={{{{redirect_uri_value}} | urlEncoder}}
22732300
access_token_headers:
22742301
title: Access Token Headers
22752302
type: object
@@ -2278,7 +2305,7 @@ definitions:
22782305
The DeclarativeOAuth Specific optional headers to inject while exchanging the `auth_code` to `access_token` during `completeOAuthFlow` step.
22792306
examples:
22802307
- {
2281-
"Authorization": "Basic {base64Encoder:{client_id}:{client_secret}}",
2308+
"Authorization": "Basic {{ {{ client_id_value }}:{{ client_secret_value }} | base64Encoder }}",
22822309
}
22832310
access_token_params:
22842311
title: Access Token Query Params (Json Encoded)
@@ -2289,9 +2316,9 @@ definitions:
22892316
When this property is provided, the query params will be encoded as `Json` and included in the outgoing API request.
22902317
examples:
22912318
- {
2292-
"{auth_code_key}": "{{auth_code_key}}",
2293-
"{client_id_key}": "{{client_id_key}}",
2294-
"{client_secret_key}": "{{client_secret_key}}",
2319+
"{{ auth_code_key }}": "{{ auth_code_value }}",
2320+
"{{ client_id_key }}": "{{ client_id_value }}",
2321+
"{{ client_secret_key }}": "{{ client_secret_value }}",
22952322
}
22962323
extract_output:
22972324
title: Extract Output

0 commit comments

Comments
 (0)