Skip to content

Commit 98aadfe

Browse files
author
Baz
authored
feat: (Low-Code CDK) - extend the OAuthConfigSpecification with the OauthConnectorInputSpecification components (#93)
1 parent d242f79 commit 98aadfe

File tree

7 files changed

+748
-339
lines changed

7 files changed

+748
-339
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ dist
1313
.venv
1414
.pytest_cache
1515
.idea
16+
.vscode
1617
**/__pycache__

airbyte_cdk/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
FailureType,
4040
Level,
4141
OAuthConfigSpecification,
42+
OauthConnectorInputSpecification,
4243
OrchestratorType,
44+
State,
4345
Status,
4446
StreamDescriptor,
4547
SyncMode,

airbyte_cdk/sources/declarative/declarative_component_schema.yaml

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,6 +1972,173 @@ definitions:
19721972
- app_id:
19731973
type: string
19741974
path_in_connector_config: ["info", "app_id"]
1975+
oauth_connector_input_specification:
1976+
title: DeclarativeOAuth Connector Specification
1977+
description: |-
1978+
The DeclarativeOAuth specific blob.
1979+
Pertains to the fields defined by the connector relating to the OAuth flow.
1980+
1981+
Interpolation capabilities:
1982+
- The variables placeholders are declared as `{my_var}`.
1983+
- The nested resolution variables like `{{my_nested_var}}` is allowed as well.
1984+
1985+
- The allowed interpolation context is:
1986+
+ base64Encoder - encode to `base64`, {base64Encoder:{my_var_a}:{my_var_b}}
1987+
+ base64Decorer - decode from `base64` encoded string, {base64Decoder:{my_string_variable_or_string_value}}
1988+
+ urlEncoder - encode the input string to URL-like format, {urlEncoder:https://test.host.com/endpoint}
1989+
+ urlDecorer - decode the input url-encoded string into text format, {urlDecoder:https%3A%2F%2Fairbyte.io}
1990+
+ codeChallengeS256 - get the `codeChallenge` encoded value to provide additional data-provider specific authorisation values, {codeChallengeS256:{state_value}}
1991+
1992+
Examples:
1993+
- The TikTok Marketing DeclarativeOAuth spec:
1994+
{
1995+
"oauth_connector_input_specification": {
1996+
"type": "object",
1997+
"additionalProperties": false,
1998+
"properties": {
1999+
"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}}",
2000+
"access_token_url": "https://business-api.tiktok.com/open_api/v1.3/oauth2/access_token/",
2001+
"access_token_params": {
2002+
"{auth_code_key}": "{{auth_code_key}}",
2003+
"{client_id_key}": "{{client_id_key}}",
2004+
"{client_secret_key}": "{{client_secret_key}}"
2005+
},
2006+
"access_token_headers": {
2007+
"Content-Type": "application/json",
2008+
"Accept": "application/json"
2009+
},
2010+
"extract_output": ["data.access_token"],
2011+
"client_id_key": "app_id",
2012+
"client_secret_key": "secret",
2013+
"auth_code_key": "auth_code"
2014+
}
2015+
}
2016+
}
2017+
type: object
2018+
additionalProperties: true
2019+
required:
2020+
- consent_url
2021+
- access_token_url
2022+
- extract_output
2023+
properties:
2024+
consent_url:
2025+
title: DeclarativeOAuth Consent URL
2026+
type: string
2027+
description: |-
2028+
The DeclarativeOAuth Specific string URL string template to initiate the authentication.
2029+
The placeholders are replaced during the processing to provide neccessary values.
2030+
examples:
2031+
- consent_url: https://domain.host.com/marketing_api/auth?{client_id_key}={{client_id_key}}&{redirect_uri_key}={urlEncoder:{{redirect_uri_key}}}&{state_key}={{state_key}}
2032+
- consent_url: 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}
2033+
scope:
2034+
title: (Optional) DeclarativeOAuth Scope
2035+
type: string
2036+
description: |-
2037+
The DeclarativeOAuth Specific string of the scopes needed to be grant for authenticated user.
2038+
examples:
2039+
- scope: user:read user:read_orders workspaces:read
2040+
access_token_url:
2041+
title: DeclarativeOAuth Access Token URL
2042+
type: string
2043+
description: |-
2044+
The DeclarativeOAuth Specific URL templated string to obtain the `access_token`, `refresh_token` etc.
2045+
The placeholders are replaced during the processing to provide neccessary values.
2046+
examples:
2047+
- access_token_url: 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}}}
2048+
access_token_headers:
2049+
title: (Optional) DeclarativeOAuth Access Token Headers
2050+
type: object
2051+
additionalProperties: true
2052+
description: |-
2053+
The DeclarativeOAuth Specific optional headers to inject while exchanging the `auth_code` to `access_token` during `completeOAuthFlow` step.
2054+
examples:
2055+
- access_token_headers: {
2056+
"Authorization": "Basic {base64Encoder:{client_id}:{client_secret}}"
2057+
}
2058+
access_token_params:
2059+
title: (Optional) DeclarativeOAuth Access Token Query Params (Json Encoded)
2060+
type: object
2061+
additionalProperties: true
2062+
description: |-
2063+
The DeclarativeOAuth Specific optional query parameters to inject while exchanging the `auth_code` to `access_token` during `completeOAuthFlow` step.
2064+
When this property is provided, the query params will be encoded as `Json` and included in the outgoing API request.
2065+
examples:
2066+
- access_token_params: {
2067+
"{auth_code_key}": "{{auth_code_key}}",
2068+
"{client_id_key}": "{{client_id_key}}",
2069+
"{client_secret_key}": "{{client_secret_key}}"
2070+
}
2071+
extract_output:
2072+
title: DeclarativeOAuth Extract Output
2073+
type: array
2074+
items:
2075+
type: string
2076+
description: |-
2077+
The DeclarativeOAuth Specific list of strings to indicate which keys should be extracted and returned back to the input config.
2078+
examples:
2079+
- extract_output: ["access_token", "refresh_token", "other_field"]
2080+
state:
2081+
title: (Optional) DeclarativeOAuth Configurable State Query Param
2082+
type: object
2083+
additionalProperties: true
2084+
required:
2085+
- min
2086+
- max
2087+
description: |-
2088+
The DeclarativeOAuth Specific object to provide the criteria of how the `state` query param should be constructed,
2089+
including length and complexity.
2090+
properties:
2091+
min:
2092+
type: integer
2093+
max:
2094+
type: integer
2095+
examples:
2096+
- state: {
2097+
"min": 7,
2098+
"max": 128,
2099+
}
2100+
client_id_key:
2101+
title: (Optional) DeclarativeOAuth Client ID Key Override
2102+
type: string
2103+
description: |-
2104+
The DeclarativeOAuth Specific optional override to provide the custom `client_id` key name, if required by data-provider.
2105+
examples:
2106+
- client_id_key: "my_custom_client_id_key_name"
2107+
client_secret_key:
2108+
title: (Optional) DeclarativeOAuth Client Secret Key Override
2109+
type: string
2110+
description: |-
2111+
The DeclarativeOAuth Specific optional override to provide the custom `client_secret` key name, if required by data-provider.
2112+
examples:
2113+
- client_secret_key: "my_custom_client_secret_key_name"
2114+
scope_key:
2115+
title: (Optional) DeclarativeOAuth Scope Key Override
2116+
type: string
2117+
description: |-
2118+
The DeclarativeOAuth Specific optional override to provide the custom `scope` key name, if required by data-provider.
2119+
examples:
2120+
- scope_key: "my_custom_scope_key_key_name"
2121+
state_key:
2122+
title: (Optional) DeclarativeOAuth State Key Override
2123+
type: string
2124+
description: |-
2125+
The DeclarativeOAuth Specific optional override to provide the custom `state` key name, if required by data-provider.
2126+
examples:
2127+
- state_key: "my_custom_state_key_key_name"
2128+
auth_code_key:
2129+
title: (Optional) DeclarativeOAuth Auth Code Key Override
2130+
type: string
2131+
description: |-
2132+
The DeclarativeOAuth Specific optional override to provide the custom `code` key name to something like `auth_code` or `custom_auth_code`, if required by data-provider.
2133+
examples:
2134+
- auth_code_key: "my_custom_auth_code_key_name"
2135+
redirect_uri_key:
2136+
title: (Optional) DeclarativeOAuth Redirect URI Key Override
2137+
type: string
2138+
description: |-
2139+
The DeclarativeOAuth Specific optional override to provide the custom `redirect_uri` key name to something like `callback_uri`, if required by data-provider.
2140+
examples:
2141+
- redirect_uri_key: "my_custom_redirect_uri_key_name"
19752142
complete_oauth_output_specification:
19762143
title: "OAuth output specification"
19772144
description: |-

airbyte_cdk/sources/declarative/models/declarative_component_schema.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,123 @@ class NoPagination(BaseModel):
748748
type: Literal["NoPagination"]
749749

750750

751+
class State(BaseModel):
752+
class Config:
753+
extra = Extra.allow
754+
755+
min: int
756+
max: int
757+
758+
759+
class OauthConnectorInputSpecification(BaseModel):
760+
class Config:
761+
extra = Extra.allow
762+
763+
consent_url: str = Field(
764+
...,
765+
description="The DeclarativeOAuth Specific string URL string template to initiate the authentication.\nThe placeholders are replaced during the processing to provide neccessary values.",
766+
examples=[
767+
{
768+
"consent_url": "https://domain.host.com/marketing_api/auth?{client_id_key}={{client_id_key}}&{redirect_uri_key}={urlEncoder:{{redirect_uri_key}}}&{state_key}={{state_key}}"
769+
},
770+
{
771+
"consent_url": "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}"
772+
},
773+
],
774+
title="DeclarativeOAuth Consent URL",
775+
)
776+
scope: Optional[str] = Field(
777+
None,
778+
description="The DeclarativeOAuth Specific string of the scopes needed to be grant for authenticated user.",
779+
examples=[{"scope": "user:read user:read_orders workspaces:read"}],
780+
title="(Optional) DeclarativeOAuth Scope",
781+
)
782+
access_token_url: str = Field(
783+
...,
784+
description="The DeclarativeOAuth Specific URL templated string to obtain the `access_token`, `refresh_token` etc.\nThe placeholders are replaced during the processing to provide neccessary values.",
785+
examples=[
786+
{
787+
"access_token_url": "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}}}"
788+
}
789+
],
790+
title="DeclarativeOAuth Access Token URL",
791+
)
792+
access_token_headers: Optional[Dict[str, Any]] = Field(
793+
None,
794+
description="The DeclarativeOAuth Specific optional headers to inject while exchanging the `auth_code` to `access_token` during `completeOAuthFlow` step.",
795+
examples=[
796+
{
797+
"access_token_headers": {
798+
"Authorization": "Basic {base64Encoder:{client_id}:{client_secret}}"
799+
}
800+
}
801+
],
802+
title="(Optional) DeclarativeOAuth Access Token Headers",
803+
)
804+
access_token_params: Optional[Dict[str, Any]] = Field(
805+
None,
806+
description="The DeclarativeOAuth Specific optional query parameters to inject while exchanging the `auth_code` to `access_token` during `completeOAuthFlow` step.\nWhen this property is provided, the query params will be encoded as `Json` and included in the outgoing API request.",
807+
examples=[
808+
{
809+
"access_token_params": {
810+
"{auth_code_key}": "{{auth_code_key}}",
811+
"{client_id_key}": "{{client_id_key}}",
812+
"{client_secret_key}": "{{client_secret_key}}",
813+
}
814+
}
815+
],
816+
title="(Optional) DeclarativeOAuth Access Token Query Params (Json Encoded)",
817+
)
818+
extract_output: List[str] = Field(
819+
...,
820+
description="The DeclarativeOAuth Specific list of strings to indicate which keys should be extracted and returned back to the input config. ",
821+
examples=[{"extract_output": ["access_token", "refresh_token", "other_field"]}],
822+
title="DeclarativeOAuth Extract Output",
823+
)
824+
state: Optional[State] = Field(
825+
None,
826+
description="The DeclarativeOAuth Specific object to provide the criteria of how the `state` query param should be constructed,\nincluding length and complexity. ",
827+
examples=[{"state": {"min": 7, "max": 128}}],
828+
title="(Optional) DeclarativeOAuth Configurable State Query Param",
829+
)
830+
client_id_key: Optional[str] = Field(
831+
None,
832+
description="The DeclarativeOAuth Specific optional override to provide the custom `client_id` key name, if required by data-provider.",
833+
examples=[{"client_id_key": "my_custom_client_id_key_name"}],
834+
title="(Optional) DeclarativeOAuth Client ID Key Override",
835+
)
836+
client_secret_key: Optional[str] = Field(
837+
None,
838+
description="The DeclarativeOAuth Specific optional override to provide the custom `client_secret` key name, if required by data-provider.",
839+
examples=[{"client_secret_key": "my_custom_client_secret_key_name"}],
840+
title="(Optional) DeclarativeOAuth Client Secret Key Override",
841+
)
842+
scope_key: Optional[str] = Field(
843+
None,
844+
description="The DeclarativeOAuth Specific optional override to provide the custom `scope` key name, if required by data-provider.",
845+
examples=[{"scope_key": "my_custom_scope_key_key_name"}],
846+
title="(Optional) DeclarativeOAuth Scope Key Override",
847+
)
848+
state_key: Optional[str] = Field(
849+
None,
850+
description="The DeclarativeOAuth Specific optional override to provide the custom `state` key name, if required by data-provider. ",
851+
examples=[{"state_key": "my_custom_state_key_key_name"}],
852+
title="(Optional) DeclarativeOAuth State Key Override",
853+
)
854+
auth_code_key: Optional[str] = Field(
855+
None,
856+
description="The DeclarativeOAuth Specific optional override to provide the custom `code` key name to something like `auth_code` or `custom_auth_code`, if required by data-provider. ",
857+
examples=[{"auth_code_key": "my_custom_auth_code_key_name"}],
858+
title="(Optional) DeclarativeOAuth Auth Code Key Override",
859+
)
860+
redirect_uri_key: Optional[str] = Field(
861+
None,
862+
description="The DeclarativeOAuth Specific optional override to provide the custom `redirect_uri` key name to something like `callback_uri`, if required by data-provider.",
863+
examples=[{"redirect_uri_key": "my_custom_redirect_uri_key_name"}],
864+
title="(Optional) DeclarativeOAuth Redirect URI Key Override",
865+
)
866+
867+
751868
class OAuthConfigSpecification(BaseModel):
752869
class Config:
753870
extra = Extra.allow
@@ -766,6 +883,11 @@ class Config:
766883
],
767884
title="OAuth user input",
768885
)
886+
oauth_connector_input_specification: Optional[OauthConnectorInputSpecification] = Field(
887+
None,
888+
description='The DeclarativeOAuth specific blob.\nPertains to the fields defined by the connector relating to the OAuth flow.\n\nInterpolation capabilities:\n- The variables placeholders are declared as `{my_var}`.\n- The nested resolution variables like `{{my_nested_var}}` is allowed as well.\n\n- The allowed interpolation context is:\n + base64Encoder - encode to `base64`, {base64Encoder:{my_var_a}:{my_var_b}}\n + base64Decorer - decode from `base64` encoded string, {base64Decoder:{my_string_variable_or_string_value}}\n + urlEncoder - encode the input string to URL-like format, {urlEncoder:https://test.host.com/endpoint}\n + urlDecorer - decode the input url-encoded string into text format, {urlDecoder:https%3A%2F%2Fairbyte.io}\n + codeChallengeS256 - get the `codeChallenge` encoded value to provide additional data-provider specific authorisation values, {codeChallengeS256:{state_value}}\n\nExamples:\n - The TikTok Marketing DeclarativeOAuth spec:\n {\n "oauth_connector_input_specification": {\n "type": "object",\n "additionalProperties": false,\n "properties": {\n "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}}",\n "access_token_url": "https://business-api.tiktok.com/open_api/v1.3/oauth2/access_token/",\n "access_token_params": {\n "{auth_code_key}": "{{auth_code_key}}",\n "{client_id_key}": "{{client_id_key}}",\n "{client_secret_key}": "{{client_secret_key}}"\n },\n "access_token_headers": {\n "Content-Type": "application/json",\n "Accept": "application/json"\n },\n "extract_output": ["data.access_token"],\n "client_id_key": "app_id",\n "client_secret_key": "secret",\n "auth_code_key": "auth_code"\n }\n }\n }',
889+
title="DeclarativeOAuth Connector Specification",
890+
)
769891
complete_oauth_output_specification: Optional[Dict[str, Any]] = Field(
770892
None,
771893
description="OAuth specific blob. This is a Json Schema used to validate Json configurations produced by the OAuth flows as they are\nreturned by the distant OAuth APIs.\nMust be a valid JSON describing the fields to merge back to `ConnectorSpecification.connectionSpecification`.\nFor each field, a special annotation `path_in_connector_config` can be specified to determine where to merge it,\nExamples:\n complete_oauth_output_specification={\n refresh_token: {\n type: string,\n path_in_connector_config: ['credentials', 'refresh_token']\n }\n }",

0 commit comments

Comments
 (0)