@tensile-tools/auth-client 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +62 -2
- package/dist/client.d.ts +569 -0
- package/dist/client.js +637 -0
- package/dist/devtools.d.ts +12 -0
- package/dist/devtools.js +44 -0
- package/dist/elements/account.d.ts +63 -0
- package/dist/elements/account.js +331 -0
- package/dist/elements/approvals.d.ts +61 -0
- package/dist/elements/approvals.js +252 -0
- package/dist/elements/auth.d.ts +48 -0
- package/dist/elements/auth.js +238 -0
- package/dist/elements/base.d.ts +176 -0
- package/dist/elements/base.js +540 -0
- package/dist/elements/config.d.ts +70 -0
- package/dist/elements/config.js +119 -0
- package/dist/elements/format.d.ts +32 -0
- package/dist/elements/format.js +67 -0
- package/dist/elements/index.d.ts +21 -0
- package/dist/elements/index.js +31 -0
- package/dist/elements/qr.d.ts +9 -0
- package/dist/elements/qr.js +302 -0
- package/dist/elements/returnto.d.ts +17 -0
- package/dist/elements/returnto.js +63 -0
- package/dist/elements/setup.d.ts +70 -0
- package/dist/elements/setup.js +316 -0
- package/dist/elements/styles.d.ts +3 -0
- package/dist/elements/styles.js +194 -0
- package/dist/elements/text.d.ts +21 -0
- package/dist/elements/text.js +302 -0
- package/dist/fonts/OFL-geist-mono.txt +93 -0
- package/dist/fonts/OFL-geist.txt +93 -0
- package/dist/fonts/OFL-inter.txt +93 -0
- package/dist/fonts/README.md +18 -0
- package/dist/fonts/geist-mono.woff2 +0 -0
- package/dist/fonts/geist.woff2 +0 -0
- package/dist/fonts/inter.woff2 +0 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/problem.d.ts +54 -0
- package/dist/problem.js +40 -0
- package/dist/webauthn.d.ts +46 -0
- package/dist/webauthn.js +102 -0
- package/package.json +51 -4
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,569 @@
|
|
|
1
|
+
import { type Problem } from './problem.ts';
|
|
2
|
+
import { toBase64url, type Capabilities } from './webauthn.ts';
|
|
3
|
+
/** The server routes the client calls. Each begin route answers WebAuthn options; each finish route takes the credential JSON. */
|
|
4
|
+
export interface Endpoints {
|
|
5
|
+
signInBegin: string;
|
|
6
|
+
signInFinish: string;
|
|
7
|
+
signUpBegin: string;
|
|
8
|
+
signUpFinish: string;
|
|
9
|
+
stepUpBegin: string;
|
|
10
|
+
stepUpFinish: string;
|
|
11
|
+
addPasskeyBegin: string;
|
|
12
|
+
addPasskeyFinish: string;
|
|
13
|
+
signOut: string;
|
|
14
|
+
/** Answers `{userId, credentialIds, name?, displayName?}` for the signed-in account, for the Signal API. */
|
|
15
|
+
credentials: string;
|
|
16
|
+
/** Takes `{code}` to finish a sign-in that needs TOTP. */
|
|
17
|
+
totpVerify: string;
|
|
18
|
+
/** Takes `{code}` to sign in with a recovery code. */
|
|
19
|
+
recoverySignIn: string;
|
|
20
|
+
/** Takes `{email, password}`; answers 202 for every address. */
|
|
21
|
+
passwordSignUp: string;
|
|
22
|
+
/** Takes `{email, password}`; answers the session, or `{needs}`. */
|
|
23
|
+
passwordSignIn: string;
|
|
24
|
+
/** Takes `{code, password?}` from a confirmation link. */
|
|
25
|
+
passwordConfirm: string;
|
|
26
|
+
/** Takes `{email}`; answers 202 for every address. */
|
|
27
|
+
passwordForgot: string;
|
|
28
|
+
/** Takes `{code, password, keepTokens?}` from a reset link. */
|
|
29
|
+
passwordReset: string;
|
|
30
|
+
/** Takes `{password}` to step the session up. */
|
|
31
|
+
passwordStepUp: string;
|
|
32
|
+
/** Takes `{current, next, endOtherSessions?}`. */
|
|
33
|
+
passwordChange: string;
|
|
34
|
+
/** Takes `{email?, password}`. */
|
|
35
|
+
passwordAdd: string;
|
|
36
|
+
/** Takes `{endOtherSessions?}`. */
|
|
37
|
+
passwordRemove: string;
|
|
38
|
+
/** Takes `{email}`; answers 202. */
|
|
39
|
+
emailChange: string;
|
|
40
|
+
/** Sends a fresh confirmation link; answers 202. */
|
|
41
|
+
emailResend: string;
|
|
42
|
+
/** Answers `{address, verified, password, changed_at}`. */
|
|
43
|
+
passwordStatus: string;
|
|
44
|
+
/** Answers the signed-in session. */
|
|
45
|
+
me: string;
|
|
46
|
+
/** Answers `{uri}` to start TOTP enrolment. */
|
|
47
|
+
totpEnroll: string;
|
|
48
|
+
/** Takes `{code}` to turn TOTP on. */
|
|
49
|
+
totpConfirm: string;
|
|
50
|
+
/** Answers the person's own TOTP status. */
|
|
51
|
+
totpStatus: string;
|
|
52
|
+
/** Removes the person's TOTP factor. */
|
|
53
|
+
totpRemove: string;
|
|
54
|
+
/** Answers `{codes}`, a new set of recovery codes. */
|
|
55
|
+
recoveryGenerate: string;
|
|
56
|
+
/** Takes `{code}`, one code typed back. */
|
|
57
|
+
recoveryConfirm: string;
|
|
58
|
+
/** Answers `{items}`, the approvals that wait for the person. */
|
|
59
|
+
approvals: string;
|
|
60
|
+
/** One approval; `{id}` is replaced. Its begin, finish, and deny routes add `/begin`, `/finish`, and `/deny`. */
|
|
61
|
+
approval: string;
|
|
62
|
+
/** Answers `{current, items}`, the session tree. */
|
|
63
|
+
sessions: string;
|
|
64
|
+
/** Revokes one session; `{id}` is replaced. */
|
|
65
|
+
revokeSession: string;
|
|
66
|
+
/** Revokes every other device. */
|
|
67
|
+
revokeOthers: string;
|
|
68
|
+
/** Answers `{items, chain}`; takes `?before=<seq>`. */
|
|
69
|
+
activity: string;
|
|
70
|
+
/** Answers `{items}`, recovery sign-ins the person can undo. */
|
|
71
|
+
recoverySignIns: string;
|
|
72
|
+
/** Takes `{session}`. */
|
|
73
|
+
recoveryUndo: string;
|
|
74
|
+
/** Answers `{sessions}`, the session tree with each agent's sessions. Served by the tensile-auth server. */
|
|
75
|
+
agentsTree: string;
|
|
76
|
+
/** Takes `{name, scopes}` and creates an agent. Served by the tensile-auth server. */
|
|
77
|
+
agents: string;
|
|
78
|
+
/** One agent; `{id}` is replaced. Its delegate and revoke routes add `/delegate` and `/revoke`. */
|
|
79
|
+
agent: string;
|
|
80
|
+
/** Takes `{name, scopes, ttl_seconds}` and creates a personal access token. */
|
|
81
|
+
tokens: string;
|
|
82
|
+
/** Takes `{code}` and answers what claiming an agent would do. */
|
|
83
|
+
claimPeek: string;
|
|
84
|
+
/** Takes `{code, scopes, ttl_seconds, key_thumbprint}` and claims an agent. */
|
|
85
|
+
claimClaim: string;
|
|
86
|
+
/** One OAuth authorization request; `{id}` is replaced. Its approve and deny routes add `/approve` and `/deny`. */
|
|
87
|
+
oauthRequest: string;
|
|
88
|
+
/** One device request; `{id}` is replaced with the user code. Its approve and deny routes add `/approve` and `/deny`. */
|
|
89
|
+
deviceRequest: string;
|
|
90
|
+
}
|
|
91
|
+
/** Default routes, under `base`. */
|
|
92
|
+
export declare const defaultEndpoints: Endpoints;
|
|
93
|
+
export interface ClientOptions {
|
|
94
|
+
/** Prefix for every endpoint, for example `https://tensile.example`. Default: same origin. */
|
|
95
|
+
base?: string;
|
|
96
|
+
endpoints?: Partial<Endpoints>;
|
|
97
|
+
/** The relying party ID, for the Signal API. Default: the page's host name. */
|
|
98
|
+
rpId?: string;
|
|
99
|
+
/** BroadcastChannel name for tab sync. Default `tensile-auth`. */
|
|
100
|
+
channel?: string;
|
|
101
|
+
fetch?: typeof globalThis.fetch;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The result of a ceremony. Branch on `outcome`; every case is one a
|
|
105
|
+
* person can act on.
|
|
106
|
+
*/
|
|
107
|
+
export type Outcome<T = unknown> = {
|
|
108
|
+
outcome: 'ok';
|
|
109
|
+
data: T;
|
|
110
|
+
}
|
|
111
|
+
/** No passkey for this site, or the person closed the prompt: browsers can't tell these apart. Offer the other ways in. */
|
|
112
|
+
| {
|
|
113
|
+
outcome: 'no_passkey_or_cancelled';
|
|
114
|
+
}
|
|
115
|
+
/** This authenticator already holds a passkey for the account. */
|
|
116
|
+
| {
|
|
117
|
+
outcome: 'already_registered';
|
|
118
|
+
}
|
|
119
|
+
/** The browser has no WebAuthn, or not the feature asked for. */
|
|
120
|
+
| {
|
|
121
|
+
outcome: 'unsupported';
|
|
122
|
+
}
|
|
123
|
+
/** The account needs another factor first, for example `['totp']`: ask for it, then call `verifyTOTP`. */
|
|
124
|
+
| {
|
|
125
|
+
outcome: 'needs_factor';
|
|
126
|
+
needs: string[];
|
|
127
|
+
}
|
|
128
|
+
/** Too many attempts; wait `retryAfter` seconds. */
|
|
129
|
+
| {
|
|
130
|
+
outcome: 'throttled';
|
|
131
|
+
retryAfter: number;
|
|
132
|
+
}
|
|
133
|
+
/** The server refused; show `problem.title` and `problem.fix`. */
|
|
134
|
+
| {
|
|
135
|
+
outcome: 'problem';
|
|
136
|
+
problem: Problem;
|
|
137
|
+
};
|
|
138
|
+
/** The account's address and password, from `passwordStatus`. */
|
|
139
|
+
export interface PasswordStatus {
|
|
140
|
+
address: string;
|
|
141
|
+
verified: boolean;
|
|
142
|
+
password: boolean;
|
|
143
|
+
changed_at: string;
|
|
144
|
+
}
|
|
145
|
+
/** The person's authenticator app, from `totpStatus`. */
|
|
146
|
+
export interface TOTPStatus {
|
|
147
|
+
/** True when the account has a factor, confirmed or not. */
|
|
148
|
+
enrolled: boolean;
|
|
149
|
+
/** True once the first code was accepted: the app is on. */
|
|
150
|
+
confirmed: boolean;
|
|
151
|
+
/** True after too many wrong codes; setting it up again clears it. */
|
|
152
|
+
locked: boolean;
|
|
153
|
+
/** When the app was set up. */
|
|
154
|
+
since?: string;
|
|
155
|
+
}
|
|
156
|
+
/** Session events every tab hears. */
|
|
157
|
+
export type SessionEvent = {
|
|
158
|
+
type: 'signed-in' | 'signed-out' | 'stepped-up' | 'session-lost';
|
|
159
|
+
};
|
|
160
|
+
/** An agent, as the account routes name it. */
|
|
161
|
+
export interface AgentRef {
|
|
162
|
+
id: string;
|
|
163
|
+
name: string;
|
|
164
|
+
/** The type the agent reported, for example `claude-code`. Trust it only when `verified`. */
|
|
165
|
+
type?: string;
|
|
166
|
+
verified?: boolean;
|
|
167
|
+
}
|
|
168
|
+
/** An approval an agent asked the person for. */
|
|
169
|
+
export interface ApprovalView {
|
|
170
|
+
id: string;
|
|
171
|
+
state: 'pending' | 'approved' | 'denied';
|
|
172
|
+
agent: AgentRef | null;
|
|
173
|
+
action: {
|
|
174
|
+
kind: string;
|
|
175
|
+
resource?: string;
|
|
176
|
+
params?: Record<string, string>;
|
|
177
|
+
summary: string;
|
|
178
|
+
};
|
|
179
|
+
expiresAt: string;
|
|
180
|
+
}
|
|
181
|
+
/** An agent the person owns, as the tensile-auth server answers it. */
|
|
182
|
+
export interface AgentView {
|
|
183
|
+
id: string;
|
|
184
|
+
owner: string;
|
|
185
|
+
name: string;
|
|
186
|
+
scopes: string[];
|
|
187
|
+
created_at: string;
|
|
188
|
+
}
|
|
189
|
+
/** A token delegated to an agent, or a personal access token. Show `token` once; the server never returns it again. */
|
|
190
|
+
export interface IssuedToken {
|
|
191
|
+
token: string;
|
|
192
|
+
session: string;
|
|
193
|
+
agent?: string;
|
|
194
|
+
name?: string;
|
|
195
|
+
scopes: string[];
|
|
196
|
+
expires_at: string;
|
|
197
|
+
}
|
|
198
|
+
/** A pending OAuth authorization request, for the consent page. */
|
|
199
|
+
export interface AuthorizationView {
|
|
200
|
+
id: string;
|
|
201
|
+
client: string;
|
|
202
|
+
client_name: string;
|
|
203
|
+
/** `configured`, `metadata_document`, or `registered`. */
|
|
204
|
+
client_kind: string;
|
|
205
|
+
/** The host of a client ID metadata document. Show it, since anyone can name a client. */
|
|
206
|
+
client_host?: string;
|
|
207
|
+
redirect_uri: string;
|
|
208
|
+
redirect_host: string;
|
|
209
|
+
resource?: string;
|
|
210
|
+
resource_name?: string;
|
|
211
|
+
scopes: string[];
|
|
212
|
+
/** Warnings to show next to the approve button. */
|
|
213
|
+
warnings: string[];
|
|
214
|
+
/** The app asked for a fresh sign-in; approving fails with `login_required` until the person signs in again. */
|
|
215
|
+
login_required: boolean;
|
|
216
|
+
created_at: string;
|
|
217
|
+
expires_at: string;
|
|
218
|
+
}
|
|
219
|
+
/** A pending device request, for the device page. */
|
|
220
|
+
export interface DeviceRequestView {
|
|
221
|
+
client: string;
|
|
222
|
+
client_name: string;
|
|
223
|
+
scopes: string[];
|
|
224
|
+
/** The address of the device that asked. Show it, so people notice a request they didn't start. */
|
|
225
|
+
requester?: string;
|
|
226
|
+
created_at: string;
|
|
227
|
+
expires_at: string;
|
|
228
|
+
}
|
|
229
|
+
/** One live session in the person's tree. */
|
|
230
|
+
export interface SessionView {
|
|
231
|
+
id: string;
|
|
232
|
+
/** `device`, `agent`, `token`, `app`, or `other`. */
|
|
233
|
+
kind: string;
|
|
234
|
+
agent?: AgentRef;
|
|
235
|
+
name?: string;
|
|
236
|
+
client?: string;
|
|
237
|
+
device?: string;
|
|
238
|
+
userAgent?: string;
|
|
239
|
+
createdAt: string;
|
|
240
|
+
lastSeenAt: string;
|
|
241
|
+
expiresAt: string;
|
|
242
|
+
children: SessionView[];
|
|
243
|
+
}
|
|
244
|
+
/** One audit event of the person. */
|
|
245
|
+
export interface ActivityEvent {
|
|
246
|
+
seq: number;
|
|
247
|
+
kind: string;
|
|
248
|
+
at: string;
|
|
249
|
+
agent?: AgentRef;
|
|
250
|
+
session?: string;
|
|
251
|
+
byAgent?: boolean;
|
|
252
|
+
methods?: string[];
|
|
253
|
+
action?: string;
|
|
254
|
+
reason?: string;
|
|
255
|
+
count?: number;
|
|
256
|
+
summary?: string;
|
|
257
|
+
seal?: string;
|
|
258
|
+
}
|
|
259
|
+
/** A page of activity and the state of the audit chain. */
|
|
260
|
+
export interface Activity {
|
|
261
|
+
items: ActivityEvent[];
|
|
262
|
+
chain: {
|
|
263
|
+
/** `verified`: a check passed within 3 minutes; `tampered`: a check found a changed event; `unknown`: no check has finished; `unavailable`: checks fail. */
|
|
264
|
+
state: 'verified' | 'tampered' | 'unknown' | 'unavailable';
|
|
265
|
+
verified: boolean;
|
|
266
|
+
/** When the chain last verified, while that still counts. */
|
|
267
|
+
verified_at?: string;
|
|
268
|
+
/** When the last check finished, and whether it couldn't run. */
|
|
269
|
+
checked_at?: string;
|
|
270
|
+
last_check_failed: boolean;
|
|
271
|
+
/** How many of the listed events are sealed into the chain. */
|
|
272
|
+
sealed: number;
|
|
273
|
+
total: number;
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
/** A sign-in with a recovery code that the person can still undo. */
|
|
277
|
+
export interface RecoverySignInView {
|
|
278
|
+
session: string;
|
|
279
|
+
at: string;
|
|
280
|
+
undoBy: string;
|
|
281
|
+
device?: string;
|
|
282
|
+
changes: string[];
|
|
283
|
+
}
|
|
284
|
+
export interface StepUpOptions {
|
|
285
|
+
/** Step up for one purpose only, for example `{name: 'secrets.edit', resource: 'repo:acme/api:prod'}`. */
|
|
286
|
+
for?: {
|
|
287
|
+
name: string;
|
|
288
|
+
resource?: string;
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
export interface EnterOptions {
|
|
292
|
+
/** The name typed so far, for a new account if no passkey exists. */
|
|
293
|
+
name?: string;
|
|
294
|
+
/** Aborts a background conditional request before a modal prompt. */
|
|
295
|
+
signal?: AbortSignal;
|
|
296
|
+
}
|
|
297
|
+
export declare class AuthClient {
|
|
298
|
+
readonly endpoints: Endpoints;
|
|
299
|
+
private readonly base;
|
|
300
|
+
private readonly rpId;
|
|
301
|
+
private readonly doFetch;
|
|
302
|
+
private readonly channel;
|
|
303
|
+
private readonly listeners;
|
|
304
|
+
private conditional;
|
|
305
|
+
private fresh;
|
|
306
|
+
constructor(opts?: ClientOptions);
|
|
307
|
+
/** Runs `fn` on every session event in this tab and others. Returns an unsubscribe function. */
|
|
308
|
+
onSessionChange(fn: (e: SessionEvent) => void): () => void;
|
|
309
|
+
/** Stops listening to other tabs. */
|
|
310
|
+
close(): void;
|
|
311
|
+
/** Reports what this browser supports, to choose screens. */
|
|
312
|
+
capabilities(): Promise<Capabilities>;
|
|
313
|
+
/** Signs in with a passkey through the browser's account chooser. */
|
|
314
|
+
signIn(): Promise<Outcome>;
|
|
315
|
+
/** Creates an account with a passkey. */
|
|
316
|
+
signUp(opts: {
|
|
317
|
+
name: string;
|
|
318
|
+
displayName?: string;
|
|
319
|
+
}): Promise<Outcome>;
|
|
320
|
+
/** Adds a passkey to the signed-in account. */
|
|
321
|
+
addPasskey(opts?: {
|
|
322
|
+
label?: string;
|
|
323
|
+
}): Promise<Outcome>;
|
|
324
|
+
/** Confirms it's you with a passkey, for the whole session or for one purpose. */
|
|
325
|
+
stepUp(opts?: StepUpOptions): Promise<Outcome>;
|
|
326
|
+
/** Finishes a sign-in that answered `needs_factor` with a TOTP code. */
|
|
327
|
+
verifyTOTP(code: string): Promise<Outcome>;
|
|
328
|
+
/** Signs in with a recovery code. It may answer `needs_factor` when the account has TOTP. */
|
|
329
|
+
signInWithRecoveryCode(code: string): Promise<Outcome>;
|
|
330
|
+
/**
|
|
331
|
+
* Starts an email and password sign-up. It answers `ok` for every
|
|
332
|
+
* address: the person learns what happened by email. A refusal names
|
|
333
|
+
* the password rule, for example `password_too_short`.
|
|
334
|
+
*/
|
|
335
|
+
signUpWithPassword(opts: {
|
|
336
|
+
email: string;
|
|
337
|
+
password: string;
|
|
338
|
+
}): Promise<Outcome>;
|
|
339
|
+
/**
|
|
340
|
+
* Signs in with an email address and a password. It may answer
|
|
341
|
+
* `needs_factor` when the account has TOTP. Every failure is the same
|
|
342
|
+
* `factor_rejected` problem. Use `<input type="password">` and allow
|
|
343
|
+
* paste, so password managers work.
|
|
344
|
+
*/
|
|
345
|
+
signInWithPassword(opts: {
|
|
346
|
+
email: string;
|
|
347
|
+
password: string;
|
|
348
|
+
}): Promise<Outcome>;
|
|
349
|
+
/**
|
|
350
|
+
* Redeems the code of a confirmation link. The code comes from `code`,
|
|
351
|
+
* or from the page's URL fragment (`#code=…`), which browsers don't
|
|
352
|
+
* send to servers or in Referer; it is removed from the address bar
|
|
353
|
+
* before the request, so it is posted once. When the answer is the
|
|
354
|
+
* `confirm_sign_in` problem, ask the person to sign in, or for their
|
|
355
|
+
* password, and call it again with `password`.
|
|
356
|
+
*/
|
|
357
|
+
confirmEmail(opts?: {
|
|
358
|
+
code?: string;
|
|
359
|
+
password?: string;
|
|
360
|
+
}): Promise<Outcome>;
|
|
361
|
+
/** Asks for a reset link. It answers `ok` for every address. */
|
|
362
|
+
forgotPassword(email: string): Promise<Outcome>;
|
|
363
|
+
/**
|
|
364
|
+
* Sets a new password with the code of a reset link, from `code` or the
|
|
365
|
+
* URL fragment as for `confirmEmail`. A reset ends every session, this
|
|
366
|
+
* one too; `keepTokens` keeps personal access tokens and OAuth grants.
|
|
367
|
+
*/
|
|
368
|
+
resetPassword(opts: {
|
|
369
|
+
password: string;
|
|
370
|
+
code?: string;
|
|
371
|
+
keepTokens?: boolean;
|
|
372
|
+
}): Promise<Outcome>;
|
|
373
|
+
/** Confirms it's you with your password. The server refuses it on an account with a passkey or TOTP. */
|
|
374
|
+
stepUpWithPassword(password: string): Promise<Outcome>;
|
|
375
|
+
/** Changes the password, after checking the current one. */
|
|
376
|
+
changePassword(opts: {
|
|
377
|
+
current: string;
|
|
378
|
+
next: string;
|
|
379
|
+
endOtherSessions?: boolean;
|
|
380
|
+
}): Promise<Outcome>;
|
|
381
|
+
/** Adds a password; `email` is needed when the account has no confirmed address. */
|
|
382
|
+
addPassword(opts: {
|
|
383
|
+
password: string;
|
|
384
|
+
email?: string;
|
|
385
|
+
}): Promise<Outcome>;
|
|
386
|
+
/** Removes the password, when the account has another way to sign in. */
|
|
387
|
+
removePassword(opts?: {
|
|
388
|
+
endOtherSessions?: boolean;
|
|
389
|
+
}): Promise<Outcome>;
|
|
390
|
+
/** Asks to change the email address; the new one must be confirmed. */
|
|
391
|
+
changeEmail(email: string): Promise<Outcome>;
|
|
392
|
+
/** Sends a fresh confirmation link to an unconfirmed address. */
|
|
393
|
+
resendVerification(): Promise<Outcome>;
|
|
394
|
+
/** Reads the account's address and whether it has a password. */
|
|
395
|
+
passwordStatus(): Promise<Outcome<PasswordStatus>>;
|
|
396
|
+
/** Reads the signed-in session. */
|
|
397
|
+
me(): Promise<Outcome<{
|
|
398
|
+
user: string;
|
|
399
|
+
assurance: string;
|
|
400
|
+
methods: string[];
|
|
401
|
+
recoveryOnly: boolean;
|
|
402
|
+
}>>;
|
|
403
|
+
/** Lists the approvals that wait for the person, newest first. */
|
|
404
|
+
approvals(): Promise<Outcome<ApprovalView[]>>;
|
|
405
|
+
/** Reads one approval. */
|
|
406
|
+
approval(id: string): Promise<Outcome<ApprovalView>>;
|
|
407
|
+
/**
|
|
408
|
+
* Approves an agent's request with a passkey. The passkey signs the
|
|
409
|
+
* approval's challenge, which covers the exact action.
|
|
410
|
+
*/
|
|
411
|
+
approve(id: string): Promise<Outcome>;
|
|
412
|
+
/** Declines an agent's request. */
|
|
413
|
+
deny(id: string): Promise<Outcome>;
|
|
414
|
+
/** Reads the person's session tree and which session is this one. */
|
|
415
|
+
sessions(): Promise<Outcome<{
|
|
416
|
+
current: string;
|
|
417
|
+
items: SessionView[];
|
|
418
|
+
}>>;
|
|
419
|
+
/** Revokes one of the person's sessions and everything delegated from it. */
|
|
420
|
+
revokeSession(id: string): Promise<Outcome>;
|
|
421
|
+
/** Signs out every other device. It steps up first when the server asks. */
|
|
422
|
+
signOutOthers(): Promise<Outcome<{
|
|
423
|
+
revoked: number;
|
|
424
|
+
}>>;
|
|
425
|
+
/** Reads the person's latest audit events and the chain state. */
|
|
426
|
+
activity(opts?: {
|
|
427
|
+
before?: number;
|
|
428
|
+
}): Promise<Outcome<Activity>>;
|
|
429
|
+
/** Lists recovery sign-ins the person can still undo. */
|
|
430
|
+
recoverySignIns(): Promise<Outcome<RecoverySignInView[]>>;
|
|
431
|
+
/** Undoes a recovery sign-in the person says wasn't them. */
|
|
432
|
+
undoRecovery(session: string): Promise<Outcome<Record<string, number | boolean>>>;
|
|
433
|
+
/** Reads the person's sessions as a tree, with each agent's sessions under the session that delegated them. */
|
|
434
|
+
agentsTree(): Promise<Outcome<{
|
|
435
|
+
sessions: unknown[];
|
|
436
|
+
}>>;
|
|
437
|
+
/** Creates an agent the person owns. */
|
|
438
|
+
createAgent(opts: {
|
|
439
|
+
name: string;
|
|
440
|
+
scopes?: string[];
|
|
441
|
+
}): Promise<Outcome<AgentView>>;
|
|
442
|
+
/** Issues a token for one of the person's agents. It steps up first when the server asks. */
|
|
443
|
+
delegate(agent: string, opts?: {
|
|
444
|
+
name?: string;
|
|
445
|
+
scopes?: string[];
|
|
446
|
+
ttlSeconds?: number;
|
|
447
|
+
keyThumbprint?: string;
|
|
448
|
+
}): Promise<Outcome<IssuedToken>>;
|
|
449
|
+
/** Revokes one of the person's agents and every session it holds. */
|
|
450
|
+
revokeAgent(agent: string): Promise<Outcome>;
|
|
451
|
+
/** Creates a personal access token. It steps up first when the server asks. */
|
|
452
|
+
createToken(opts: {
|
|
453
|
+
name: string;
|
|
454
|
+
scopes?: string[];
|
|
455
|
+
ttlSeconds?: number;
|
|
456
|
+
}): Promise<Outcome<IssuedToken>>;
|
|
457
|
+
/** Reads what claiming an agent with a claim code would do, and the words the agent shows, without claiming it. */
|
|
458
|
+
peekClaim(code: string): Promise<Outcome<{
|
|
459
|
+
agent: Record<string, unknown>;
|
|
460
|
+
words: string;
|
|
461
|
+
}>>;
|
|
462
|
+
/** Claims an agent that signed up by itself. */
|
|
463
|
+
claimAgent(code: string, opts?: {
|
|
464
|
+
scopes?: string[];
|
|
465
|
+
ttlSeconds?: number;
|
|
466
|
+
keyThumbprint?: string;
|
|
467
|
+
}): Promise<Outcome<AgentView>>;
|
|
468
|
+
/** Reads a pending OAuth authorization request, for the consent page. */
|
|
469
|
+
authorization(id: string): Promise<Outcome<AuthorizationView>>;
|
|
470
|
+
/** Approves an OAuth authorization request and answers where to send the browser. It steps up first when the server asks. */
|
|
471
|
+
approveAuthorization(id: string): Promise<Outcome<{
|
|
472
|
+
redirect_to: string;
|
|
473
|
+
}>>;
|
|
474
|
+
/** Denies an OAuth authorization request and answers where to send the browser. */
|
|
475
|
+
denyAuthorization(id: string): Promise<Outcome<{
|
|
476
|
+
redirect_to: string;
|
|
477
|
+
}>>;
|
|
478
|
+
/** Reads the pending device request for the code the person typed. */
|
|
479
|
+
deviceRequest(userCode: string): Promise<Outcome<DeviceRequestView>>;
|
|
480
|
+
/** Approves the device request for a user code. It steps up first when the server asks. */
|
|
481
|
+
approveDevice(userCode: string): Promise<Outcome>;
|
|
482
|
+
/** Denies the device request for a user code. */
|
|
483
|
+
denyDevice(userCode: string): Promise<Outcome>;
|
|
484
|
+
/** Starts TOTP enrolment and answers the `otpauth://` URI. */
|
|
485
|
+
enrollTOTP(): Promise<Outcome<{
|
|
486
|
+
uri: string;
|
|
487
|
+
}>>;
|
|
488
|
+
/** Turns TOTP on with a code from the app. */
|
|
489
|
+
confirmTOTP(code: string): Promise<Outcome>;
|
|
490
|
+
/** Answers whether the person's authenticator app is on, locked, or not set up. */
|
|
491
|
+
totpStatus(): Promise<Outcome<TOTPStatus>>;
|
|
492
|
+
/** Removes the person's authenticator app. It steps up first when the server asks for a fresh sign-in. */
|
|
493
|
+
removeTOTP(): Promise<Outcome<TOTPStatus>>;
|
|
494
|
+
/** Makes a new set of recovery codes, which replaces the old set. */
|
|
495
|
+
generateRecoveryCodes(): Promise<Outcome<{
|
|
496
|
+
codes: string[];
|
|
497
|
+
}>>;
|
|
498
|
+
/** Checks one recovery code typed back, so the person proves they saved the set. */
|
|
499
|
+
confirmRecoveryCodes(code: string): Promise<Outcome>;
|
|
500
|
+
private path;
|
|
501
|
+
/**
|
|
502
|
+
* Calls an account route like `fetch` does, stepping up when the server
|
|
503
|
+
* asks, and turns the answer into an outcome instead of throwing.
|
|
504
|
+
*/
|
|
505
|
+
private call;
|
|
506
|
+
/** Posts JSON and turns the answer into an outcome. */
|
|
507
|
+
private post;
|
|
508
|
+
private postCode;
|
|
509
|
+
/** Turns a successful finish into ok, or needs_factor when the server asks for more. */
|
|
510
|
+
private settled;
|
|
511
|
+
/** Signs out of this session in every tab. */
|
|
512
|
+
signOut(): Promise<void>;
|
|
513
|
+
/**
|
|
514
|
+
* One entry point for "Continue". It asks the browser to answer at once
|
|
515
|
+
* when it supports immediate mediation, so a person without a passkey
|
|
516
|
+
* goes straight to sign-up with no failed prompt; elsewhere it shows the
|
|
517
|
+
* normal prompt. Returns `no_passkey_or_cancelled` when there's no
|
|
518
|
+
* passkey, so the page can offer sign-up, a phone, or a recovery code.
|
|
519
|
+
* It cancels any background autofill request first, which otherwise
|
|
520
|
+
* makes the modal prompt fail without a word.
|
|
521
|
+
*/
|
|
522
|
+
enter(opts?: EnterOptions): Promise<Outcome>;
|
|
523
|
+
/**
|
|
524
|
+
* Offers passkeys in the autofill of an input with
|
|
525
|
+
* `autocomplete="username webauthn"`. It resolves when the person picks
|
|
526
|
+
* one, and is cancelled by any other ceremony this client starts.
|
|
527
|
+
*/
|
|
528
|
+
autofill(): Promise<Outcome>;
|
|
529
|
+
/**
|
|
530
|
+
* Until when the session passes step-up checks, from the server's
|
|
531
|
+
* Tensile-Auth-Fresh-Until header on the last response, or undefined.
|
|
532
|
+
* Show it as a timer, or prompt before a sensitive action.
|
|
533
|
+
*/
|
|
534
|
+
get freshUntil(): Date | undefined;
|
|
535
|
+
/**
|
|
536
|
+
* `fetch` that answers refusals the way a person would: on a step-up
|
|
537
|
+
* challenge it runs the step-up (for the challenge's purpose, if any)
|
|
538
|
+
* and retries once. Any other failure throws a `ProblemError`. A 401
|
|
539
|
+
* tells every tab the session is gone.
|
|
540
|
+
*/
|
|
541
|
+
fetch(input: string, init?: RequestInit & {
|
|
542
|
+
stepUpFirst?: boolean;
|
|
543
|
+
}): Promise<Response>;
|
|
544
|
+
/**
|
|
545
|
+
* Tells password managers which of this account's passkeys still exist
|
|
546
|
+
* and the account's current name, through the WebAuthn Signal API, so
|
|
547
|
+
* they stop offering removed passkeys. Call it after sign-in, after
|
|
548
|
+
* removing a passkey, and after a rename. It does nothing where the
|
|
549
|
+
* browser lacks the API.
|
|
550
|
+
*/
|
|
551
|
+
syncPasskeys(): Promise<void>;
|
|
552
|
+
private readFresh;
|
|
553
|
+
private cancelAutofill;
|
|
554
|
+
private notify;
|
|
555
|
+
private begin;
|
|
556
|
+
private finish;
|
|
557
|
+
private assert;
|
|
558
|
+
private register;
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Derives a non-extractable AES-GCM key from a passkey's PRF output, for
|
|
562
|
+
* secrets the server never sees. `purpose` separates keys for different
|
|
563
|
+
* uses of the same passkey. It returns `unsupported` when the output is
|
|
564
|
+
* missing, so the page can offer its fallback, such as a passphrase.
|
|
565
|
+
*/
|
|
566
|
+
export declare function deriveKey(prfOutput: ArrayBuffer | undefined, purpose: string): Promise<CryptoKey | 'unsupported'>;
|
|
567
|
+
/** Creates an auth client. */
|
|
568
|
+
export declare function createAuthClient(opts?: ClientOptions): AuthClient;
|
|
569
|
+
export { toBase64url };
|