-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathauth.ts
More file actions
524 lines (452 loc) · 12.3 KB
/
auth.ts
File metadata and controls
524 lines (452 loc) · 12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../../../core/resource';
import * as InvocationsAPI from './invocations';
import {
InvocationCreateParams,
InvocationExchangeParams,
InvocationExchangeResponse,
InvocationSubmitParams,
Invocations,
} from './invocations';
import { APIPromise } from '../../../core/api-promise';
import { OffsetPagination, type OffsetPaginationParams, PagePromise } from '../../../core/pagination';
import { buildHeaders } from '../../../internal/headers';
import { RequestOptions } from '../../../internal/request-options';
import { path } from '../../../internal/utils/path';
export class Auth extends APIResource {
invocations: InvocationsAPI.Invocations = new InvocationsAPI.Invocations(this._client);
/**
* Creates a new auth agent for the specified domain and profile combination, or
* returns an existing one if it already exists. This is idempotent - calling with
* the same domain and profile will return the same agent. Does NOT start an
* invocation - use POST /agents/auth/invocations to start an auth flow.
*
* @example
* ```ts
* const authAgent = await client.agents.auth.create({
* domain: 'netflix.com',
* profile_name: 'user-123',
* });
* ```
*/
create(body: AuthCreateParams, options?: RequestOptions): APIPromise<AuthAgent> {
return this._client.post('/agents/auth', { body, ...options });
}
/**
* Retrieve an auth agent by its ID. Returns the current authentication status of
* the managed profile.
*
* @example
* ```ts
* const authAgent = await client.agents.auth.retrieve('id');
* ```
*/
retrieve(id: string, options?: RequestOptions): APIPromise<AuthAgent> {
return this._client.get(path`/agents/auth/${id}`, options);
}
/**
* List auth agents with optional filters for profile_name and domain.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const authAgent of client.agents.auth.list()) {
* // ...
* }
* ```
*/
list(
query: AuthListParams | null | undefined = {},
options?: RequestOptions,
): PagePromise<AuthAgentsOffsetPagination, AuthAgent> {
return this._client.getAPIList('/agents/auth', OffsetPagination<AuthAgent>, { query, ...options });
}
/**
* Deletes an auth agent and terminates its workflow. This will:
*
* - Soft delete the auth agent record
* - Gracefully terminate the agent's Temporal workflow
* - Cancel any in-progress invocations
*
* @example
* ```ts
* await client.agents.auth.delete('id');
* ```
*/
delete(id: string, options?: RequestOptions): APIPromise<void> {
return this._client.delete(path`/agents/auth/${id}`, {
...options,
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
});
}
}
export type AuthAgentsOffsetPagination = OffsetPagination<AuthAgent>;
/**
* Response from get invocation endpoint
*/
export interface AgentAuthInvocationResponse {
/**
* App name (org name at time of invocation creation)
*/
app_name: string;
/**
* Domain for authentication
*/
domain: string;
/**
* When the handoff code expires
*/
expires_at: string;
/**
* Invocation status
*/
status: 'IN_PROGRESS' | 'SUCCESS' | 'EXPIRED' | 'CANCELED' | 'FAILED';
/**
* Current step in the invocation workflow
*/
step:
| 'initialized'
| 'discovering'
| 'awaiting_input'
| 'awaiting_external_action'
| 'submitting'
| 'completed'
| 'expired';
/**
* The invocation type:
*
* - login: First-time authentication
* - reauth: Re-authentication for previously authenticated agents
* - auto_login: Legacy type (no longer created, kept for backward compatibility)
*/
type: 'login' | 'auto_login' | 'reauth';
/**
* Error message explaining why the invocation failed (present when status=FAILED)
*/
error_message?: string | null;
/**
* Instructions for user when external action is required (present when
* step=awaiting_external_action)
*/
external_action_message?: string | null;
/**
* Browser live view URL for debugging the invocation
*/
live_view_url?: string | null;
/**
* MFA method options to choose from (present when step=awaiting_input and MFA
* selection is required)
*/
mfa_options?: Array<AgentAuthInvocationResponse.MfaOption> | null;
/**
* Fields currently awaiting input (present when step=awaiting_input)
*/
pending_fields?: Array<DiscoveredField> | null;
/**
* SSO buttons available on the page (present when step=awaiting_input)
*/
pending_sso_buttons?: Array<AgentAuthInvocationResponse.PendingSSOButton> | null;
/**
* SSO provider being used for authentication (e.g., google, github, microsoft)
*/
sso_provider?: string | null;
/**
* Names of fields that have been submitted (present when step=submitting or later)
*/
submitted_fields?: Array<string> | null;
}
export namespace AgentAuthInvocationResponse {
/**
* An MFA method option for verification
*/
export interface MfaOption {
/**
* The visible option text
*/
label: string;
/**
* The MFA delivery method type
*/
type: 'sms' | 'call' | 'email' | 'totp' | 'push' | 'security_key';
/**
* Additional instructions from the site
*/
description?: string | null;
/**
* The masked destination (phone/email) if shown
*/
target?: string | null;
}
/**
* An SSO button for signing in with an external identity provider
*/
export interface PendingSSOButton {
/**
* Visible button text
*/
label: string;
/**
* Identity provider name
*/
provider: string;
/**
* XPath selector for the button
*/
selector: string;
}
}
/**
* Response from submit endpoint - returns immediately after submission is accepted
*/
export interface AgentAuthSubmitResponse {
/**
* Whether the submission was accepted for processing
*/
accepted: boolean;
}
/**
* An auth agent that manages authentication for a specific domain and profile
* combination
*/
export interface AuthAgent {
/**
* Unique identifier for the auth agent
*/
id: string;
/**
* Target domain for authentication
*/
domain: string;
/**
* Name of the profile associated with this auth agent
*/
profile_name: string;
/**
* Current authentication status of the managed profile
*/
status: 'AUTHENTICATED' | 'NEEDS_AUTH';
/**
* Additional domains that are valid for this auth agent's authentication flow
* (besides the primary domain). Useful when login pages redirect to different
* domains.
*/
allowed_domains?: Array<string>;
/**
* Whether automatic re-authentication is possible (has credential_id, selectors,
* and login_url)
*/
can_reauth?: boolean;
/**
* ID of the linked credential for automatic re-authentication
*/
credential_id?: string;
/**
* Name of the linked credential for automatic re-authentication
*/
credential_name?: string;
/**
* Whether this auth agent has stored selectors for deterministic re-authentication
*/
has_selectors?: boolean;
/**
* When the last authentication check was performed
*/
last_auth_check_at?: string;
/**
* URL where the browser landed after successful login. Query parameters and
* fragments are stripped for privacy.
*/
post_login_url?: string;
}
/**
* Request to create or find an auth agent
*/
export interface AuthAgentCreateRequest {
/**
* Domain for authentication
*/
domain: string;
/**
* Name of the profile to use for this auth agent
*/
profile_name: string;
/**
* Additional domains that are valid for this auth agent's authentication flow
* (besides the primary domain). Useful when login pages redirect to different
* domains.
*/
allowed_domains?: Array<string>;
/**
* Optional name of an existing credential to use for this auth agent. If provided,
* the credential will be linked to the agent and its values will be used to
* auto-fill the login form on invocation.
*/
credential_name?: string;
/**
* Optional login page URL. If provided, will be stored on the agent and used to
* skip discovery in future invocations.
*/
login_url?: string;
/**
* Optional proxy configuration
*/
proxy?: AuthAgentCreateRequest.Proxy;
}
export namespace AuthAgentCreateRequest {
/**
* Optional proxy configuration
*/
export interface Proxy {
/**
* ID of the proxy to use
*/
proxy_id?: string;
}
}
/**
* Request to create an invocation for an existing auth agent
*/
export interface AuthAgentInvocationCreateRequest {
/**
* ID of the auth agent to create an invocation for
*/
auth_agent_id: string;
/**
* If provided, saves the submitted credentials under this name upon successful
* login. The credential will be linked to the auth agent for automatic
* re-authentication.
*/
save_credential_as?: string;
}
/**
* Response from creating an invocation. Always returns an invocation_id.
*/
export interface AuthAgentInvocationCreateResponse {
/**
* When the handoff code expires.
*/
expires_at: string;
/**
* One-time code for handoff.
*/
handoff_code: string;
/**
* URL to redirect user to.
*/
hosted_url: string;
/**
* Unique identifier for the invocation.
*/
invocation_id: string;
/**
* The invocation type:
*
* - login: First-time authentication
* - reauth: Re-authentication for previously authenticated agents
* - auto_login: Legacy type (no longer created, kept for backward compatibility)
*/
type: 'login' | 'auto_login' | 'reauth';
}
/**
* A discovered form field
*/
export interface DiscoveredField {
/**
* Field label
*/
label: string;
/**
* Field name
*/
name: string;
/**
* CSS selector for the field
*/
selector: string;
/**
* Field type
*/
type: 'text' | 'email' | 'password' | 'tel' | 'number' | 'url' | 'code' | 'totp';
/**
* Field placeholder
*/
placeholder?: string;
/**
* Whether field is required
*/
required?: boolean;
}
export interface AuthCreateParams {
/**
* Domain for authentication
*/
domain: string;
/**
* Name of the profile to use for this auth agent
*/
profile_name: string;
/**
* Additional domains that are valid for this auth agent's authentication flow
* (besides the primary domain). Useful when login pages redirect to different
* domains.
*/
allowed_domains?: Array<string>;
/**
* Optional name of an existing credential to use for this auth agent. If provided,
* the credential will be linked to the agent and its values will be used to
* auto-fill the login form on invocation.
*/
credential_name?: string;
/**
* Optional login page URL. If provided, will be stored on the agent and used to
* skip discovery in future invocations.
*/
login_url?: string;
/**
* Optional proxy configuration
*/
proxy?: AuthCreateParams.Proxy;
}
export namespace AuthCreateParams {
/**
* Optional proxy configuration
*/
export interface Proxy {
/**
* ID of the proxy to use
*/
proxy_id?: string;
}
}
export interface AuthListParams extends OffsetPaginationParams {
/**
* Filter by domain
*/
domain?: string;
/**
* Filter by profile name
*/
profile_name?: string;
}
Auth.Invocations = Invocations;
export declare namespace Auth {
export {
type AgentAuthInvocationResponse as AgentAuthInvocationResponse,
type AgentAuthSubmitResponse as AgentAuthSubmitResponse,
type AuthAgent as AuthAgent,
type AuthAgentCreateRequest as AuthAgentCreateRequest,
type AuthAgentInvocationCreateRequest as AuthAgentInvocationCreateRequest,
type AuthAgentInvocationCreateResponse as AuthAgentInvocationCreateResponse,
type DiscoveredField as DiscoveredField,
type AuthAgentsOffsetPagination as AuthAgentsOffsetPagination,
type AuthCreateParams as AuthCreateParams,
type AuthListParams as AuthListParams,
};
export {
Invocations as Invocations,
type InvocationExchangeResponse as InvocationExchangeResponse,
type InvocationCreateParams as InvocationCreateParams,
type InvocationExchangeParams as InvocationExchangeParams,
type InvocationSubmitParams as InvocationSubmitParams,
};
}