dlt icon indicating copy to clipboard operation
dlt copied to clipboard

rest_api: Add `OAuth2ClientCredentials` to the list of built-in auth methods

Open willi-mueller opened this issue 6 months ago • 0 comments

rest_Add OAuth2ClientCredentials to the current list of built-in auth methods.

This requires changes only in the dlt-core repo in rest_client/auth.py

Tasks:

  • [x] in sources/rest_api/typing.py: add AuthType, add OAuth2Config
  • [x] remove __init()__
  • [x] implement __post_init__()
  • [x] uncomment skip in tests/rest_api/test_configurations.py::test_auth_type_configs
  • [x] update docs

Specification:

The code should look like as follows:

@configspec
class OAuth2ClientCredentials(OAuth2AuthBase):
    """
    This class implements OAuth2 Client Credentials flow where the autorization service
    gives permission without the end user approving.
    This is often used for machine-to-machine authorization.
    The client sends its client ID and client secret to the authorization service which replies
    with a temporary access token.
    With the access token, the client can access resource services.
    """
    access_token_url: TSecretStrValue = None
    client_id: TSecretStrValue = None
    client_secret: TSecretStrValue = None
    access_token_request_data: Dict[str, Any] = None
    default_token_expiration: int = 3600
    session: Annotated[BaseSession, NotResolved()] = None

    def __post_init__(self) -> None:
        if self.access_token_request_data is None:
            self.access_token_request_data = {}

        self.token_expiry: pendulum.DateTime = pendulum.now()

        if self.session is None:
            self.session = requests.client.session

willi-mueller avatar Aug 14 '24 12:08 willi-mueller