@hyper.authio/testing 0.7.0 → 0.8.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/dist/index.d.cts CHANGED
@@ -9,8 +9,8 @@ interface FakeAuthioClientEncryption {
9
9
  key: JWK;
10
10
  /** Defaults to `RSA-OAEP-256`. */
11
11
  algorithm?: "RSA-OAEP" | "RSA-OAEP-256";
12
- /** Defaults to `A256CBC-HS512`. */
13
- encryptionMethod?: "A128CBC-HS256" | "A192CBC-HS384" | "A256CBC-HS512";
12
+ /** The content encryption (JWE `enc`), CBC-HS or GCM as Authio offers them. Defaults to `A256CBC-HS512`. */
13
+ encryptionMethod?: "A128CBC-HS256" | "A192CBC-HS384" | "A256CBC-HS512" | "A128GCM" | "A192GCM" | "A256GCM";
14
14
  /** Encrypts the client's access tokens (nested JWT). */
15
15
  accessTokens?: boolean;
16
16
  /** Encrypts the client's ID tokens. Defaults to `true`. */
@@ -21,14 +21,49 @@ interface FakeAuthioClientEncryption {
21
21
  logoutTokens?: boolean;
22
22
  }
23
23
  /**
24
- * A client registered in the fake.
24
+ * How a client authenticates to the token, introspection, revocation and device endpoints, as registered in Authio.
25
+ */
26
+ type FakeAuthioTokenEndpointAuthMethod = "client_secret_basic" | "client_secret_post" | "private_key_jwt" | "none";
27
+ /**
28
+ * The algorithm Authio signs every token of a client with: the realm's RSA key, or the client secret (HS*).
29
+ */
30
+ type FakeAuthioSigningAlgorithm = "RS256" | "HS256" | "HS384" | "HS512";
31
+ /**
32
+ * A client registered in the fake, configured as a client is in Authio's console. What the client requires is
33
+ * enforced as Authio enforces it: a request that does not match is refused with an error naming the setting, and
34
+ * what the client does not require is accepted (PKCE sent voluntarily, a secret sent by a public client).
25
35
  */
26
36
  interface FakeAuthioClient {
27
37
  clientId: string;
28
- /** For `client_secret_basic` and `client_secret_post`. */
38
+ /** For `client_secret_basic` and `client_secret_post`, and the key of HS* signatures. */
29
39
  clientSecret?: string;
30
40
  /** The public JWK `private_key_jwt` assertions are verified with. */
31
41
  publicKey?: JWK;
42
+ /**
43
+ * How the client must authenticate; another method is refused with `invalid_client`, except a secret sent by a
44
+ * `none` client, which is ignored. Defaults to `client_secret_basic` with a `clientSecret`, `private_key_jwt` with
45
+ * only a `publicKey`, and `none` with neither.
46
+ */
47
+ tokenEndpointAuthMethod?: FakeAuthioTokenEndpointAuthMethod;
48
+ /**
49
+ * Refuses an authorization request without `code_challenge` (Authio's "PKCE" switch). Defaults to `true`, as Authio
50
+ * creates clients; set `false` for a client with PKCE off.
51
+ */
52
+ requirePkce?: boolean;
53
+ /**
54
+ * The PKCE methods accepted, required or not: a `code_challenge` with another method is refused. Defaults to
55
+ * `["S256"]`, as Authio creates clients.
56
+ */
57
+ pkceMethods?: ("S256" | "plain")[];
58
+ /**
59
+ * The algorithm the client's ID tokens, signed UserInfo and logout tokens are signed with. Defaults to `RS256`. HS*
60
+ * needs a `clientSecret` of at least 32, 48 or 64 bytes (RFC 7518 §3.2), as Authio requires.
61
+ */
62
+ signingAlgorithm?: FakeAuthioSigningAlgorithm;
63
+ /** The algorithm the client's access tokens are signed with, Authio's second setting. Defaults to `RS256`. */
64
+ accessTokenSigningAlgorithm?: FakeAuthioSigningAlgorithm;
65
+ /** Issues a new ID token with every refresh. Defaults to `false`. */
66
+ issueIdTokenOnRefresh?: boolean;
32
67
  /** Scopes granted when a request names none. */
33
68
  defaultScopes?: string[];
34
69
  /** Extra claims put into every access token issued to the client. */
@@ -41,6 +76,10 @@ interface FakeAuthioClient {
41
76
  postLogoutRedirectUris?: string[];
42
77
  /** Where back-channel logout tokens are posted when a session of the client ends. */
43
78
  backchannelLogoutUri?: string;
79
+ /** The page loaded (here: fetched) when a session of the client ends (front-channel logout). */
80
+ frontchannelLogoutUri?: string;
81
+ /** Adds `iss` and `sid` to the front-channel logout URI. Defaults to `false`. */
82
+ frontchannelLogoutSessionRequired?: boolean;
44
83
  /** Encrypts what is issued to the client. */
45
84
  encryption?: FakeAuthioClientEncryption;
46
85
  }
@@ -104,6 +143,16 @@ interface FakeAuthioBackchannelDelivery {
104
143
  /** The HTTP status the client answered, or 0 when it could not be reached. */
105
144
  status: number;
106
145
  }
146
+ /**
147
+ * A front-channel logout page the fake loaded for a client.
148
+ */
149
+ interface FakeAuthioFrontchannelDelivery {
150
+ clientId: string;
151
+ /** The URL loaded, with `iss` and `sid` when the client requires the session. */
152
+ url: string;
153
+ /** The HTTP status the client answered, or 0 when it could not be reached. */
154
+ status: number;
155
+ }
107
156
  /**
108
157
  * The parameters an authorization ended with, as the fake sent them back.
109
158
  */
@@ -128,6 +177,13 @@ interface FakeAuthioOptions {
128
177
  clients?: FakeAuthioClient[];
129
178
  users?: FakeAuthioUser[];
130
179
  personalAccessTokens?: FakeAuthioPersonalAccessToken[];
180
+ /**
181
+ * The clock tokens are issued and checked with (milliseconds since the epoch), such as the `ManualClock` the
182
+ * library under test uses. Defaults to the system clock.
183
+ */
184
+ clock?: {
185
+ now(): number;
186
+ };
131
187
  }
132
188
  /**
133
189
  * Options of a token minted directly.
@@ -157,11 +213,12 @@ interface FakeAuthioTokenOptions {
157
213
  }
158
214
  type Endpoint = "token" | "introspect" | "revoke" | "userinfo" | "device" | "discovery" | "authorize" | "logout";
159
215
  /**
160
- * An in-memory Authio realm served over HTTP on loopback: discovery, JWKS, authorization (PKCE, `state`, `nonce`,
161
- * `prompt`, `max_age`, `acr_values`, `response_mode=web_message`, RFC 9207 `iss`), token (client credentials,
162
- * authorization code with ID tokens, refresh, token exchange, password, device code, personal access token),
163
- * introspection, revocation, UserInfo, device authorization, end session and back-channel logout delivery, with JWE
164
- * (RSA-OAEP, RSA-OAEP-256) for clients that registered an encryption key.
216
+ * An in-memory Authio realm served over HTTP on loopback: discovery, JWKS, authorization (PKCE required or not and its
217
+ * allowed methods, `state`, `nonce`, `prompt`, `max_age`, `acr_values`, `response_mode` query or web_message, RFC 9207
218
+ * `iss`), token (client credentials, authorization code with ID tokens, refresh, token exchange, password, device code,
219
+ * personal access token) with the client's exact authentication method, introspection, revocation, UserInfo, device
220
+ * authorization, end session, back-channel and front-channel logout delivery, tokens signed RS256 or HS* with the
221
+ * client secret, and JWE (RSA-OAEP, RSA-OAEP-256) for clients that registered an encryption key.
165
222
  */
166
223
  declare class FakeAuthio {
167
224
  /** Every request received, in order. */
@@ -170,6 +227,8 @@ declare class FakeAuthio {
170
227
  readonly failures: Map<Endpoint, FakeAuthioError[]>;
171
228
  /** Every back-channel logout token posted, in order. */
172
229
  readonly backchannelDeliveries: FakeAuthioBackchannelDelivery[];
230
+ /** Every front-channel logout page loaded, in order. */
231
+ readonly frontchannelDeliveries: FakeAuthioFrontchannelDelivery[];
173
232
  /** What successive device-code polls answer; the last value repeats. Defaults to `["approved"]`. */
174
233
  deviceOutcomes: FakeAuthioDeviceOutcome[];
175
234
  /** Overrides the discovery document's issuer, to test the mismatch check. */
@@ -190,6 +249,7 @@ declare class FakeAuthio {
190
249
  private readonly issued;
191
250
  private readonly devicePolls;
192
251
  private readonly lifetime;
252
+ private readonly clock;
193
253
  private session;
194
254
  private server;
195
255
  private signingKey;
@@ -267,6 +327,20 @@ declare class FakeAuthio {
267
327
  sub?: string;
268
328
  sid?: string;
269
329
  }): Promise<number>;
330
+ /**
331
+ * The front-channel logout URL of a client for a session: its `frontchannelLogoutUri`, with `iss` and `sid` when the
332
+ * client requires the session.
333
+ */
334
+ frontchannelLogoutUrl(clientId: string, sid: string): string;
335
+ /**
336
+ * Loads the client's front-channel logout page, as the browser does in an iframe when Authio ends a session.
337
+ *
338
+ * @returns The HTTP status the client answered, or 0 when it could not be reached.
339
+ */
340
+ deliverFrontchannelLogout(clientId: string, options: {
341
+ sid: string;
342
+ headers?: Record<string, string>;
343
+ }): Promise<number>;
270
344
  /** Marks a token revoked, as Authio would after a sign-out: an access token, or a refresh token, which is then forgotten. */
271
345
  revokeToken(token: string): void;
272
346
  /** Revokes every refresh token of a person, or of one Authio session (`sid`), as Authio does when a session ends. */
@@ -292,6 +366,9 @@ declare class FakeAuthio {
292
366
  private revoke;
293
367
  private device;
294
368
  private userInfo;
369
+ private nowSeconds;
370
+ private sign;
371
+ private verificationKeyFor;
295
372
  private requireUser;
296
373
  }
297
374
 
@@ -339,4 +416,4 @@ declare function createWebhookDelivery(type: string, data: unknown, secret: stri
339
416
  sendEventIdHeader?: boolean;
340
417
  }): Promise<FakeWebhookDelivery>;
341
418
 
342
- export { FakeAuthio, type FakeAuthioAuthorizationOutcome, type FakeAuthioBackchannelDelivery, type FakeAuthioClient, type FakeAuthioClientEncryption, type FakeAuthioDeviceOutcome, type FakeAuthioError, type FakeAuthioOptions, type FakeAuthioPersonalAccessToken, type FakeAuthioRecordedRequest, type FakeAuthioTokenOptions, type FakeAuthioUser, type FakeWebhookDelivery, ManualClock, createWebhookDelivery };
419
+ export { FakeAuthio, type FakeAuthioAuthorizationOutcome, type FakeAuthioBackchannelDelivery, type FakeAuthioClient, type FakeAuthioClientEncryption, type FakeAuthioDeviceOutcome, type FakeAuthioError, type FakeAuthioFrontchannelDelivery, type FakeAuthioOptions, type FakeAuthioPersonalAccessToken, type FakeAuthioRecordedRequest, type FakeAuthioSigningAlgorithm, type FakeAuthioTokenEndpointAuthMethod, type FakeAuthioTokenOptions, type FakeAuthioUser, type FakeWebhookDelivery, ManualClock, createWebhookDelivery };
package/dist/index.d.ts CHANGED
@@ -9,8 +9,8 @@ interface FakeAuthioClientEncryption {
9
9
  key: JWK;
10
10
  /** Defaults to `RSA-OAEP-256`. */
11
11
  algorithm?: "RSA-OAEP" | "RSA-OAEP-256";
12
- /** Defaults to `A256CBC-HS512`. */
13
- encryptionMethod?: "A128CBC-HS256" | "A192CBC-HS384" | "A256CBC-HS512";
12
+ /** The content encryption (JWE `enc`), CBC-HS or GCM as Authio offers them. Defaults to `A256CBC-HS512`. */
13
+ encryptionMethod?: "A128CBC-HS256" | "A192CBC-HS384" | "A256CBC-HS512" | "A128GCM" | "A192GCM" | "A256GCM";
14
14
  /** Encrypts the client's access tokens (nested JWT). */
15
15
  accessTokens?: boolean;
16
16
  /** Encrypts the client's ID tokens. Defaults to `true`. */
@@ -21,14 +21,49 @@ interface FakeAuthioClientEncryption {
21
21
  logoutTokens?: boolean;
22
22
  }
23
23
  /**
24
- * A client registered in the fake.
24
+ * How a client authenticates to the token, introspection, revocation and device endpoints, as registered in Authio.
25
+ */
26
+ type FakeAuthioTokenEndpointAuthMethod = "client_secret_basic" | "client_secret_post" | "private_key_jwt" | "none";
27
+ /**
28
+ * The algorithm Authio signs every token of a client with: the realm's RSA key, or the client secret (HS*).
29
+ */
30
+ type FakeAuthioSigningAlgorithm = "RS256" | "HS256" | "HS384" | "HS512";
31
+ /**
32
+ * A client registered in the fake, configured as a client is in Authio's console. What the client requires is
33
+ * enforced as Authio enforces it: a request that does not match is refused with an error naming the setting, and
34
+ * what the client does not require is accepted (PKCE sent voluntarily, a secret sent by a public client).
25
35
  */
26
36
  interface FakeAuthioClient {
27
37
  clientId: string;
28
- /** For `client_secret_basic` and `client_secret_post`. */
38
+ /** For `client_secret_basic` and `client_secret_post`, and the key of HS* signatures. */
29
39
  clientSecret?: string;
30
40
  /** The public JWK `private_key_jwt` assertions are verified with. */
31
41
  publicKey?: JWK;
42
+ /**
43
+ * How the client must authenticate; another method is refused with `invalid_client`, except a secret sent by a
44
+ * `none` client, which is ignored. Defaults to `client_secret_basic` with a `clientSecret`, `private_key_jwt` with
45
+ * only a `publicKey`, and `none` with neither.
46
+ */
47
+ tokenEndpointAuthMethod?: FakeAuthioTokenEndpointAuthMethod;
48
+ /**
49
+ * Refuses an authorization request without `code_challenge` (Authio's "PKCE" switch). Defaults to `true`, as Authio
50
+ * creates clients; set `false` for a client with PKCE off.
51
+ */
52
+ requirePkce?: boolean;
53
+ /**
54
+ * The PKCE methods accepted, required or not: a `code_challenge` with another method is refused. Defaults to
55
+ * `["S256"]`, as Authio creates clients.
56
+ */
57
+ pkceMethods?: ("S256" | "plain")[];
58
+ /**
59
+ * The algorithm the client's ID tokens, signed UserInfo and logout tokens are signed with. Defaults to `RS256`. HS*
60
+ * needs a `clientSecret` of at least 32, 48 or 64 bytes (RFC 7518 §3.2), as Authio requires.
61
+ */
62
+ signingAlgorithm?: FakeAuthioSigningAlgorithm;
63
+ /** The algorithm the client's access tokens are signed with, Authio's second setting. Defaults to `RS256`. */
64
+ accessTokenSigningAlgorithm?: FakeAuthioSigningAlgorithm;
65
+ /** Issues a new ID token with every refresh. Defaults to `false`. */
66
+ issueIdTokenOnRefresh?: boolean;
32
67
  /** Scopes granted when a request names none. */
33
68
  defaultScopes?: string[];
34
69
  /** Extra claims put into every access token issued to the client. */
@@ -41,6 +76,10 @@ interface FakeAuthioClient {
41
76
  postLogoutRedirectUris?: string[];
42
77
  /** Where back-channel logout tokens are posted when a session of the client ends. */
43
78
  backchannelLogoutUri?: string;
79
+ /** The page loaded (here: fetched) when a session of the client ends (front-channel logout). */
80
+ frontchannelLogoutUri?: string;
81
+ /** Adds `iss` and `sid` to the front-channel logout URI. Defaults to `false`. */
82
+ frontchannelLogoutSessionRequired?: boolean;
44
83
  /** Encrypts what is issued to the client. */
45
84
  encryption?: FakeAuthioClientEncryption;
46
85
  }
@@ -104,6 +143,16 @@ interface FakeAuthioBackchannelDelivery {
104
143
  /** The HTTP status the client answered, or 0 when it could not be reached. */
105
144
  status: number;
106
145
  }
146
+ /**
147
+ * A front-channel logout page the fake loaded for a client.
148
+ */
149
+ interface FakeAuthioFrontchannelDelivery {
150
+ clientId: string;
151
+ /** The URL loaded, with `iss` and `sid` when the client requires the session. */
152
+ url: string;
153
+ /** The HTTP status the client answered, or 0 when it could not be reached. */
154
+ status: number;
155
+ }
107
156
  /**
108
157
  * The parameters an authorization ended with, as the fake sent them back.
109
158
  */
@@ -128,6 +177,13 @@ interface FakeAuthioOptions {
128
177
  clients?: FakeAuthioClient[];
129
178
  users?: FakeAuthioUser[];
130
179
  personalAccessTokens?: FakeAuthioPersonalAccessToken[];
180
+ /**
181
+ * The clock tokens are issued and checked with (milliseconds since the epoch), such as the `ManualClock` the
182
+ * library under test uses. Defaults to the system clock.
183
+ */
184
+ clock?: {
185
+ now(): number;
186
+ };
131
187
  }
132
188
  /**
133
189
  * Options of a token minted directly.
@@ -157,11 +213,12 @@ interface FakeAuthioTokenOptions {
157
213
  }
158
214
  type Endpoint = "token" | "introspect" | "revoke" | "userinfo" | "device" | "discovery" | "authorize" | "logout";
159
215
  /**
160
- * An in-memory Authio realm served over HTTP on loopback: discovery, JWKS, authorization (PKCE, `state`, `nonce`,
161
- * `prompt`, `max_age`, `acr_values`, `response_mode=web_message`, RFC 9207 `iss`), token (client credentials,
162
- * authorization code with ID tokens, refresh, token exchange, password, device code, personal access token),
163
- * introspection, revocation, UserInfo, device authorization, end session and back-channel logout delivery, with JWE
164
- * (RSA-OAEP, RSA-OAEP-256) for clients that registered an encryption key.
216
+ * An in-memory Authio realm served over HTTP on loopback: discovery, JWKS, authorization (PKCE required or not and its
217
+ * allowed methods, `state`, `nonce`, `prompt`, `max_age`, `acr_values`, `response_mode` query or web_message, RFC 9207
218
+ * `iss`), token (client credentials, authorization code with ID tokens, refresh, token exchange, password, device code,
219
+ * personal access token) with the client's exact authentication method, introspection, revocation, UserInfo, device
220
+ * authorization, end session, back-channel and front-channel logout delivery, tokens signed RS256 or HS* with the
221
+ * client secret, and JWE (RSA-OAEP, RSA-OAEP-256) for clients that registered an encryption key.
165
222
  */
166
223
  declare class FakeAuthio {
167
224
  /** Every request received, in order. */
@@ -170,6 +227,8 @@ declare class FakeAuthio {
170
227
  readonly failures: Map<Endpoint, FakeAuthioError[]>;
171
228
  /** Every back-channel logout token posted, in order. */
172
229
  readonly backchannelDeliveries: FakeAuthioBackchannelDelivery[];
230
+ /** Every front-channel logout page loaded, in order. */
231
+ readonly frontchannelDeliveries: FakeAuthioFrontchannelDelivery[];
173
232
  /** What successive device-code polls answer; the last value repeats. Defaults to `["approved"]`. */
174
233
  deviceOutcomes: FakeAuthioDeviceOutcome[];
175
234
  /** Overrides the discovery document's issuer, to test the mismatch check. */
@@ -190,6 +249,7 @@ declare class FakeAuthio {
190
249
  private readonly issued;
191
250
  private readonly devicePolls;
192
251
  private readonly lifetime;
252
+ private readonly clock;
193
253
  private session;
194
254
  private server;
195
255
  private signingKey;
@@ -267,6 +327,20 @@ declare class FakeAuthio {
267
327
  sub?: string;
268
328
  sid?: string;
269
329
  }): Promise<number>;
330
+ /**
331
+ * The front-channel logout URL of a client for a session: its `frontchannelLogoutUri`, with `iss` and `sid` when the
332
+ * client requires the session.
333
+ */
334
+ frontchannelLogoutUrl(clientId: string, sid: string): string;
335
+ /**
336
+ * Loads the client's front-channel logout page, as the browser does in an iframe when Authio ends a session.
337
+ *
338
+ * @returns The HTTP status the client answered, or 0 when it could not be reached.
339
+ */
340
+ deliverFrontchannelLogout(clientId: string, options: {
341
+ sid: string;
342
+ headers?: Record<string, string>;
343
+ }): Promise<number>;
270
344
  /** Marks a token revoked, as Authio would after a sign-out: an access token, or a refresh token, which is then forgotten. */
271
345
  revokeToken(token: string): void;
272
346
  /** Revokes every refresh token of a person, or of one Authio session (`sid`), as Authio does when a session ends. */
@@ -292,6 +366,9 @@ declare class FakeAuthio {
292
366
  private revoke;
293
367
  private device;
294
368
  private userInfo;
369
+ private nowSeconds;
370
+ private sign;
371
+ private verificationKeyFor;
295
372
  private requireUser;
296
373
  }
297
374
 
@@ -339,4 +416,4 @@ declare function createWebhookDelivery(type: string, data: unknown, secret: stri
339
416
  sendEventIdHeader?: boolean;
340
417
  }): Promise<FakeWebhookDelivery>;
341
418
 
342
- export { FakeAuthio, type FakeAuthioAuthorizationOutcome, type FakeAuthioBackchannelDelivery, type FakeAuthioClient, type FakeAuthioClientEncryption, type FakeAuthioDeviceOutcome, type FakeAuthioError, type FakeAuthioOptions, type FakeAuthioPersonalAccessToken, type FakeAuthioRecordedRequest, type FakeAuthioTokenOptions, type FakeAuthioUser, type FakeWebhookDelivery, ManualClock, createWebhookDelivery };
419
+ export { FakeAuthio, type FakeAuthioAuthorizationOutcome, type FakeAuthioBackchannelDelivery, type FakeAuthioClient, type FakeAuthioClientEncryption, type FakeAuthioDeviceOutcome, type FakeAuthioError, type FakeAuthioFrontchannelDelivery, type FakeAuthioOptions, type FakeAuthioPersonalAccessToken, type FakeAuthioRecordedRequest, type FakeAuthioSigningAlgorithm, type FakeAuthioTokenEndpointAuthMethod, type FakeAuthioTokenOptions, type FakeAuthioUser, type FakeWebhookDelivery, ManualClock, createWebhookDelivery };