@hyper.authio/server 0.0.0-stage → 0.1.1
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/README.md +114 -2
- package/dist/index.cjs +739 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +439 -0
- package/dist/index.d.ts +439 -0
- package/dist/index.js +714 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
import { AuthioResourceAccess, AuthioResourceAccessSource, AuthioError, AuthioConnection, AuthioDiscoveryClient, AuthioClient, AuthioConnectionOptions, AuthioClientOptions, AuthioWebhookEvent, AuthioClock, AuthioWebhookDataByType, AuthioTypedWebhookEvent, AuthioClientCredentialsToken } from '@hyper.authio/client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The party acting for the subject, from the `act` claim (RFC 8693): who exchanged the token, nested when the chain
|
|
5
|
+
* is longer.
|
|
6
|
+
*/
|
|
7
|
+
interface AuthioActor {
|
|
8
|
+
readonly clientId: string | undefined;
|
|
9
|
+
readonly subject: string | undefined;
|
|
10
|
+
readonly actor: AuthioActor | undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Where the user reads flat (non-`*_resource_access`) roles and groups from.
|
|
14
|
+
*/
|
|
15
|
+
interface AuthioUserClaimSettings {
|
|
16
|
+
/**
|
|
17
|
+
* Claims holding role names directly, such as one written by a claim mapper with the Role source. They count for
|
|
18
|
+
* `hasRole` without a source filter. Defaults to `["role"]`.
|
|
19
|
+
*/
|
|
20
|
+
roleClaims?: readonly string[];
|
|
21
|
+
/**
|
|
22
|
+
* Claims holding group names, such as one written by a claim mapper with the Group source. Defaults to
|
|
23
|
+
* `["groups"]`.
|
|
24
|
+
*/
|
|
25
|
+
groupClaims?: readonly string[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The caller of an API, read from a validated access token or an introspection answer: identity, every form of
|
|
29
|
+
* permission Authio issues, and the raw claims for anything else.
|
|
30
|
+
*/
|
|
31
|
+
declare class AuthioUser {
|
|
32
|
+
/** `sub`: the person's id, or the credential's for a machine caller. */
|
|
33
|
+
readonly subject: string;
|
|
34
|
+
/** The client the token was issued to (`azp`, else `client_id`). */
|
|
35
|
+
readonly clientId: string | undefined;
|
|
36
|
+
/** `sid`. */
|
|
37
|
+
readonly sessionId: string | undefined;
|
|
38
|
+
/** `jti`. */
|
|
39
|
+
readonly tokenId: string | undefined;
|
|
40
|
+
/** `aud`. */
|
|
41
|
+
readonly audiences: readonly string[];
|
|
42
|
+
/** The granted scopes. */
|
|
43
|
+
readonly scopes: readonly string[];
|
|
44
|
+
/** The roles of the seven `*_resource_access` claims, with their source and permissions. */
|
|
45
|
+
readonly resourceAccess: AuthioResourceAccess;
|
|
46
|
+
/** Every role name: the `*_resource_access` roles, then the flat role claims. */
|
|
47
|
+
readonly roles: readonly string[];
|
|
48
|
+
/** Resource → every method any role allows on it. */
|
|
49
|
+
readonly permissions: Readonly<Record<string, readonly string[]>>;
|
|
50
|
+
/** The group names of the group claims. */
|
|
51
|
+
readonly groups: readonly string[];
|
|
52
|
+
/** `org_id`. */
|
|
53
|
+
readonly organizationId: string | undefined;
|
|
54
|
+
/** `org_alias`. */
|
|
55
|
+
readonly organizationAlias: string | undefined;
|
|
56
|
+
/** `account_id`. */
|
|
57
|
+
readonly accountId: string | undefined;
|
|
58
|
+
/** `acr`. */
|
|
59
|
+
readonly acr: string | undefined;
|
|
60
|
+
/** `acr` as a number: 1 one factor, 2 several, 3 one of them phishing-resistant. */
|
|
61
|
+
readonly authenticationLevel: number | undefined;
|
|
62
|
+
/** `amr`. */
|
|
63
|
+
readonly authenticationMethods: readonly string[];
|
|
64
|
+
/** `idp`. */
|
|
65
|
+
readonly identityProvider: string | undefined;
|
|
66
|
+
/** `auth_time`. */
|
|
67
|
+
readonly authenticatedAt: Date | undefined;
|
|
68
|
+
/** `act`. */
|
|
69
|
+
readonly actor: AuthioActor | undefined;
|
|
70
|
+
/** `delegation_id`. */
|
|
71
|
+
readonly delegationId: string | undefined;
|
|
72
|
+
readonly email: string | undefined;
|
|
73
|
+
readonly emailVerified: boolean | undefined;
|
|
74
|
+
readonly name: string | undefined;
|
|
75
|
+
readonly preferredUsername: string | undefined;
|
|
76
|
+
/** `credential_type`, on a token issued to an account credential or a consumer. */
|
|
77
|
+
readonly credentialType: string | undefined;
|
|
78
|
+
/** `credential_id`. */
|
|
79
|
+
readonly credentialId: string | undefined;
|
|
80
|
+
/** Every claim, as the token or the introspection answer carried it. */
|
|
81
|
+
readonly claims: Readonly<Record<string, unknown>>;
|
|
82
|
+
/** The access token the user was read from. Not enumerable, so it stays out of logs and JSON. */
|
|
83
|
+
readonly token: string | undefined;
|
|
84
|
+
private readonly flatRoles;
|
|
85
|
+
/**
|
|
86
|
+
* @param claims The token's payload, or the introspection answer's members.
|
|
87
|
+
* @param settings Where flat roles and groups are read from.
|
|
88
|
+
* @param token The access token, kept for forwarding and on-behalf-of.
|
|
89
|
+
*/
|
|
90
|
+
constructor(claims: Readonly<Record<string, unknown>>, settings?: AuthioUserClaimSettings, token?: string);
|
|
91
|
+
/** Whether an actor exchanged the token on the subject's behalf. */
|
|
92
|
+
get isDelegated(): boolean;
|
|
93
|
+
/** Whether the scope was granted. */
|
|
94
|
+
hasScope(scope: string): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Whether the user holds the role. Without sources, from any `*_resource_access` claim or a flat role claim; with
|
|
97
|
+
* sources, only from those `*_resource_access` claims.
|
|
98
|
+
*/
|
|
99
|
+
hasRole(role: string, options?: {
|
|
100
|
+
sources?: readonly AuthioResourceAccessSource[];
|
|
101
|
+
}): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Authio's grant rule: whether a role (from any source, or only from the given ones) allows `method` on
|
|
104
|
+
* `resource`. Case-insensitive.
|
|
105
|
+
*/
|
|
106
|
+
hasPermission(resource: string, method: string, options?: {
|
|
107
|
+
sources?: readonly AuthioResourceAccessSource[];
|
|
108
|
+
}): boolean;
|
|
109
|
+
/** Whether the user is in the group (exact match). */
|
|
110
|
+
hasGroup(group: string): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Whether the claim is present (not `null`), and, given values, whether it holds one of them (exact match; an
|
|
113
|
+
* array claim matches when any item does).
|
|
114
|
+
*/
|
|
115
|
+
hasClaim(type: string, ...values: string[]): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* The claim's values as text: one for a scalar, one per item for an array, JSON text for an object.
|
|
118
|
+
*/
|
|
119
|
+
claimValues(type: string): string[];
|
|
120
|
+
/** Every member but the raw token. */
|
|
121
|
+
toJSON(): Record<string, unknown>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* How several required values combine.
|
|
126
|
+
*/
|
|
127
|
+
type AuthioMatch = "any" | "all";
|
|
128
|
+
/**
|
|
129
|
+
* Why a rule refused the caller.
|
|
130
|
+
*/
|
|
131
|
+
interface AuthioRuleFailure {
|
|
132
|
+
/** What is missing, in words. */
|
|
133
|
+
readonly message: string;
|
|
134
|
+
/**
|
|
135
|
+
* The RFC 6750 / RFC 9470 error to put in `WWW-Authenticate`: `insufficient_scope` for scopes,
|
|
136
|
+
* `insufficient_user_authentication` for `acr`/`amr`, none otherwise.
|
|
137
|
+
*/
|
|
138
|
+
readonly error?: "insufficient_scope" | "insufficient_user_authentication";
|
|
139
|
+
/** The required scopes, for `insufficient_scope`. */
|
|
140
|
+
readonly scope?: string;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* A condition on the caller.
|
|
144
|
+
*/
|
|
145
|
+
interface AuthioRule {
|
|
146
|
+
/** What the rule requires, for logs. */
|
|
147
|
+
readonly description: string;
|
|
148
|
+
/** `undefined` when the caller satisfies the rule, else why not. */
|
|
149
|
+
check(user: AuthioUser): AuthioRuleFailure | undefined;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Checks every rule. On refusal the message joins every rule's, and the error is the one asking for a stronger
|
|
153
|
+
* sign-in, else the first one that has an error.
|
|
154
|
+
*/
|
|
155
|
+
declare function authorize(user: AuthioUser, ...rules: AuthioRule[]): AuthioRuleFailure | undefined;
|
|
156
|
+
/**
|
|
157
|
+
* Requires granted scopes.
|
|
158
|
+
*/
|
|
159
|
+
declare function requireScope(scopes: string | readonly string[], match?: AuthioMatch): AuthioRule;
|
|
160
|
+
/**
|
|
161
|
+
* Requires roles, from any source or only from the given `*_resource_access` claims.
|
|
162
|
+
*/
|
|
163
|
+
declare function requireRole(roles: string | readonly string[], options?: {
|
|
164
|
+
match?: AuthioMatch;
|
|
165
|
+
sources?: readonly AuthioResourceAccessSource[];
|
|
166
|
+
}): AuthioRule;
|
|
167
|
+
/**
|
|
168
|
+
* Requires a permission (`method` on `resource`), granted by a role from any source or only from the given ones.
|
|
169
|
+
*/
|
|
170
|
+
declare function requirePermission(resource: string, method: string, options?: {
|
|
171
|
+
sources?: readonly AuthioResourceAccessSource[];
|
|
172
|
+
}): AuthioRule;
|
|
173
|
+
/**
|
|
174
|
+
* Requires groups, read from the group claims (a claim mapper with the Group source).
|
|
175
|
+
*/
|
|
176
|
+
declare function requireGroup(groups: string | readonly string[], match?: AuthioMatch): AuthioRule;
|
|
177
|
+
/**
|
|
178
|
+
* Requires a claim: present, or holding one of the given values. Fits claim-mapper claims, the user's own claims and
|
|
179
|
+
* any other claim Authio issues.
|
|
180
|
+
*/
|
|
181
|
+
declare function requireClaim(type: string, ...values: string[]): AuthioRule;
|
|
182
|
+
/**
|
|
183
|
+
* Requires an organization context, or a given organization (alias or id, case-insensitive).
|
|
184
|
+
*/
|
|
185
|
+
declare function requireOrganization(organization?: string): AuthioRule;
|
|
186
|
+
/**
|
|
187
|
+
* Requires a minimum authentication level (`acr`): 1 one factor, 2 several, 3 one of them phishing-resistant.
|
|
188
|
+
*/
|
|
189
|
+
declare function requireAuthenticationLevel(minimumLevel: number): AuthioRule;
|
|
190
|
+
/**
|
|
191
|
+
* Requires authentication methods (`amr`, case-insensitive), such as `otp`, `swk` or `fed`.
|
|
192
|
+
*/
|
|
193
|
+
declare function requireAuthenticationMethod(methods: string | readonly string[], match?: AuthioMatch): AuthioRule;
|
|
194
|
+
/**
|
|
195
|
+
* Requires the token to have been issued to one of the clients (`azp`, else `client_id`).
|
|
196
|
+
*/
|
|
197
|
+
declare function requireClient(clientIds: string | readonly string[]): AuthioRule;
|
|
198
|
+
/**
|
|
199
|
+
* Requires every rule.
|
|
200
|
+
*/
|
|
201
|
+
declare function allOf(...rules: AuthioRule[]): AuthioRule;
|
|
202
|
+
/**
|
|
203
|
+
* Requires at least one rule; the refusal is the first rule's.
|
|
204
|
+
*/
|
|
205
|
+
declare function anyOf(...rules: AuthioRule[]): AuthioRule;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* The request carries no valid access token: answer `401` with `wwwAuthenticate`.
|
|
209
|
+
*/
|
|
210
|
+
declare class AuthioBearerError extends AuthioError {
|
|
211
|
+
readonly status = 401;
|
|
212
|
+
/** `invalid_token`, or `undefined` when the request had no token at all (RFC 6750 §3.1). */
|
|
213
|
+
readonly error: "invalid_token" | undefined;
|
|
214
|
+
/** Why the token was refused, safe to send to the caller. */
|
|
215
|
+
readonly description: string | undefined;
|
|
216
|
+
constructor(description: string | undefined, options?: {
|
|
217
|
+
error?: "invalid_token" | undefined;
|
|
218
|
+
cause?: unknown;
|
|
219
|
+
});
|
|
220
|
+
/** The `WWW-Authenticate` value. */
|
|
221
|
+
get wwwAuthenticate(): string;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* The caller is known but not allowed: answer `403`, with `wwwAuthenticate` when the refusal has a bearer error.
|
|
225
|
+
*/
|
|
226
|
+
declare class AuthioForbiddenError extends AuthioError {
|
|
227
|
+
readonly status = 403;
|
|
228
|
+
readonly failure: AuthioRuleFailure;
|
|
229
|
+
constructor(failure: AuthioRuleFailure);
|
|
230
|
+
/** The `WWW-Authenticate` value, or `undefined` when the refusal is not about scopes or the sign-in. */
|
|
231
|
+
get wwwAuthenticate(): string | undefined;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* The `WWW-Authenticate` value of a refusal: `insufficient_scope` (with `scope`) or
|
|
235
|
+
* `insufficient_user_authentication`.
|
|
236
|
+
*/
|
|
237
|
+
declare function toForbiddenChallenge(failure: AuthioRuleFailure): string | undefined;
|
|
238
|
+
/**
|
|
239
|
+
* Problem details (RFC 9457) for a `401` or `403`.
|
|
240
|
+
*/
|
|
241
|
+
declare function toProblemDetails(error: AuthioBearerError | AuthioForbiddenError): Record<string, unknown>;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Whether and how Authio's introspection endpoint takes part in validating a token.
|
|
245
|
+
*
|
|
246
|
+
* - `none`: the JWT is validated locally (signature, issuer, audience, lifetime). Fastest; a revoked token stays
|
|
247
|
+
* valid until it expires.
|
|
248
|
+
* - `activeCheck`: validated locally, then confirmed active by introspection (cached per `jti`).
|
|
249
|
+
* - `introspectionOnly`: introspection alone, for opaque (reference) or encrypted tokens.
|
|
250
|
+
*/
|
|
251
|
+
type AuthioIntrospectionMode = "none" | "activeCheck" | "introspectionOnly";
|
|
252
|
+
/**
|
|
253
|
+
* How an API validates Authio access tokens.
|
|
254
|
+
*/
|
|
255
|
+
interface AuthioVerifierOptions extends AuthioConnectionOptions, AuthioUserClaimSettings {
|
|
256
|
+
/** The audiences this API accepts: its resource identifier (RFC 8707) or client id. Required. */
|
|
257
|
+
audiences: string | readonly string[];
|
|
258
|
+
/** Defaults to `none`. */
|
|
259
|
+
introspection?: AuthioIntrospectionMode;
|
|
260
|
+
/**
|
|
261
|
+
* The API's confidential client, for introspection: a client already created, or its options (issuer settings are
|
|
262
|
+
* taken from these options when absent). It must be the client the resource server names as its introspection
|
|
263
|
+
* client, since Authio answers introspection according to who asks.
|
|
264
|
+
*/
|
|
265
|
+
client?: AuthioClient | Omit<AuthioClientOptions, keyof AuthioConnectionOptions>;
|
|
266
|
+
/** Seconds an active introspection answer is kept (never past the token's expiry). Defaults to 30. */
|
|
267
|
+
introspectionCacheDuration?: number;
|
|
268
|
+
/** Seconds of clock skew tolerated on `exp` and `nbf`. Defaults to 30. */
|
|
269
|
+
clockSkew?: number;
|
|
270
|
+
/** Accepted signing algorithms. Defaults to the asymmetric ones (RS*, PS*, ES*). */
|
|
271
|
+
validAlgorithms?: readonly string[];
|
|
272
|
+
/** Refuses a token whose `typ` claim is present and not `Bearer` (an ID token, for one). Defaults to `true`. */
|
|
273
|
+
rejectNonAccessTokens?: boolean;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Validates Authio access tokens and reads the caller.
|
|
277
|
+
*/
|
|
278
|
+
interface AuthioVerifier {
|
|
279
|
+
/** The connection settings. */
|
|
280
|
+
readonly connection: AuthioConnection;
|
|
281
|
+
/** The discovery document. */
|
|
282
|
+
readonly discovery: AuthioDiscoveryClient;
|
|
283
|
+
/** The accepted audiences. */
|
|
284
|
+
readonly audiences: readonly string[];
|
|
285
|
+
/** The introspection mode. */
|
|
286
|
+
readonly introspection: AuthioIntrospectionMode;
|
|
287
|
+
/** The client used for introspection, when there is one. */
|
|
288
|
+
readonly client: AuthioClient | undefined;
|
|
289
|
+
/**
|
|
290
|
+
* Validates a token and reads the caller.
|
|
291
|
+
*
|
|
292
|
+
* @throws AuthioBearerError when the token is not valid for this API.
|
|
293
|
+
*/
|
|
294
|
+
verify(token: string, signal?: AbortSignal): Promise<AuthioUser>;
|
|
295
|
+
/**
|
|
296
|
+
* Validates the token of an `Authorization: Bearer` header.
|
|
297
|
+
*
|
|
298
|
+
* @throws AuthioBearerError without an error code when there is no bearer token, with `invalid_token` when it is
|
|
299
|
+
* not valid.
|
|
300
|
+
*/
|
|
301
|
+
verifyAuthorizationHeader(header: string | null | undefined, signal?: AbortSignal): Promise<AuthioUser>;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Error descriptions of the refusals the SDK makes itself.
|
|
305
|
+
*/
|
|
306
|
+
declare const AuthioBearerErrorDescriptions: {
|
|
307
|
+
readonly Inactive: "Authio reports the token as not active to this API's client. It was revoked or has expired or its session ended; or this API's client is not the introspection client of the resource server the token is for.";
|
|
308
|
+
readonly Unconfirmed: "Authio could not be reached to confirm that the token is active.";
|
|
309
|
+
readonly Empty: "The token is empty.";
|
|
310
|
+
readonly Encrypted: "The token is encrypted; validate it with introspection ('introspectionOnly').";
|
|
311
|
+
readonly SigningKeysUnavailable: "Authio could not be reached to read its signing keys.";
|
|
312
|
+
};
|
|
313
|
+
/**
|
|
314
|
+
* Creates a token verifier.
|
|
315
|
+
*
|
|
316
|
+
* @throws AuthioConfigurationError when no audience is given, or introspection is asked for without a client.
|
|
317
|
+
*/
|
|
318
|
+
declare function createAuthioVerifier(options: AuthioVerifierOptions): AuthioVerifier;
|
|
319
|
+
/**
|
|
320
|
+
* The token of an `Authorization: Bearer` header, or `undefined` when the header is absent or of another scheme.
|
|
321
|
+
*/
|
|
322
|
+
declare function readBearerToken(header: string | null | undefined): string | undefined;
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Remembers delivered event ids, so a redelivery is acknowledged without running the handlers twice.
|
|
326
|
+
*/
|
|
327
|
+
interface AuthioWebhookDeduplicationStore {
|
|
328
|
+
/** Records the id; `false` when it was already recorded within the window. */
|
|
329
|
+
tryBegin(eventId: string, windowMs: number): boolean | Promise<boolean>;
|
|
330
|
+
/** Forgets the id, after a handler failed, so the redelivery runs again. */
|
|
331
|
+
release(eventId: string): void | Promise<void>;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* How webhook deliveries are received.
|
|
335
|
+
*/
|
|
336
|
+
interface AuthioWebhookOptions {
|
|
337
|
+
/** The webhook's secret. */
|
|
338
|
+
secret?: string;
|
|
339
|
+
/** Several secrets, while one is being rotated; a delivery signed with any of them is accepted. */
|
|
340
|
+
secrets?: readonly string[];
|
|
341
|
+
/** Seconds a signature's timestamp may differ from now. Defaults to 300. */
|
|
342
|
+
tolerance?: number;
|
|
343
|
+
/** `memory` (default), `none`, or a store shared between instances. */
|
|
344
|
+
deduplication?: "memory" | "none" | AuthioWebhookDeduplicationStore;
|
|
345
|
+
/** Seconds a delivered id is remembered. Defaults to 86400. */
|
|
346
|
+
deduplicationWindow?: number;
|
|
347
|
+
/** The largest body accepted, in bytes. Defaults to 1 MiB. */
|
|
348
|
+
maxBodySize?: number;
|
|
349
|
+
/** The clock. */
|
|
350
|
+
clock?: AuthioClock;
|
|
351
|
+
/** Called when a delivery is refused or a handler fails. */
|
|
352
|
+
onError?: (error: unknown, context: {
|
|
353
|
+
reason: string;
|
|
354
|
+
eventId?: string;
|
|
355
|
+
eventType?: string;
|
|
356
|
+
}) => void;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* A handler of one event type, or of every type.
|
|
360
|
+
*/
|
|
361
|
+
type AuthioWebhookHandler<E extends AuthioWebhookEvent = AuthioWebhookEvent> = (event: E) => void | Promise<void>;
|
|
362
|
+
/**
|
|
363
|
+
* What to answer a delivery with.
|
|
364
|
+
*/
|
|
365
|
+
interface AuthioWebhookOutcome {
|
|
366
|
+
/** `200` handled, duplicate or ping; `400` unreadable; `401` bad or stale signature; `413` too large; `500` a handler failed. */
|
|
367
|
+
readonly status: 200 | 400 | 401 | 413 | 500;
|
|
368
|
+
/** Why, for logs. */
|
|
369
|
+
readonly reason: "handled" | "duplicate" | "unreadable" | "unsigned" | "too_large" | "handler_failed";
|
|
370
|
+
readonly event?: AuthioWebhookEvent;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Receives Authio webhook deliveries: verifies, deduplicates and dispatches them.
|
|
374
|
+
*/
|
|
375
|
+
interface AuthioWebhooks {
|
|
376
|
+
/** Handles one event type, typed. */
|
|
377
|
+
on<T extends keyof AuthioWebhookDataByType>(type: T, handler: AuthioWebhookHandler<AuthioTypedWebhookEvent<T>>): AuthioWebhooks;
|
|
378
|
+
/** Handles another event type, or `*` for every type. */
|
|
379
|
+
on(type: string, handler: AuthioWebhookHandler): AuthioWebhooks;
|
|
380
|
+
/**
|
|
381
|
+
* Handles a delivery: the body exactly as received and the request headers.
|
|
382
|
+
*/
|
|
383
|
+
handle(delivery: {
|
|
384
|
+
body: string | Uint8Array;
|
|
385
|
+
headers: Headers | Record<string, string | string[] | undefined>;
|
|
386
|
+
}): Promise<AuthioWebhookOutcome>;
|
|
387
|
+
/** The largest body accepted, in bytes. */
|
|
388
|
+
readonly maxBodySize: number;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Creates a webhook receiver. Handlers run in registration order; a `*` handler sees every event.
|
|
392
|
+
*
|
|
393
|
+
* @throws AuthioConfigurationError when no secret is configured.
|
|
394
|
+
*/
|
|
395
|
+
declare function createAuthioWebhooks(options: AuthioWebhookOptions): AuthioWebhooks;
|
|
396
|
+
/**
|
|
397
|
+
* A deduplication store kept in this process's memory.
|
|
398
|
+
*/
|
|
399
|
+
declare function createMemoryDeduplicationStore(clock?: AuthioClock): AuthioWebhookDeduplicationStore;
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Who a downstream call is made for: a caller read by the verifier, or the incoming access token itself.
|
|
403
|
+
*/
|
|
404
|
+
type AuthioDownstreamSubject = AuthioUser | string;
|
|
405
|
+
/**
|
|
406
|
+
* A `fetch` that forwards the caller's own access token, unchanged, to a downstream API that accepts the same
|
|
407
|
+
* audience. Sends no `Authorization` when there is no token.
|
|
408
|
+
*/
|
|
409
|
+
declare function createForwardingFetch(subject: AuthioDownstreamSubject | undefined, inner?: typeof fetch): typeof fetch;
|
|
410
|
+
/**
|
|
411
|
+
* Exchanges the caller's token for one addressed to a downstream API (RFC 8693), and caches it.
|
|
412
|
+
*/
|
|
413
|
+
interface AuthioOnBehalfOf {
|
|
414
|
+
/**
|
|
415
|
+
* A token for the downstream API on the caller's behalf: cached per incoming `jti` (else token hash), resource and
|
|
416
|
+
* sorted scopes, renewed `tokenRefreshSkew` before expiry (at most half its lifetime); concurrent callers share
|
|
417
|
+
* one exchange.
|
|
418
|
+
*
|
|
419
|
+
* @throws AuthioError when there is no incoming token.
|
|
420
|
+
*/
|
|
421
|
+
getToken(subject: AuthioDownstreamSubject | undefined, signal?: AbortSignal): Promise<AuthioClientCredentialsToken>;
|
|
422
|
+
/** Drops a cached token; with `accessToken`, only when the cache still holds that token. */
|
|
423
|
+
invalidate(subject: AuthioDownstreamSubject, accessToken?: string): Promise<void>;
|
|
424
|
+
/** A `fetch` that sends the exchanged token, and on a `401` drops it and retries once. */
|
|
425
|
+
fetch(subject: AuthioDownstreamSubject | undefined, inner?: typeof fetch): typeof fetch;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Creates an on-behalf-of exchanger.
|
|
429
|
+
*
|
|
430
|
+
* @param options `client` (the API's confidential client), the downstream `resource` and `scopes`.
|
|
431
|
+
*/
|
|
432
|
+
declare function createOnBehalfOf(options: {
|
|
433
|
+
client: AuthioClient;
|
|
434
|
+
resource?: string;
|
|
435
|
+
scopes?: Iterable<string> | string;
|
|
436
|
+
tokenRefreshSkew?: number;
|
|
437
|
+
}): AuthioOnBehalfOf;
|
|
438
|
+
|
|
439
|
+
export { type AuthioActor, AuthioBearerError, AuthioBearerErrorDescriptions, type AuthioDownstreamSubject, AuthioForbiddenError, type AuthioIntrospectionMode, type AuthioMatch, type AuthioOnBehalfOf, type AuthioRule, type AuthioRuleFailure, AuthioUser, type AuthioUserClaimSettings, type AuthioVerifier, type AuthioVerifierOptions, type AuthioWebhookDeduplicationStore, type AuthioWebhookHandler, type AuthioWebhookOptions, type AuthioWebhookOutcome, type AuthioWebhooks, allOf, anyOf, authorize, createAuthioVerifier, createAuthioWebhooks, createForwardingFetch, createMemoryDeduplicationStore, createOnBehalfOf, readBearerToken, requireAuthenticationLevel, requireAuthenticationMethod, requireClaim, requireClient, requireGroup, requireOrganization, requirePermission, requireRole, requireScope, toForbiddenChallenge, toProblemDetails };
|