Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions airbyte_cdk/sources/declarative/auth/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
from dataclasses import InitVar, dataclass, field
from datetime import datetime, timedelta
from typing import Any, List, Mapping, Optional, Union
from typing import Any, List, Mapping, Optional, Tuple, Union

from airbyte_cdk.sources.declarative.auth.declarative_authenticator import DeclarativeAuthenticator
from airbyte_cdk.sources.declarative.interpolation.interpolated_boolean import InterpolatedBoolean
Expand Down Expand Up @@ -46,6 +46,9 @@ class DeclarativeOauth2Authenticator(AbstractOauth2Authenticator, DeclarativeAut
refresh_request_headers (Optional[Mapping[str, Any]]): The request headers to send in the refresh request
grant_type: The grant_type to request for access_token. If set to refresh_token, the refresh_token parameter has to be provided
message_repository (MessageRepository): the message repository used to emit logs on HTTP requests
refresh_token_error_status_codes (Tuple[int, ...]): Status codes to identify refresh token errors in response
refresh_token_error_key (str): Key to identify refresh token error in response
refresh_token_error_values (Tuple[str, ...]): List of values to check for exception during token refresh process
"""

config: Mapping[str, Any]
Expand All @@ -72,9 +75,16 @@ class DeclarativeOauth2Authenticator(AbstractOauth2Authenticator, DeclarativeAut
message_repository: MessageRepository = NoopMessageRepository()
profile_assertion: Optional[DeclarativeAuthenticator] = None
use_profile_assertion: Optional[Union[InterpolatedBoolean, str, bool]] = False
refresh_token_error_status_codes: Tuple[int, ...] = ()
refresh_token_error_key: str = ""
refresh_token_error_values: Tuple[str, ...] = ()

def __post_init__(self, parameters: Mapping[str, Any]) -> None:
super().__init__()
super().__init__(
refresh_token_error_status_codes=self.refresh_token_error_status_codes,
refresh_token_error_key=self.refresh_token_error_key,
refresh_token_error_values=self.refresh_token_error_values,
)
if self.token_refresh_endpoint is not None:
self._token_refresh_endpoint: Optional[InterpolatedString] = InterpolatedString.create(
self.token_refresh_endpoint, parameters=parameters
Expand Down
28 changes: 25 additions & 3 deletions airbyte_cdk/sources/declarative/declarative_component_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,28 @@ definitions:
type: string
examples:
- "%Y-%m-%d %H:%M:%S.%f+00:00"
refresh_token_error_status_codes:
title: Refresh Token Error Status Codes
description: Status Codes to Identify refresh token error in response (Refresh Token Error Key and Refresh Token Error Values should be also specified). Responses with one of the error status code and containing an error value will be flagged as a config error
type: array
items:
type: integer
examples:
- [400, 500]
refresh_token_error_key:
title: Refresh Token Error Key
description: Key to Identify refresh token error in response (Refresh Token Error Status Codes and Refresh Token Error Values should be also specified).
type: string
examples:
- "error"
refresh_token_error_values:
title: Refresh Token Error Values
description: 'List of values to check for exception during token refresh process. Used to check if the error found in the response matches the key from the Refresh Token Error Key field (e.g. response={"error": "invalid_grant"}). Only responses with one of the error status code and containing an error value will be flagged as a config error'
type: array
items:
type: string
examples:
- ["invalid_grant", "invalid_permissions"]
refresh_token_updater:
title: Refresh Token Updater
description: When the refresh token updater is defined, new refresh tokens, access tokens and the access token expiry date are written back from the authentication response to the config object. This is important if the refresh token can only used once.
Expand Down Expand Up @@ -1468,7 +1490,7 @@ definitions:
examples:
- ["credentials", "token_expiry_date"]
refresh_token_error_status_codes:
title: Refresh Token Error Status Codes
title: (Deprecated - Use the same field on the OAuthAuthenticator level) Refresh Token Error Status Codes
description: Status Codes to Identify refresh token error in response (Refresh Token Error Key and Refresh Token Error Values should be also specified). Responses with one of the error status code and containing an error value will be flagged as a config error
type: array
items:
Expand All @@ -1477,14 +1499,14 @@ definitions:
examples:
- [400, 500]
refresh_token_error_key:
title: Refresh Token Error Key
title: (Deprecated - Use the same field on the OAuthAuthenticator level) Refresh Token Error Key
description: Key to Identify refresh token error in response (Refresh Token Error Status Codes and Refresh Token Error Values should be also specified).
type: string
default: ""
examples:
- "error"
refresh_token_error_values:
title: Refresh Token Error Values
title: (Deprecated - Use the same field on the OAuthAuthenticator level) Refresh Token Error Values
description: 'List of values to check for exception during token refresh process. Used to check if the error found in the response matches the key from the Refresh Token Error Key field (e.g. response={"error": "invalid_grant"}). Only responses with one of the error status code and containing an error value will be flagged as a config error'
type: array
items:
Expand Down
Loading
Loading