diff --git a/api.md b/api.md index 7670466d..62d3fb7c 100644 --- a/api.md +++ b/api.md @@ -224,12 +224,6 @@ Methods: - client.jobs.manual.retrieve(job_id) -> ManualAsyncJob -# Auth - -Methods: - -- client.auth.create_token(\*\*params) -> CreateAccessTokenResponse - # Sandbox ## Connections diff --git a/src/finch/_client.py b/src/finch/_client.py index 6e220ad4..a49d3035 100644 --- a/src/finch/_client.py +++ b/src/finch/_client.py @@ -58,7 +58,6 @@ class Finch(SyncAPIClient): webhooks: resources.Webhooks request_forwarding: resources.RequestForwarding jobs: resources.Jobs - auth: resources.Auth sandbox: resources.Sandbox with_raw_response: FinchWithRawResponse @@ -66,6 +65,8 @@ class Finch(SyncAPIClient): access_token: str | None client_id: str | None client_secret: str | None + sandbox_client_id: str | None + sandbox_client_secret: str | None webhook_secret: str | None def __init__( @@ -74,6 +75,8 @@ def __init__( access_token: str | None = None, client_id: str | None = None, client_secret: str | None = None, + sandbox_client_id: str | None = None, + sandbox_client_secret: str | None = None, webhook_secret: str | None = None, base_url: str | httpx.URL | None = None, timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN, @@ -103,6 +106,8 @@ def __init__( This automatically infers the following arguments from their corresponding environment variables if they are not provided: - `client_id` from `FINCH_CLIENT_ID` - `client_secret` from `FINCH_CLIENT_SECRET` + - `sandbox_client_id` from `FINCH_SANDBOX_CLIENT_ID` + - `sandbox_client_secret` from `FINCH_SANDBOX_CLIENT_SECRET` - `webhook_secret` from `FINCH_WEBHOOK_SECRET` """ self.access_token = access_token @@ -115,6 +120,14 @@ def __init__( client_secret = os.environ.get("FINCH_CLIENT_SECRET") self.client_secret = client_secret + if sandbox_client_id is None: + sandbox_client_id = os.environ.get("FINCH_SANDBOX_CLIENT_ID") + self.sandbox_client_id = sandbox_client_id + + if sandbox_client_secret is None: + sandbox_client_secret = os.environ.get("FINCH_SANDBOX_CLIENT_SECRET") + self.sandbox_client_secret = sandbox_client_secret + if webhook_secret is None: webhook_secret = os.environ.get("FINCH_WEBHOOK_SECRET") self.webhook_secret = webhook_secret @@ -145,7 +158,6 @@ def __init__( self.webhooks = resources.Webhooks(self) self.request_forwarding = resources.RequestForwarding(self) self.jobs = resources.Jobs(self) - self.auth = resources.Auth(self) self.sandbox = resources.Sandbox(self) self.with_raw_response = FinchWithRawResponse(self) @@ -189,6 +201,8 @@ def copy( access_token: str | None = None, client_id: str | None = None, client_secret: str | None = None, + sandbox_client_id: str | None = None, + sandbox_client_secret: str | None = None, webhook_secret: str | None = None, base_url: str | httpx.URL | None = None, timeout: float | Timeout | None | NotGiven = NOT_GIVEN, @@ -244,6 +258,8 @@ def copy( access_token=access_token or self.access_token, client_id=client_id or self.client_id, client_secret=client_secret or self.client_secret, + sandbox_client_id=sandbox_client_id or self.sandbox_client_id, + sandbox_client_secret=sandbox_client_secret or self.sandbox_client_secret, webhook_secret=webhook_secret or self.webhook_secret, base_url=base_url or self.base_url, timeout=self.timeout if isinstance(timeout, NotGiven) else timeout, @@ -369,7 +385,6 @@ class AsyncFinch(AsyncAPIClient): webhooks: resources.AsyncWebhooks request_forwarding: resources.AsyncRequestForwarding jobs: resources.AsyncJobs - auth: resources.AsyncAuth sandbox: resources.AsyncSandbox with_raw_response: AsyncFinchWithRawResponse @@ -377,6 +392,8 @@ class AsyncFinch(AsyncAPIClient): access_token: str | None client_id: str | None client_secret: str | None + sandbox_client_id: str | None + sandbox_client_secret: str | None webhook_secret: str | None def __init__( @@ -385,6 +402,8 @@ def __init__( access_token: str | None = None, client_id: str | None = None, client_secret: str | None = None, + sandbox_client_id: str | None = None, + sandbox_client_secret: str | None = None, webhook_secret: str | None = None, base_url: str | httpx.URL | None = None, timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN, @@ -414,6 +433,8 @@ def __init__( This automatically infers the following arguments from their corresponding environment variables if they are not provided: - `client_id` from `FINCH_CLIENT_ID` - `client_secret` from `FINCH_CLIENT_SECRET` + - `sandbox_client_id` from `FINCH_SANDBOX_CLIENT_ID` + - `sandbox_client_secret` from `FINCH_SANDBOX_CLIENT_SECRET` - `webhook_secret` from `FINCH_WEBHOOK_SECRET` """ self.access_token = access_token @@ -426,6 +447,14 @@ def __init__( client_secret = os.environ.get("FINCH_CLIENT_SECRET") self.client_secret = client_secret + if sandbox_client_id is None: + sandbox_client_id = os.environ.get("FINCH_SANDBOX_CLIENT_ID") + self.sandbox_client_id = sandbox_client_id + + if sandbox_client_secret is None: + sandbox_client_secret = os.environ.get("FINCH_SANDBOX_CLIENT_SECRET") + self.sandbox_client_secret = sandbox_client_secret + if webhook_secret is None: webhook_secret = os.environ.get("FINCH_WEBHOOK_SECRET") self.webhook_secret = webhook_secret @@ -456,7 +485,6 @@ def __init__( self.webhooks = resources.AsyncWebhooks(self) self.request_forwarding = resources.AsyncRequestForwarding(self) self.jobs = resources.AsyncJobs(self) - self.auth = resources.AsyncAuth(self) self.sandbox = resources.AsyncSandbox(self) self.with_raw_response = AsyncFinchWithRawResponse(self) @@ -500,6 +528,8 @@ def copy( access_token: str | None = None, client_id: str | None = None, client_secret: str | None = None, + sandbox_client_id: str | None = None, + sandbox_client_secret: str | None = None, webhook_secret: str | None = None, base_url: str | httpx.URL | None = None, timeout: float | Timeout | None | NotGiven = NOT_GIVEN, @@ -555,6 +585,8 @@ def copy( access_token=access_token or self.access_token, client_id=client_id or self.client_id, client_secret=client_secret or self.client_secret, + sandbox_client_id=sandbox_client_id or self.sandbox_client_id, + sandbox_client_secret=sandbox_client_secret or self.sandbox_client_secret, webhook_secret=webhook_secret or self.webhook_secret, base_url=base_url or self.base_url, timeout=self.timeout if isinstance(timeout, NotGiven) else timeout, @@ -680,7 +712,6 @@ def __init__(self, client: Finch) -> None: self.account = resources.AccountWithRawResponse(client.account) self.request_forwarding = resources.RequestForwardingWithRawResponse(client.request_forwarding) self.jobs = resources.JobsWithRawResponse(client.jobs) - self.auth = resources.AuthWithRawResponse(client.auth) self.sandbox = resources.SandboxWithRawResponse(client.sandbox) @@ -692,7 +723,6 @@ def __init__(self, client: AsyncFinch) -> None: self.account = resources.AsyncAccountWithRawResponse(client.account) self.request_forwarding = resources.AsyncRequestForwardingWithRawResponse(client.request_forwarding) self.jobs = resources.AsyncJobsWithRawResponse(client.jobs) - self.auth = resources.AsyncAuthWithRawResponse(client.auth) self.sandbox = resources.AsyncSandboxWithRawResponse(client.sandbox) diff --git a/src/finch/resources/__init__.py b/src/finch/resources/__init__.py index f5912eb0..b3c215be 100644 --- a/src/finch/resources/__init__.py +++ b/src/finch/resources/__init__.py @@ -1,6 +1,5 @@ # File generated from our OpenAPI spec by Stainless. -from .auth import Auth, AsyncAuth, AuthWithRawResponse, AsyncAuthWithRawResponse from .hris import HRIS, AsyncHRIS, HRISWithRawResponse, AsyncHRISWithRawResponse from .jobs import Jobs, AsyncJobs, JobsWithRawResponse, AsyncJobsWithRawResponse from .account import Account, AsyncAccount, AccountWithRawResponse, AsyncAccountWithRawResponse @@ -47,10 +46,6 @@ "AsyncJobs", "JobsWithRawResponse", "AsyncJobsWithRawResponse", - "Auth", - "AsyncAuth", - "AuthWithRawResponse", - "AsyncAuthWithRawResponse", "Sandbox", "AsyncSandbox", "SandboxWithRawResponse", diff --git a/src/finch/resources/auth.py b/src/finch/resources/auth.py deleted file mode 100644 index 1a7bd991..00000000 --- a/src/finch/resources/auth.py +++ /dev/null @@ -1,129 +0,0 @@ -# File generated from our OpenAPI spec by Stainless. - -from __future__ import annotations - -import httpx - -from ..types import CreateAccessTokenResponse, auth_create_token_params -from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven -from .._utils import maybe_transform -from .._compat import cached_property -from .._resource import SyncAPIResource, AsyncAPIResource -from .._response import to_raw_response_wrapper, async_to_raw_response_wrapper -from .._base_client import ( - make_request_options, -) - -__all__ = ["Auth", "AsyncAuth"] - - -class Auth(SyncAPIResource): - @cached_property - def with_raw_response(self) -> AuthWithRawResponse: - return AuthWithRawResponse(self) - - def create_token( - self, - *, - client_id: str, - client_secret: str, - code: str, - redirect_uri: str, - # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. - # The extra values given here take precedence over values defined on the client or passed to this method. - extra_headers: Headers | None = None, - extra_query: Query | None = None, - extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> CreateAccessTokenResponse: - """ - Exchange the authorization code for an access token - - Args: - extra_headers: Send extra headers - - extra_query: Add additional query parameters to the request - - extra_body: Add additional JSON properties to the request - - timeout: Override the client-level default timeout for this request, in seconds - """ - return self._post( - "/auth/token", - body=maybe_transform( - { - "client_id": client_id, - "client_secret": client_secret, - "code": code, - "redirect_uri": redirect_uri, - }, - auth_create_token_params.AuthCreateTokenParams, - ), - options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout - ), - cast_to=CreateAccessTokenResponse, - ) - - -class AsyncAuth(AsyncAPIResource): - @cached_property - def with_raw_response(self) -> AsyncAuthWithRawResponse: - return AsyncAuthWithRawResponse(self) - - async def create_token( - self, - *, - client_id: str, - client_secret: str, - code: str, - redirect_uri: str, - # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. - # The extra values given here take precedence over values defined on the client or passed to this method. - extra_headers: Headers | None = None, - extra_query: Query | None = None, - extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> CreateAccessTokenResponse: - """ - Exchange the authorization code for an access token - - Args: - extra_headers: Send extra headers - - extra_query: Add additional query parameters to the request - - extra_body: Add additional JSON properties to the request - - timeout: Override the client-level default timeout for this request, in seconds - """ - return await self._post( - "/auth/token", - body=maybe_transform( - { - "client_id": client_id, - "client_secret": client_secret, - "code": code, - "redirect_uri": redirect_uri, - }, - auth_create_token_params.AuthCreateTokenParams, - ), - options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout - ), - cast_to=CreateAccessTokenResponse, - ) - - -class AuthWithRawResponse: - def __init__(self, auth: Auth) -> None: - self.create_token = to_raw_response_wrapper( - auth.create_token, - ) - - -class AsyncAuthWithRawResponse: - def __init__(self, auth: AsyncAuth) -> None: - self.create_token = async_to_raw_response_wrapper( - auth.create_token, - ) diff --git a/src/finch/types/__init__.py b/src/finch/types/__init__.py index f9898554..3519a122 100644 --- a/src/finch/types/__init__.py +++ b/src/finch/types/__init__.py @@ -17,7 +17,6 @@ from .introspection import Introspection as Introspection from .location_param import LocationParam as LocationParam from .disconnect_response import DisconnectResponse as DisconnectResponse -from .auth_create_token_params import AuthCreateTokenParams as AuthCreateTokenParams from .access_token_create_params import AccessTokenCreateParams as AccessTokenCreateParams from .create_access_token_response import CreateAccessTokenResponse as CreateAccessTokenResponse from .request_forwarding_forward_params import RequestForwardingForwardParams as RequestForwardingForwardParams diff --git a/src/finch/types/auth_create_token_params.py b/src/finch/types/auth_create_token_params.py deleted file mode 100644 index 9cce752f..00000000 --- a/src/finch/types/auth_create_token_params.py +++ /dev/null @@ -1,17 +0,0 @@ -# File generated from our OpenAPI spec by Stainless. - -from __future__ import annotations - -from typing_extensions import Required, TypedDict - -__all__ = ["AuthCreateTokenParams"] - - -class AuthCreateTokenParams(TypedDict, total=False): - client_id: Required[str] - - client_secret: Required[str] - - code: Required[str] - - redirect_uri: Required[str] diff --git a/tests/api_resources/test_auth.py b/tests/api_resources/test_auth.py deleted file mode 100644 index f826ee79..00000000 --- a/tests/api_resources/test_auth.py +++ /dev/null @@ -1,71 +0,0 @@ -# File generated from our OpenAPI spec by Stainless. - -from __future__ import annotations - -import os - -import pytest - -from finch import Finch, AsyncFinch -from finch.types import CreateAccessTokenResponse -from tests.utils import assert_matches_type -from finch._client import Finch, AsyncFinch - -base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") -access_token = "My Access Token" - - -class TestAuth: - strict_client = Finch(base_url=base_url, access_token=access_token, _strict_response_validation=True) - loose_client = Finch(base_url=base_url, access_token=access_token, _strict_response_validation=False) - parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"]) - - @parametrize - def test_method_create_token(self, client: Finch) -> None: - auth = client.auth.create_token( - client_id="", - client_secret="", - code="", - redirect_uri="https://example.com", - ) - assert_matches_type(CreateAccessTokenResponse, auth, path=["response"]) - - @parametrize - def test_raw_response_create_token(self, client: Finch) -> None: - response = client.auth.with_raw_response.create_token( - client_id="", - client_secret="", - code="", - redirect_uri="https://example.com", - ) - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - auth = response.parse() - assert_matches_type(CreateAccessTokenResponse, auth, path=["response"]) - - -class TestAsyncAuth: - strict_client = AsyncFinch(base_url=base_url, access_token=access_token, _strict_response_validation=True) - loose_client = AsyncFinch(base_url=base_url, access_token=access_token, _strict_response_validation=False) - parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"]) - - @parametrize - async def test_method_create_token(self, client: AsyncFinch) -> None: - auth = await client.auth.create_token( - client_id="", - client_secret="", - code="", - redirect_uri="https://example.com", - ) - assert_matches_type(CreateAccessTokenResponse, auth, path=["response"]) - - @parametrize - async def test_raw_response_create_token(self, client: AsyncFinch) -> None: - response = await client.auth.with_raw_response.create_token( - client_id="", - client_secret="", - code="", - redirect_uri="https://example.com", - ) - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - auth = response.parse() - assert_matches_type(CreateAccessTokenResponse, auth, path=["response"])