Skip to content

Commit e941d0f

Browse files
feat(auth): add auto_login credential flow
1 parent 6f18d40 commit e941d0f

26 files changed

+783
-665
lines changed

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 90
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-20fac779e9e13dc9421e467be31dbf274c39072ba0c01528ba451b48698d43c1.yml
3-
openapi_spec_hash: c3fc5784297ccc8f729326b62000d1f0
4-
config_hash: e47e015528251ee83e30367dbbb51044
1+
configured_endpoints: 89
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-8d66dbedea5b240936b338809f272568ca84a452fc13dbda835479f2ec068b41.yml
3+
openapi_spec_hash: 7c499bfce2e996f1fff5e7791cea390e
4+
config_hash: fcc2db3ed48ab4e8d1b588d31d394a23

api.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,13 @@ Types:
287287

288288
```python
289289
from kernel.types.agents import (
290-
AgentAuthDiscoverResponse,
291290
AgentAuthInvocationResponse,
292291
AgentAuthSubmitResponse,
293292
AuthAgent,
294293
AuthAgentCreateRequest,
295294
AuthAgentInvocationCreateRequest,
296295
AuthAgentInvocationCreateResponse,
297296
DiscoveredField,
298-
ReauthResponse,
299297
)
300298
```
301299

@@ -305,7 +303,6 @@ Methods:
305303
- <code title="get /agents/auth/{id}">client.agents.auth.<a href="./src/kernel/resources/agents/auth/auth.py">retrieve</a>(id) -> <a href="./src/kernel/types/agents/auth_agent.py">AuthAgent</a></code>
306304
- <code title="get /agents/auth">client.agents.auth.<a href="./src/kernel/resources/agents/auth/auth.py">list</a>(\*\*<a href="src/kernel/types/agents/auth_list_params.py">params</a>) -> <a href="./src/kernel/types/agents/auth_agent.py">SyncOffsetPagination[AuthAgent]</a></code>
307305
- <code title="delete /agents/auth/{id}">client.agents.auth.<a href="./src/kernel/resources/agents/auth/auth.py">delete</a>(id) -> None</code>
308-
- <code title="post /agents/auth/{id}/reauth">client.agents.auth.<a href="./src/kernel/resources/agents/auth/auth.py">reauth</a>(id) -> <a href="./src/kernel/types/agents/reauth_response.py">ReauthResponse</a></code>
309306

310307
### Invocations
311308

@@ -319,7 +316,6 @@ Methods:
319316

320317
- <code title="post /agents/auth/invocations">client.agents.auth.invocations.<a href="./src/kernel/resources/agents/auth/invocations.py">create</a>(\*\*<a href="src/kernel/types/agents/auth/invocation_create_params.py">params</a>) -> <a href="./src/kernel/types/agents/auth_agent_invocation_create_response.py">AuthAgentInvocationCreateResponse</a></code>
321318
- <code title="get /agents/auth/invocations/{invocation_id}">client.agents.auth.invocations.<a href="./src/kernel/resources/agents/auth/invocations.py">retrieve</a>(invocation_id) -> <a href="./src/kernel/types/agents/agent_auth_invocation_response.py">AgentAuthInvocationResponse</a></code>
322-
- <code title="post /agents/auth/invocations/{invocation_id}/discover">client.agents.auth.invocations.<a href="./src/kernel/resources/agents/auth/invocations.py">discover</a>(invocation_id, \*\*<a href="src/kernel/types/agents/auth/invocation_discover_params.py">params</a>) -> <a href="./src/kernel/types/agents/agent_auth_discover_response.py">AgentAuthDiscoverResponse</a></code>
323319
- <code title="post /agents/auth/invocations/{invocation_id}/exchange">client.agents.auth.invocations.<a href="./src/kernel/resources/agents/auth/invocations.py">exchange</a>(invocation_id, \*\*<a href="src/kernel/types/agents/auth/invocation_exchange_params.py">params</a>) -> <a href="./src/kernel/types/agents/auth/invocation_exchange_response.py">InvocationExchangeResponse</a></code>
324320
- <code title="post /agents/auth/invocations/{invocation_id}/submit">client.agents.auth.invocations.<a href="./src/kernel/resources/agents/auth/invocations.py">submit</a>(invocation_id, \*\*<a href="src/kernel/types/agents/auth/invocation_submit_params.py">params</a>) -> <a href="./src/kernel/types/agents/agent_auth_submit_response.py">AgentAuthSubmitResponse</a></code>
325321

@@ -328,13 +324,19 @@ Methods:
328324
Types:
329325

330326
```python
331-
from kernel.types import CreateCredentialRequest, Credential, UpdateCredentialRequest
327+
from kernel.types import (
328+
CreateCredentialRequest,
329+
Credential,
330+
UpdateCredentialRequest,
331+
CredentialTotpCodeResponse,
332+
)
332333
```
333334

334335
Methods:
335336

336337
- <code title="post /credentials">client.credentials.<a href="./src/kernel/resources/credentials.py">create</a>(\*\*<a href="src/kernel/types/credential_create_params.py">params</a>) -> <a href="./src/kernel/types/credential.py">Credential</a></code>
337-
- <code title="get /credentials/{id}">client.credentials.<a href="./src/kernel/resources/credentials.py">retrieve</a>(id) -> <a href="./src/kernel/types/credential.py">Credential</a></code>
338-
- <code title="patch /credentials/{id}">client.credentials.<a href="./src/kernel/resources/credentials.py">update</a>(id, \*\*<a href="src/kernel/types/credential_update_params.py">params</a>) -> <a href="./src/kernel/types/credential.py">Credential</a></code>
338+
- <code title="get /credentials/{id_or_name}">client.credentials.<a href="./src/kernel/resources/credentials.py">retrieve</a>(id_or_name) -> <a href="./src/kernel/types/credential.py">Credential</a></code>
339+
- <code title="patch /credentials/{id_or_name}">client.credentials.<a href="./src/kernel/resources/credentials.py">update</a>(id_or_name, \*\*<a href="src/kernel/types/credential_update_params.py">params</a>) -> <a href="./src/kernel/types/credential.py">Credential</a></code>
339340
- <code title="get /credentials">client.credentials.<a href="./src/kernel/resources/credentials.py">list</a>(\*\*<a href="src/kernel/types/credential_list_params.py">params</a>) -> <a href="./src/kernel/types/credential.py">SyncOffsetPagination[Credential]</a></code>
340-
- <code title="delete /credentials/{id}">client.credentials.<a href="./src/kernel/resources/credentials.py">delete</a>(id) -> None</code>
341+
- <code title="delete /credentials/{id_or_name}">client.credentials.<a href="./src/kernel/resources/credentials.py">delete</a>(id_or_name) -> None</code>
342+
- <code title="get /credentials/{id_or_name}/totp-code">client.credentials.<a href="./src/kernel/resources/credentials.py">totp_code</a>(id_or_name) -> <a href="./src/kernel/types/credential_totp_code_response.py">CredentialTotpCodeResponse</a></code>

src/kernel/resources/agents/auth/auth.py

Lines changed: 29 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import httpx
66

7-
from ...._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given
7+
from ...._types import Body, Omit, Query, Headers, NoneType, NotGiven, SequenceNotStr, omit, not_given
88
from ...._utils import maybe_transform, async_maybe_transform
99
from ...._compat import cached_property
1010
from .invocations import (
@@ -26,7 +26,6 @@
2626
from ...._base_client import AsyncPaginator, make_request_options
2727
from ....types.agents import auth_list_params, auth_create_params
2828
from ....types.agents.auth_agent import AuthAgent
29-
from ....types.agents.reauth_response import ReauthResponse
3029

3130
__all__ = ["AuthResource", "AsyncAuthResource"]
3231

@@ -58,8 +57,9 @@ def with_streaming_response(self) -> AuthResourceWithStreamingResponse:
5857
def create(
5958
self,
6059
*,
60+
domain: str,
6161
profile_name: str,
62-
target_domain: str,
62+
allowed_domains: SequenceNotStr[str] | Omit = omit,
6363
credential_name: str | Omit = omit,
6464
login_url: str | Omit = omit,
6565
proxy: auth_create_params.Proxy | Omit = omit,
@@ -77,9 +77,13 @@ def create(
7777
invocation - use POST /agents/auth/invocations to start an auth flow.
7878
7979
Args:
80+
domain: Domain for authentication
81+
8082
profile_name: Name of the profile to use for this auth agent
8183
82-
target_domain: Target domain for authentication
84+
allowed_domains: Additional domains that are valid for this auth agent's authentication flow
85+
(besides the primary domain). Useful when login pages redirect to different
86+
domains.
8387
8488
credential_name: Optional name of an existing credential to use for this auth agent. If provided,
8589
the credential will be linked to the agent and its values will be used to
@@ -102,8 +106,9 @@ def create(
102106
"/agents/auth",
103107
body=maybe_transform(
104108
{
109+
"domain": domain,
105110
"profile_name": profile_name,
106-
"target_domain": target_domain,
111+
"allowed_domains": allowed_domains,
107112
"credential_name": credential_name,
108113
"login_url": login_url,
109114
"proxy": proxy,
@@ -154,10 +159,10 @@ def retrieve(
154159
def list(
155160
self,
156161
*,
162+
domain: str | Omit = omit,
157163
limit: int | Omit = omit,
158164
offset: int | Omit = omit,
159165
profile_name: str | Omit = omit,
160-
target_domain: str | Omit = omit,
161166
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
162167
# The extra values given here take precedence over values defined on the client or passed to this method.
163168
extra_headers: Headers | None = None,
@@ -166,17 +171,17 @@ def list(
166171
timeout: float | httpx.Timeout | None | NotGiven = not_given,
167172
) -> SyncOffsetPagination[AuthAgent]:
168173
"""
169-
List auth agents with optional filters for profile_name and target_domain.
174+
List auth agents with optional filters for profile_name and domain.
170175
171176
Args:
177+
domain: Filter by domain
178+
172179
limit: Maximum number of results to return
173180
174181
offset: Number of results to skip
175182
176183
profile_name: Filter by profile name
177184
178-
target_domain: Filter by target domain
179-
180185
extra_headers: Send extra headers
181186
182187
extra_query: Add additional query parameters to the request
@@ -195,10 +200,10 @@ def list(
195200
timeout=timeout,
196201
query=maybe_transform(
197202
{
203+
"domain": domain,
198204
"limit": limit,
199205
"offset": offset,
200206
"profile_name": profile_name,
201-
"target_domain": target_domain,
202207
},
203208
auth_list_params.AuthListParams,
204209
),
@@ -245,42 +250,6 @@ def delete(
245250
cast_to=NoneType,
246251
)
247252

248-
def reauth(
249-
self,
250-
id: str,
251-
*,
252-
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
253-
# The extra values given here take precedence over values defined on the client or passed to this method.
254-
extra_headers: Headers | None = None,
255-
extra_query: Query | None = None,
256-
extra_body: Body | None = None,
257-
timeout: float | httpx.Timeout | None | NotGiven = not_given,
258-
) -> ReauthResponse:
259-
"""
260-
Triggers automatic re-authentication for an auth agent using stored credentials.
261-
Requires the auth agent to have a linked credential, stored selectors, and
262-
login_url. Returns immediately with status indicating whether re-auth was
263-
started.
264-
265-
Args:
266-
extra_headers: Send extra headers
267-
268-
extra_query: Add additional query parameters to the request
269-
270-
extra_body: Add additional JSON properties to the request
271-
272-
timeout: Override the client-level default timeout for this request, in seconds
273-
"""
274-
if not id:
275-
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
276-
return self._post(
277-
f"/agents/auth/{id}/reauth",
278-
options=make_request_options(
279-
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
280-
),
281-
cast_to=ReauthResponse,
282-
)
283-
284253

285254
class AsyncAuthResource(AsyncAPIResource):
286255
@cached_property
@@ -309,8 +278,9 @@ def with_streaming_response(self) -> AsyncAuthResourceWithStreamingResponse:
309278
async def create(
310279
self,
311280
*,
281+
domain: str,
312282
profile_name: str,
313-
target_domain: str,
283+
allowed_domains: SequenceNotStr[str] | Omit = omit,
314284
credential_name: str | Omit = omit,
315285
login_url: str | Omit = omit,
316286
proxy: auth_create_params.Proxy | Omit = omit,
@@ -328,9 +298,13 @@ async def create(
328298
invocation - use POST /agents/auth/invocations to start an auth flow.
329299
330300
Args:
301+
domain: Domain for authentication
302+
331303
profile_name: Name of the profile to use for this auth agent
332304
333-
target_domain: Target domain for authentication
305+
allowed_domains: Additional domains that are valid for this auth agent's authentication flow
306+
(besides the primary domain). Useful when login pages redirect to different
307+
domains.
334308
335309
credential_name: Optional name of an existing credential to use for this auth agent. If provided,
336310
the credential will be linked to the agent and its values will be used to
@@ -353,8 +327,9 @@ async def create(
353327
"/agents/auth",
354328
body=await async_maybe_transform(
355329
{
330+
"domain": domain,
356331
"profile_name": profile_name,
357-
"target_domain": target_domain,
332+
"allowed_domains": allowed_domains,
358333
"credential_name": credential_name,
359334
"login_url": login_url,
360335
"proxy": proxy,
@@ -405,10 +380,10 @@ async def retrieve(
405380
def list(
406381
self,
407382
*,
383+
domain: str | Omit = omit,
408384
limit: int | Omit = omit,
409385
offset: int | Omit = omit,
410386
profile_name: str | Omit = omit,
411-
target_domain: str | Omit = omit,
412387
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
413388
# The extra values given here take precedence over values defined on the client or passed to this method.
414389
extra_headers: Headers | None = None,
@@ -417,17 +392,17 @@ def list(
417392
timeout: float | httpx.Timeout | None | NotGiven = not_given,
418393
) -> AsyncPaginator[AuthAgent, AsyncOffsetPagination[AuthAgent]]:
419394
"""
420-
List auth agents with optional filters for profile_name and target_domain.
395+
List auth agents with optional filters for profile_name and domain.
421396
422397
Args:
398+
domain: Filter by domain
399+
423400
limit: Maximum number of results to return
424401
425402
offset: Number of results to skip
426403
427404
profile_name: Filter by profile name
428405
429-
target_domain: Filter by target domain
430-
431406
extra_headers: Send extra headers
432407
433408
extra_query: Add additional query parameters to the request
@@ -446,10 +421,10 @@ def list(
446421
timeout=timeout,
447422
query=maybe_transform(
448423
{
424+
"domain": domain,
449425
"limit": limit,
450426
"offset": offset,
451427
"profile_name": profile_name,
452-
"target_domain": target_domain,
453428
},
454429
auth_list_params.AuthListParams,
455430
),
@@ -496,42 +471,6 @@ async def delete(
496471
cast_to=NoneType,
497472
)
498473

499-
async def reauth(
500-
self,
501-
id: str,
502-
*,
503-
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
504-
# The extra values given here take precedence over values defined on the client or passed to this method.
505-
extra_headers: Headers | None = None,
506-
extra_query: Query | None = None,
507-
extra_body: Body | None = None,
508-
timeout: float | httpx.Timeout | None | NotGiven = not_given,
509-
) -> ReauthResponse:
510-
"""
511-
Triggers automatic re-authentication for an auth agent using stored credentials.
512-
Requires the auth agent to have a linked credential, stored selectors, and
513-
login_url. Returns immediately with status indicating whether re-auth was
514-
started.
515-
516-
Args:
517-
extra_headers: Send extra headers
518-
519-
extra_query: Add additional query parameters to the request
520-
521-
extra_body: Add additional JSON properties to the request
522-
523-
timeout: Override the client-level default timeout for this request, in seconds
524-
"""
525-
if not id:
526-
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
527-
return await self._post(
528-
f"/agents/auth/{id}/reauth",
529-
options=make_request_options(
530-
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
531-
),
532-
cast_to=ReauthResponse,
533-
)
534-
535474

536475
class AuthResourceWithRawResponse:
537476
def __init__(self, auth: AuthResource) -> None:
@@ -549,9 +488,6 @@ def __init__(self, auth: AuthResource) -> None:
549488
self.delete = to_raw_response_wrapper(
550489
auth.delete,
551490
)
552-
self.reauth = to_raw_response_wrapper(
553-
auth.reauth,
554-
)
555491

556492
@cached_property
557493
def invocations(self) -> InvocationsResourceWithRawResponse:
@@ -574,9 +510,6 @@ def __init__(self, auth: AsyncAuthResource) -> None:
574510
self.delete = async_to_raw_response_wrapper(
575511
auth.delete,
576512
)
577-
self.reauth = async_to_raw_response_wrapper(
578-
auth.reauth,
579-
)
580513

581514
@cached_property
582515
def invocations(self) -> AsyncInvocationsResourceWithRawResponse:
@@ -599,9 +532,6 @@ def __init__(self, auth: AuthResource) -> None:
599532
self.delete = to_streamed_response_wrapper(
600533
auth.delete,
601534
)
602-
self.reauth = to_streamed_response_wrapper(
603-
auth.reauth,
604-
)
605535

606536
@cached_property
607537
def invocations(self) -> InvocationsResourceWithStreamingResponse:
@@ -624,9 +554,6 @@ def __init__(self, auth: AsyncAuthResource) -> None:
624554
self.delete = async_to_streamed_response_wrapper(
625555
auth.delete,
626556
)
627-
self.reauth = async_to_streamed_response_wrapper(
628-
auth.reauth,
629-
)
630557

631558
@cached_property
632559
def invocations(self) -> AsyncInvocationsResourceWithStreamingResponse:

0 commit comments

Comments
 (0)