@auth0/auth0-server-js 1.2.0 → 1.4.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/README.md +6 -1
- package/dist/index.cjs +344 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +89 -8
- package/dist/index.d.ts +89 -8
- package/dist/index.js +340 -47
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,32 @@
|
|
|
1
|
-
import { AuthorizationDetails, AuthClient } from '@auth0/auth0-auth-js';
|
|
1
|
+
import { AuthorizationDetails, DiscoveryCacheOptions, TelemetryConfig, AuthClient } from '@auth0/auth0-auth-js';
|
|
2
|
+
export { DiscoveryCacheOptions, TelemetryConfig } from '@auth0/auth0-auth-js';
|
|
2
3
|
import { JWTPayload } from 'jose';
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Resolves the Auth0 custom domain at runtime using request-specific context.
|
|
7
|
+
*
|
|
8
|
+
* Should return a custom domain hostname (for example,
|
|
9
|
+
* `brand-1.custom-domain.com`) without protocol.
|
|
10
|
+
*
|
|
11
|
+
* The resolver receives a context object from SDK method calls (typically
|
|
12
|
+
* the same `storeOptions` object passed by the application).
|
|
13
|
+
* Resolved custom domains must be trusted and must belong to the same Auth0 tenant.
|
|
14
|
+
* Do not derive the returned domain directly from untrusted request input.
|
|
15
|
+
*
|
|
16
|
+
* The resolver must return a non-empty domain string. If it returns `null`,
|
|
17
|
+
* `undefined`, or an empty string at runtime, the SDK throws
|
|
18
|
+
* `InvalidConfigurationError`.
|
|
19
|
+
*/
|
|
20
|
+
type DomainResolver<TStoreOptions> = (context?: TStoreOptions) => Promise<string> | string;
|
|
21
|
+
|
|
4
22
|
interface ServerClientOptions<TStoreOptions = unknown> {
|
|
5
|
-
domain: string
|
|
23
|
+
domain: string | DomainResolver<TStoreOptions>;
|
|
6
24
|
clientId: string;
|
|
7
25
|
clientSecret?: string;
|
|
8
26
|
clientAssertionSigningKey?: string | CryptoKey;
|
|
9
27
|
clientAssertionSigningAlg?: string;
|
|
10
28
|
authorizationParams?: AuthorizationParameters;
|
|
29
|
+
discoveryCache?: DiscoveryCacheOptions;
|
|
11
30
|
transactionIdentifier?: string;
|
|
12
31
|
stateIdentifier?: string;
|
|
13
32
|
/**
|
|
@@ -22,6 +41,11 @@ interface ServerClientOptions<TStoreOptions = unknown> {
|
|
|
22
41
|
* When set to `true`, using a `customFetch` is required.
|
|
23
42
|
*/
|
|
24
43
|
useMtls?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Optional telemetry configuration.
|
|
46
|
+
* Telemetry is enabled by default and sends the Auth0-Client header with package name and version.
|
|
47
|
+
*/
|
|
48
|
+
telemetry?: TelemetryConfig;
|
|
25
49
|
}
|
|
26
50
|
interface UserClaims {
|
|
27
51
|
sub: string;
|
|
@@ -67,11 +91,13 @@ interface SessionData {
|
|
|
67
91
|
refreshToken: string | undefined;
|
|
68
92
|
tokenSets: TokenSet[];
|
|
69
93
|
connectionTokenSets?: ConnectionTokenSet[];
|
|
94
|
+
domain?: string;
|
|
70
95
|
[key: string]: unknown;
|
|
71
96
|
}
|
|
72
97
|
interface TransactionData {
|
|
73
98
|
audience?: string;
|
|
74
99
|
codeVerifier: string;
|
|
100
|
+
domain?: string;
|
|
75
101
|
[key: string]: unknown;
|
|
76
102
|
}
|
|
77
103
|
interface AbstractDataStore<TData, TStoreOptions = unknown> {
|
|
@@ -79,9 +105,16 @@ interface AbstractDataStore<TData, TStoreOptions = unknown> {
|
|
|
79
105
|
get(identifier: string, options?: TStoreOptions): Promise<TData | undefined>;
|
|
80
106
|
delete(identifier: string, options?: TStoreOptions): Promise<void>;
|
|
81
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Claims used to identify sessions for Backchannel Logout.
|
|
110
|
+
*
|
|
111
|
+
* `iss` is optional for backward compatibility, but is included by resolver-mode
|
|
112
|
+
* implementations to disambiguate sessions across multiple issuers/domains.
|
|
113
|
+
*/
|
|
82
114
|
type LogoutTokenClaims = {
|
|
83
115
|
sub?: string;
|
|
84
116
|
sid?: string;
|
|
117
|
+
iss?: string;
|
|
85
118
|
};
|
|
86
119
|
interface StateStore<TStoreOptions = unknown> extends AbstractDataStore<StateData, TStoreOptions> {
|
|
87
120
|
deleteByLogoutToken(claims: LogoutTokenClaims, options?: TStoreOptions): Promise<void>;
|
|
@@ -89,7 +122,11 @@ interface StateStore<TStoreOptions = unknown> extends AbstractDataStore<StateDat
|
|
|
89
122
|
interface TransactionStore<TStoreOptions = unknown> extends AbstractDataStore<TransactionData, TStoreOptions> {
|
|
90
123
|
}
|
|
91
124
|
interface EncryptedStoreOptions {
|
|
92
|
-
|
|
125
|
+
/**
|
|
126
|
+
* The secret(s) to use for encryption and decryption. Can be a single string or an array of strings for secret rotation support.
|
|
127
|
+
* When using an array of secrets, the first one is used for encryption, while all secrets are tried, in-order, for decryption.
|
|
128
|
+
*/
|
|
129
|
+
secret: string | string[];
|
|
93
130
|
}
|
|
94
131
|
interface StartInteractiveLoginOptions<TAppState = unknown> {
|
|
95
132
|
pushedAuthorizationRequests?: boolean;
|
|
@@ -110,6 +147,25 @@ interface AccessTokenForConnectionOptions {
|
|
|
110
147
|
connection: string;
|
|
111
148
|
loginHint?: string;
|
|
112
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Options for retrieving an access token with MRRT support.
|
|
152
|
+
* Allows requesting tokens for specific audiences and scopes at runtime.
|
|
153
|
+
*/
|
|
154
|
+
interface GetAccessTokenOptions {
|
|
155
|
+
/**
|
|
156
|
+
* Optional audience for the requested access token.
|
|
157
|
+
* If not provided, falls back to configuration audience or 'default'.
|
|
158
|
+
* @example 'https://api.example.com'
|
|
159
|
+
*/
|
|
160
|
+
audience?: string;
|
|
161
|
+
/**
|
|
162
|
+
* Optional scope for the requested access token.
|
|
163
|
+
* If not provided, falls back to configuration scope.
|
|
164
|
+
* Space-separated scope string.
|
|
165
|
+
* @example 'read:data write:data'
|
|
166
|
+
*/
|
|
167
|
+
scope?: string;
|
|
168
|
+
}
|
|
113
169
|
interface LogoutOptions {
|
|
114
170
|
returnTo: string;
|
|
115
171
|
}
|
|
@@ -173,7 +229,7 @@ interface SessionCookieOptions {
|
|
|
173
229
|
*
|
|
174
230
|
* Default: `lax`.
|
|
175
231
|
*/
|
|
176
|
-
sameSite?:
|
|
232
|
+
sameSite?: 'strict' | 'lax' | 'none';
|
|
177
233
|
/**
|
|
178
234
|
* The secure attribute of the session cookie.
|
|
179
235
|
*
|
|
@@ -202,9 +258,13 @@ declare class ServerClient<TStoreOptions = unknown> {
|
|
|
202
258
|
* The underlying `authClient` instance that can be used to interact with the Auth0 Authentication API.
|
|
203
259
|
* Generally, you should prefer to use the higher-level methods exposed on the `ServerClient` instance.
|
|
204
260
|
*
|
|
261
|
+
* This property can only be used when `domain` is configured as a static string.
|
|
262
|
+
* In resolver mode (`domain` as a function), the SDK resolves the domain per request,
|
|
263
|
+
* so use `ServerClient` methods instead.
|
|
264
|
+
*
|
|
205
265
|
* Important: the methods exposed on the `authClient` instance do not handle any session or state management.
|
|
206
266
|
*/
|
|
207
|
-
|
|
267
|
+
get authClient(): AuthClient;
|
|
208
268
|
constructor(options: ServerClientOptions<TStoreOptions>);
|
|
209
269
|
/**
|
|
210
270
|
* Starts the interactive login process, and returns a URL to redirect the user-agent to to request authorization at Auth0.
|
|
@@ -303,7 +363,7 @@ declare class ServerClient<TStoreOptions = unknown> {
|
|
|
303
363
|
/**
|
|
304
364
|
* Retrieve the user session from the store, or undefined if no session found.
|
|
305
365
|
* @param storeOptions Optional options used to pass to the Transaction and State Store.
|
|
306
|
-
* @returns The
|
|
366
|
+
* @returns The session or undefined if no session found in the store.
|
|
307
367
|
*/
|
|
308
368
|
getSession(storeOptions?: TStoreOptions): Promise<SessionData | undefined>;
|
|
309
369
|
/**
|
|
@@ -360,7 +420,7 @@ declare abstract class AbstractStore<TData extends JWTPayload, TStoreOptions = u
|
|
|
360
420
|
abstract get(identifier: string, options?: TStoreOptions | undefined): Promise<TData | undefined>;
|
|
361
421
|
abstract delete(identifier: string, options?: TStoreOptions | undefined): Promise<void>;
|
|
362
422
|
protected encrypt<TData extends JWTPayload>(identifier: string, stateData: TData, expiration: number): Promise<string>;
|
|
363
|
-
protected decrypt<TData>(identifier: string, encryptedStateData: string): Promise<TData>;
|
|
423
|
+
protected decrypt<TData>(identifier: string, encryptedStateData: string): Promise<TData | undefined>;
|
|
364
424
|
}
|
|
365
425
|
|
|
366
426
|
/**
|
|
@@ -386,6 +446,13 @@ interface CookieSerializeOptions {
|
|
|
386
446
|
domain?: string;
|
|
387
447
|
expires?: Date;
|
|
388
448
|
httpOnly?: boolean;
|
|
449
|
+
/**
|
|
450
|
+
* MaxAge value of the cookie in seconds.
|
|
451
|
+
*
|
|
452
|
+
* Note for implementors of {@link CookieHandler}: this value is always in seconds.
|
|
453
|
+
* Some frameworks (e.g. Express) expect `maxAge` in milliseconds, so you may need to convert
|
|
454
|
+
* before passing it to the underlying framework (e.g. `maxAge * 1000`).
|
|
455
|
+
*/
|
|
389
456
|
maxAge?: number;
|
|
390
457
|
path?: string;
|
|
391
458
|
secure?: boolean;
|
|
@@ -503,5 +570,19 @@ declare class MissingSessionError extends Error {
|
|
|
503
570
|
code: string;
|
|
504
571
|
constructor(message: string);
|
|
505
572
|
}
|
|
573
|
+
/**
|
|
574
|
+
* Error thrown when a configuration is invalid.
|
|
575
|
+
*/
|
|
576
|
+
declare class InvalidConfigurationError extends Error {
|
|
577
|
+
code: string;
|
|
578
|
+
constructor(message: string);
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Error thrown when the issuer validation fails.
|
|
582
|
+
*/
|
|
583
|
+
declare class IssuerValidationError extends Error {
|
|
584
|
+
code: string;
|
|
585
|
+
constructor(message: string);
|
|
586
|
+
}
|
|
506
587
|
|
|
507
|
-
export { type AbstractDataStore, AbstractStateStore, AbstractTransactionStore, type AccessTokenForConnectionOptions, type AuthorizationParameters, BackchannelLogoutError, type ConnectionTokenSet, type CookieHandler, type CookieSerializeOptions, CookieTransactionStore, type EncryptedStoreOptions, type InternalStateData, type LoginBackchannelOptions, type LoginBackchannelResult, type LogoutOptions, type LogoutTokenClaims, MissingRequiredArgumentError, MissingSessionError, MissingTransactionError, ServerClient, type ServerClientOptions, type SessionConfiguration, type SessionCookieOptions, type SessionData, type SessionStore, type StartInteractiveLoginOptions, StartLinkUserError, type StartLinkUserOptions, type StartUnlinkUserOptions, type StateData, type StateStore, StatefulStateStore, type StatefulStateStoreOptions, StatelessStateStore, type TokenSet, type TransactionData, type TransactionStore, type UserClaims };
|
|
588
|
+
export { type AbstractDataStore, AbstractStateStore, AbstractTransactionStore, type AccessTokenForConnectionOptions, type AuthorizationParameters, BackchannelLogoutError, type ConnectionTokenSet, type CookieHandler, type CookieSerializeOptions, CookieTransactionStore, type DomainResolver, type EncryptedStoreOptions, type GetAccessTokenOptions, type InternalStateData, InvalidConfigurationError, IssuerValidationError, type LoginBackchannelOptions, type LoginBackchannelResult, type LogoutOptions, type LogoutTokenClaims, MissingRequiredArgumentError, MissingSessionError, MissingTransactionError, ServerClient, type ServerClientOptions, type SessionConfiguration, type SessionCookieOptions, type SessionData, type SessionStore, type StartInteractiveLoginOptions, StartLinkUserError, type StartLinkUserOptions, type StartUnlinkUserOptions, type StateData, type StateStore, StatefulStateStore, type StatefulStateStoreOptions, StatelessStateStore, type TokenSet, type TransactionData, type TransactionStore, type UserClaims };
|