@auth0/auth0-express 1.0.0-beta.1 → 1.0.0-beta.3
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 +26 -2
- package/dist/app-base-url.d.ts +31 -0
- package/dist/app-base-url.d.ts.map +1 -0
- package/dist/app-base-url.js +106 -0
- package/dist/app-base-url.js.map +1 -0
- package/dist/config.d.ts +15 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +106 -0
- package/dist/config.js.map +1 -0
- package/dist/errors/index.d.ts +6 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +9 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/handlers/backchannel-logout-handler.d.ts +3 -0
- package/dist/handlers/backchannel-logout-handler.d.ts.map +1 -0
- package/dist/handlers/backchannel-logout-handler.js +15 -0
- package/dist/handlers/backchannel-logout-handler.js.map +1 -0
- package/dist/handlers/callback-handler.d.ts +4 -0
- package/dist/handlers/callback-handler.d.ts.map +1 -0
- package/dist/handlers/callback-handler.js +30 -0
- package/dist/handlers/callback-handler.js.map +1 -0
- package/dist/handlers/login-handler.d.ts +4 -0
- package/dist/handlers/login-handler.d.ts.map +1 -0
- package/dist/handlers/login-handler.js +83 -0
- package/dist/handlers/login-handler.js.map +1 -0
- package/dist/handlers/logout-handler.d.ts +4 -0
- package/dist/handlers/logout-handler.d.ts.map +1 -0
- package/dist/handlers/logout-handler.js +22 -0
- package/dist/handlers/logout-handler.js.map +1 -0
- package/dist/handlers/start-enterprise-login.d.ts +21 -0
- package/dist/handlers/start-enterprise-login.d.ts.map +1 -0
- package/dist/handlers/start-enterprise-login.js +26 -0
- package/dist/handlers/start-enterprise-login.js.map +1 -0
- package/dist/index.d.ts +14 -343
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -521
- package/dist/index.js.map +1 -1
- package/dist/middleware/claim-auth.d.ts +28 -0
- package/dist/middleware/claim-auth.d.ts.map +1 -0
- package/dist/middleware/claim-auth.js +2 -0
- package/dist/middleware/claim-auth.js.map +1 -0
- package/dist/middleware/claim-check.d.ts +41 -0
- package/dist/middleware/claim-check.d.ts.map +1 -0
- package/dist/middleware/claim-check.js +62 -0
- package/dist/middleware/claim-check.js.map +1 -0
- package/dist/middleware/claim-equals.d.ts +27 -0
- package/dist/middleware/claim-equals.d.ts.map +1 -0
- package/dist/middleware/claim-equals.js +48 -0
- package/dist/middleware/claim-equals.js.map +1 -0
- package/dist/middleware/claim-includes.d.ts +37 -0
- package/dist/middleware/claim-includes.d.ts.map +1 -0
- package/dist/middleware/claim-includes.js +68 -0
- package/dist/middleware/claim-includes.js.map +1 -0
- package/dist/middleware/require-auth.d.ts +48 -0
- package/dist/middleware/require-auth.d.ts.map +1 -0
- package/dist/middleware/require-auth.js +61 -0
- package/dist/middleware/require-auth.js.map +1 -0
- package/dist/migration/index.d.ts +5 -0
- package/dist/migration/index.d.ts.map +1 -0
- package/dist/migration/index.js +3 -0
- package/dist/migration/index.js.map +1 -0
- package/dist/router.d.ts +34 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +76 -0
- package/dist/router.js.map +1 -0
- package/dist/store/express-cookie-handler.d.ts +17 -0
- package/dist/store/express-cookie-handler.d.ts.map +1 -0
- package/dist/store/express-cookie-handler.js +30 -0
- package/dist/store/express-cookie-handler.js.map +1 -0
- package/dist/store/express-oidc-hkdf.d.ts +2 -0
- package/dist/store/express-oidc-hkdf.d.ts.map +1 -0
- package/dist/store/express-oidc-hkdf.js +11 -0
- package/dist/store/express-oidc-hkdf.js.map +1 -0
- package/dist/store/legacy-compatible-stateful-state-store.d.ts +139 -0
- package/dist/store/legacy-compatible-stateful-state-store.d.ts.map +1 -0
- package/dist/store/legacy-compatible-stateful-state-store.js +234 -0
- package/dist/store/legacy-compatible-stateful-state-store.js.map +1 -0
- package/dist/store/legacy-compatible-stateless-state-store.d.ts +82 -0
- package/dist/store/legacy-compatible-stateless-state-store.d.ts.map +1 -0
- package/dist/store/legacy-compatible-stateless-state-store.js +135 -0
- package/dist/store/legacy-compatible-stateless-state-store.js.map +1 -0
- package/dist/store/legacy-session-transformer.d.ts +67 -0
- package/dist/store/legacy-session-transformer.d.ts.map +1 -0
- package/dist/store/legacy-session-transformer.js +118 -0
- package/dist/store/legacy-session-transformer.js.map +1 -0
- package/dist/store/request-context.d.ts +36 -0
- package/dist/store/request-context.d.ts.map +1 -0
- package/dist/store/request-context.js +49 -0
- package/dist/store/request-context.js.map +1 -0
- package/dist/types/express.d.ts +13 -0
- package/dist/types/express.d.ts.map +1 -0
- package/dist/types/express.js +2 -0
- package/dist/types/express.js.map +1 -0
- package/dist/types.d.ts +190 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +35 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +186 -0
- package/dist/utils.js.map +1 -0
- package/package.json +22 -14
- package/dist/index.cjs +0 -566
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -343
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { UserClaims, StateData } from '@auth0/auth0-server-js';
|
|
2
|
+
/**
|
|
3
|
+
* Legacy session format from express-openid-connect
|
|
4
|
+
*/
|
|
5
|
+
export interface ExpressOpenidConnectSession {
|
|
6
|
+
id_token?: string;
|
|
7
|
+
access_token?: string;
|
|
8
|
+
refresh_token?: string;
|
|
9
|
+
token_type?: string;
|
|
10
|
+
expires_at?: number | string;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Session store payload structure from express-openid-connect
|
|
15
|
+
*/
|
|
16
|
+
export interface ExpressOpenidConnectStorePayload {
|
|
17
|
+
header: {
|
|
18
|
+
iat: number;
|
|
19
|
+
uat: number;
|
|
20
|
+
exp: number;
|
|
21
|
+
};
|
|
22
|
+
data: ExpressOpenidConnectSession;
|
|
23
|
+
cookie: {
|
|
24
|
+
expires: number;
|
|
25
|
+
maxAge: number;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Shared utility for transforming legacy express-openid-connect sessions to auth0-server-js StateData format.
|
|
30
|
+
*/
|
|
31
|
+
export declare class LegacySessionTransformer {
|
|
32
|
+
#private;
|
|
33
|
+
constructor(audience: string, scope: string);
|
|
34
|
+
/**
|
|
35
|
+
* Transforms express-openid-connect session format to auth0-server-js StateData format
|
|
36
|
+
*/
|
|
37
|
+
transformLegacySession(legacy: ExpressOpenidConnectSession): StateData;
|
|
38
|
+
/**
|
|
39
|
+
* Decodes a JWT token without verification to extract claims.
|
|
40
|
+
* This is safe for transformations since the token was already encrypted
|
|
41
|
+
* in the session and will be re-encrypted.
|
|
42
|
+
*/
|
|
43
|
+
decodeJWT(token: string): UserClaims | undefined;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Emits a one-time startup warning when a migration store is constructed without an explicit
|
|
47
|
+
* `sessionConfiguration.absoluteDuration`. A migrated session keeps its original
|
|
48
|
+
* express-openid-connect creation time, and this SDK expires a session at
|
|
49
|
+
* `createdAt + absoluteDuration`. This SDK defaults `absoluteDuration` to 3 days while
|
|
50
|
+
* express-openid-connect defaults it to 7 — so relying on the default *can* cut short a
|
|
51
|
+
* carried-over session already older than 3 days. Warning once at construction (rather than per
|
|
52
|
+
* read) surfaces the potential misconfiguration before any user is affected, without log spam or
|
|
53
|
+
* per-session bookkeeping.
|
|
54
|
+
*
|
|
55
|
+
* This is a heuristic for the most common mistake ("forgot to raise it"), not a precise check: it
|
|
56
|
+
* only knows whether the value was *set*, not whether it is large enough for the sessions being
|
|
57
|
+
* migrated. It cannot see the old deployment's `absoluteDuration`, so it may warn when the old
|
|
58
|
+
* value was actually lower (the default is then fine), and it stays silent when an explicit value
|
|
59
|
+
* is still too low. It only fires when the value is left unset — an app that chose a value made a
|
|
60
|
+
* deliberate decision and is not warned.
|
|
61
|
+
*
|
|
62
|
+
* @param sessionConfiguration The store's session configuration, if any.
|
|
63
|
+
*/
|
|
64
|
+
export declare function warnIfAbsoluteDurationUnset(sessionConfiguration?: {
|
|
65
|
+
absoluteDuration?: number;
|
|
66
|
+
}): void;
|
|
67
|
+
//# sourceMappingURL=legacy-session-transformer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy-session-transformer.d.ts","sourceRoot":"","sources":["../../src/store/legacy-session-transformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAC/C,MAAM,EAAE;QACN,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IACF,IAAI,EAAE,2BAA2B,CAAC;IAClC,MAAM,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED;;GAEG;AACH,qBAAa,wBAAwB;;gBAIvB,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAK3C;;OAEG;IACH,sBAAsB,CAAC,MAAM,EAAE,2BAA2B,GAAG,SAAS;IA2DtE;;;;OAIG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;CAejD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,2BAA2B,CAAC,oBAAoB,CAAC,EAAE;IAAE,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAatG"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utility for transforming legacy express-openid-connect sessions to auth0-server-js StateData format.
|
|
3
|
+
*/
|
|
4
|
+
export class LegacySessionTransformer {
|
|
5
|
+
#legacyAudience;
|
|
6
|
+
#legacyScope;
|
|
7
|
+
constructor(audience, scope) {
|
|
8
|
+
this.#legacyAudience = audience;
|
|
9
|
+
this.#legacyScope = scope;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Transforms express-openid-connect session format to auth0-server-js StateData format
|
|
13
|
+
*/
|
|
14
|
+
transformLegacySession(legacy) {
|
|
15
|
+
// Parse user claims from ID token
|
|
16
|
+
const user = legacy.id_token ? this.decodeJWT(legacy.id_token) : undefined;
|
|
17
|
+
// Convert expires_at to number if it's a string. A non-numeric string parses to NaN;
|
|
18
|
+
// fall back to 0 so a malformed value is treated as already-expired, not persisted as NaN.
|
|
19
|
+
const parsedExpiresAt = typeof legacy.expires_at === 'string' ? parseInt(legacy.expires_at, 10) : legacy.expires_at ?? 0;
|
|
20
|
+
const expiresAt = Number.isNaN(parsedExpiresAt) ? 0 : parsedExpiresAt;
|
|
21
|
+
// Build the transformed session data
|
|
22
|
+
const transformed = {
|
|
23
|
+
user,
|
|
24
|
+
idToken: legacy.id_token,
|
|
25
|
+
refreshToken: legacy.refresh_token,
|
|
26
|
+
tokenSets: legacy.access_token
|
|
27
|
+
? [
|
|
28
|
+
{
|
|
29
|
+
audience: this.#legacyAudience,
|
|
30
|
+
scope: this.#legacyScope,
|
|
31
|
+
accessToken: legacy.access_token,
|
|
32
|
+
expiresAt,
|
|
33
|
+
},
|
|
34
|
+
]
|
|
35
|
+
: [],
|
|
36
|
+
internal: {
|
|
37
|
+
// Prefer the session-level sid, fall back to the ID token's sid claim, and finally to ''
|
|
38
|
+
// when neither is present. A session with an empty sid cannot be targeted by backchannel
|
|
39
|
+
// logout (which resolves sessions by sid), so stores that index by sid should skip indexing
|
|
40
|
+
// an empty value rather than collapsing every sid-less session onto one shared key.
|
|
41
|
+
sid: legacy.sid ?? user?.sid ?? '',
|
|
42
|
+
createdAt: Math.floor(Date.now() / 1000),
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
// Preserve any additional custom properties, excluding the transformed ones
|
|
46
|
+
const excludedKeys = new Set([
|
|
47
|
+
'id_token',
|
|
48
|
+
'access_token',
|
|
49
|
+
'refresh_token',
|
|
50
|
+
'token_type',
|
|
51
|
+
'expires_at',
|
|
52
|
+
'sid',
|
|
53
|
+
'user',
|
|
54
|
+
'idToken',
|
|
55
|
+
'refreshToken',
|
|
56
|
+
'tokenSets',
|
|
57
|
+
'internal',
|
|
58
|
+
]);
|
|
59
|
+
for (const [key, value] of Object.entries(legacy)) {
|
|
60
|
+
if (!excludedKeys.has(key)) {
|
|
61
|
+
transformed[key] = value;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return transformed;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Decodes a JWT token without verification to extract claims.
|
|
68
|
+
* This is safe for transformations since the token was already encrypted
|
|
69
|
+
* in the session and will be re-encrypted.
|
|
70
|
+
*/
|
|
71
|
+
decodeJWT(token) {
|
|
72
|
+
try {
|
|
73
|
+
const parts = token.split('.');
|
|
74
|
+
if (parts.length !== 3 || !parts[1]) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
const payload = parts[1];
|
|
78
|
+
// Handle URL-safe base64
|
|
79
|
+
const base64 = payload.replace(/-/g, '+').replace(/_/g, '/');
|
|
80
|
+
const jsonPayload = Buffer.from(base64, 'base64').toString('utf-8');
|
|
81
|
+
return JSON.parse(jsonPayload);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Emits a one-time startup warning when a migration store is constructed without an explicit
|
|
90
|
+
* `sessionConfiguration.absoluteDuration`. A migrated session keeps its original
|
|
91
|
+
* express-openid-connect creation time, and this SDK expires a session at
|
|
92
|
+
* `createdAt + absoluteDuration`. This SDK defaults `absoluteDuration` to 3 days while
|
|
93
|
+
* express-openid-connect defaults it to 7 — so relying on the default *can* cut short a
|
|
94
|
+
* carried-over session already older than 3 days. Warning once at construction (rather than per
|
|
95
|
+
* read) surfaces the potential misconfiguration before any user is affected, without log spam or
|
|
96
|
+
* per-session bookkeeping.
|
|
97
|
+
*
|
|
98
|
+
* This is a heuristic for the most common mistake ("forgot to raise it"), not a precise check: it
|
|
99
|
+
* only knows whether the value was *set*, not whether it is large enough for the sessions being
|
|
100
|
+
* migrated. It cannot see the old deployment's `absoluteDuration`, so it may warn when the old
|
|
101
|
+
* value was actually lower (the default is then fine), and it stays silent when an explicit value
|
|
102
|
+
* is still too low. It only fires when the value is left unset — an app that chose a value made a
|
|
103
|
+
* deliberate decision and is not warned.
|
|
104
|
+
*
|
|
105
|
+
* @param sessionConfiguration The store's session configuration, if any.
|
|
106
|
+
*/
|
|
107
|
+
export function warnIfAbsoluteDurationUnset(sessionConfiguration) {
|
|
108
|
+
if (sessionConfiguration?.absoluteDuration !== undefined) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
console.warn(`[auth0-express] Migration store created without sessionConfiguration.absoluteDuration. This ` +
|
|
112
|
+
`SDK defaults it to 3 days, but express-openid-connect defaults to 7 — so if your previous ` +
|
|
113
|
+
`deployment used a longer absoluteDuration, migrated sessions already older than 3 days may ` +
|
|
114
|
+
`be logged out on their first write. Set sessionConfiguration.absoluteDuration to at least ` +
|
|
115
|
+
`your express-openid-connect deployment's value (default 7 days / 604800) to keep in-flight ` +
|
|
116
|
+
`sessions alive across the migration.`);
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=legacy-session-transformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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IAAI,CAAC,KAAK,CAAC,WAAW,CAAe,CAAC;QAC/C,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,2BAA2B,CAAC,oBAAoD;IAC9F,IAAI,oBAAoB,EAAE,gBAAgB,KAAK,SAAS,EAAE,CAAC;QACzD,OAAO;IACT,CAAC;IAED,OAAO,CAAC,IAAI,CACV,8FAA8F;QAC5F,4FAA4F;QAC5F,6FAA6F;QAC7F,4FAA4F;QAC5F,6FAA6F;QAC7F,sCAAsC,CACzC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { StoreOptions } from 'src/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Context containing Express request and response objects.
|
|
4
|
+
* Available within the AsyncLocalStorage scope established by the auth0 middleware.
|
|
5
|
+
*/
|
|
6
|
+
export type RequestContext = StoreOptions;
|
|
7
|
+
/**
|
|
8
|
+
* Runs a callback within an AsyncLocalStorage context containing the request and response.
|
|
9
|
+
* This establishes the context for the entire request lifecycle.
|
|
10
|
+
*
|
|
11
|
+
* @param request - Express request object
|
|
12
|
+
* @param response - Express response object
|
|
13
|
+
* @param callback - Function to execute within the context
|
|
14
|
+
* @returns The result of the callback
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* app.use((req, res, next) => {
|
|
19
|
+
* runWithContext(req, res, () => next());
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function runWithContext<T>(context: RequestContext, callback: () => T): T;
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves the current request context from AsyncLocalStorage.
|
|
26
|
+
*
|
|
27
|
+
* @returns The current RequestContext
|
|
28
|
+
* @throws {Error} If called outside of a request context
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const { request, response } = getRequestContext();
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function getRequestContext(): RequestContext;
|
|
36
|
+
//# sourceMappingURL=request-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-context.d.ts","sourceRoot":"","sources":["../../src/store/request-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,YAAY,CAAC;AAQ1C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,OAAO,EAAE,cAAc,EACvB,QAAQ,EAAE,MAAM,CAAC,GAChB,CAAC,CAEH;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CAelD"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
/**
|
|
3
|
+
* AsyncLocalStorage instance for storing request context.
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
const asyncLocalStorage = new AsyncLocalStorage();
|
|
7
|
+
/**
|
|
8
|
+
* Runs a callback within an AsyncLocalStorage context containing the request and response.
|
|
9
|
+
* This establishes the context for the entire request lifecycle.
|
|
10
|
+
*
|
|
11
|
+
* @param request - Express request object
|
|
12
|
+
* @param response - Express response object
|
|
13
|
+
* @param callback - Function to execute within the context
|
|
14
|
+
* @returns The result of the callback
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* app.use((req, res, next) => {
|
|
19
|
+
* runWithContext(req, res, () => next());
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function runWithContext(context, callback) {
|
|
24
|
+
return asyncLocalStorage.run(context, callback);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Retrieves the current request context from AsyncLocalStorage.
|
|
28
|
+
*
|
|
29
|
+
* @returns The current RequestContext
|
|
30
|
+
* @throws {Error} If called outside of a request context
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const { request, response } = getRequestContext();
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export function getRequestContext() {
|
|
38
|
+
const context = asyncLocalStorage.getStore();
|
|
39
|
+
if (!context) {
|
|
40
|
+
throw new Error('Request context not available. This error typically occurs when:\n' +
|
|
41
|
+
'1. Client methods are called outside of a request handler\n' +
|
|
42
|
+
'2. The auth0 middleware has not been initialized\n' +
|
|
43
|
+
'3. AsyncLocalStorage context was lost in an async operation\n\n' +
|
|
44
|
+
'Ensure you are calling client methods within an Express request handler ' +
|
|
45
|
+
'and the auth0 middleware is properly configured.');
|
|
46
|
+
}
|
|
47
|
+
return context;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=request-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-context.js","sourceRoot":"","sources":["../../src/store/request-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AASrD;;;GAGG;AACH,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,EAAkB,CAAC;AAElE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,cAAc,CAC5B,OAAuB,EACvB,QAAiB;IAEjB,OAAO,iBAAiB,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,iBAAiB;IAC/B,MAAM,OAAO,GAAG,iBAAiB,CAAC,QAAQ,EAAE,CAAC;IAE7C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,oEAAoE;YAClE,6DAA6D;YAC7D,oDAAoD;YACpD,iEAAiE;YACjE,0EAA0E;YAC1E,kDAAkD,CACrD,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ServerClient } from '@auth0/auth0-server-js';
|
|
2
|
+
import type { StoreOptions } from '../types.js';
|
|
3
|
+
declare global {
|
|
4
|
+
namespace Express {
|
|
5
|
+
interface Request {
|
|
6
|
+
auth0: {
|
|
7
|
+
client: ServerClient<StoreOptions>;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=express.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/types/express.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf,KAAK,EAAE;gBACL,MAAM,EAAE,YAAY,CAAC,YAAY,CAAC,CAAC;aACpC,CAAC;SACH;KACF;CACF;AAED,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/types/express.ts"],"names":[],"mappings":""}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import type { DiscoveryCacheOptions, DomainResolver, SessionConfiguration, SessionStore, UserClaims } from '@auth0/auth0-server-js';
|
|
2
|
+
import type { Request, Response } from 'express';
|
|
3
|
+
export type { DomainResolver, DiscoveryCacheOptions, UserClaims } from '@auth0/auth0-server-js';
|
|
4
|
+
/**
|
|
5
|
+
* Hook called after the OAuth callback completes in Enterprise Connect mode.
|
|
6
|
+
* Auth0 writes no session cookie; the app must write its own here and call
|
|
7
|
+
* res.redirect() (or equivalent) before the promise resolves.
|
|
8
|
+
*
|
|
9
|
+
* Required when `enterpriseConnect: true`.
|
|
10
|
+
*/
|
|
11
|
+
export type EnterpriseConnectCallbackHook = (req: Request, res: Response, result: {
|
|
12
|
+
idTokenClaims?: Record<string, unknown>;
|
|
13
|
+
user?: UserClaims;
|
|
14
|
+
appState?: unknown;
|
|
15
|
+
}) => Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Options passed to custom session store implementations.
|
|
18
|
+
*
|
|
19
|
+
* These options provide access to the Express request and response objects,
|
|
20
|
+
* which are needed for cookie and session management operations.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* class CustomSessionStore implements SessionStore<StoreOptions> {
|
|
25
|
+
* async get(id: string, options: StoreOptions) {
|
|
26
|
+
* const { request, response } = options;
|
|
27
|
+
* // Access cookies, headers, etc.
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export interface StoreOptions {
|
|
33
|
+
/** Express request object */
|
|
34
|
+
request: Request;
|
|
35
|
+
/** Express response object */
|
|
36
|
+
response: Response;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Configuration options for Auth0 authentication in Express applications.
|
|
40
|
+
*
|
|
41
|
+
* Environment variable support:
|
|
42
|
+
* - AUTH0_DOMAIN or ISSUER_BASE_URL: Auth0 domain
|
|
43
|
+
* - AUTH0_CLIENT_ID or CLIENT_ID: Client ID
|
|
44
|
+
* - AUTH0_CLIENT_SECRET or CLIENT_SECRET: Client secret
|
|
45
|
+
* - APP_BASE_URL or BASE_URL: Application base URL
|
|
46
|
+
* - AUTH0_SESSION_SECRET or SECRET: Session encryption secret
|
|
47
|
+
* - AUTH0_AUDIENCE: Optional API audience
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const options: Auth0Options = {
|
|
52
|
+
* domain: 'tenant.auth0.com',
|
|
53
|
+
* clientId: 'your_client_id',
|
|
54
|
+
* clientSecret: 'your_client_secret',
|
|
55
|
+
* appBaseUrl: 'http://localhost:3000',
|
|
56
|
+
* sessionSecret: process.env.SESSION_SECRET
|
|
57
|
+
* };
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export interface Auth0Options {
|
|
61
|
+
/**
|
|
62
|
+
* Auth0 domain (e.g., 'tenant.auth0.com') without protocol.
|
|
63
|
+
*
|
|
64
|
+
* Provide a `DomainResolver` function to resolve the Auth0 custom domain
|
|
65
|
+
* per request (Multiple Custom Domains). The resolver receives the Express
|
|
66
|
+
* request context (`{ request, response }`) and returns the domain string.
|
|
67
|
+
*/
|
|
68
|
+
domain: string | DomainResolver<StoreOptions>;
|
|
69
|
+
/** Auth0 application client ID */
|
|
70
|
+
clientId: string;
|
|
71
|
+
/** Auth0 application client secret (required for token exchange) */
|
|
72
|
+
clientSecret?: string;
|
|
73
|
+
/** Private key for client assertion authentication (alternative to clientSecret) */
|
|
74
|
+
clientAssertionSigningKey?: string | CryptoKey;
|
|
75
|
+
/** Algorithm for client assertion signing (e.g., 'RS256') */
|
|
76
|
+
clientAssertionSigningAlg?: string;
|
|
77
|
+
/** API audience for requesting access tokens */
|
|
78
|
+
audience?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Base URL of your application (e.g., 'http://localhost:3000').
|
|
81
|
+
*
|
|
82
|
+
* - Provide a single URL string for a static base URL (default behavior).
|
|
83
|
+
* - Provide an array of allowed URLs to validate the incoming request origin
|
|
84
|
+
* against an allow-list (recommended for dynamic/preview deployments).
|
|
85
|
+
* - Omit it (or set `APP_BASE_URL`/`BASE_URL` empty) to infer the base URL
|
|
86
|
+
* from the incoming request host at runtime.
|
|
87
|
+
*/
|
|
88
|
+
appBaseUrl?: string | string[];
|
|
89
|
+
/** Enable Pushed Authorization Requests (PAR) for enhanced security */
|
|
90
|
+
pushedAuthorizationRequests?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Secret for encrypting session cookies (minimum 32 characters recommended).
|
|
93
|
+
*
|
|
94
|
+
* Provide an array to support secret rotation: the first secret is used to encrypt new
|
|
95
|
+
* cookies, while all secrets are tried, in order, when decrypting. This lets you roll the
|
|
96
|
+
* secret without logging existing users out — deploy `[newSecret, oldSecret]`, then drop
|
|
97
|
+
* the old secret once every session has been re-encrypted under the new one.
|
|
98
|
+
*
|
|
99
|
+
* Via environment variables, a comma-separated `AUTH0_SESSION_SECRET` (or `SECRET`) is
|
|
100
|
+
* parsed into an array in the same order.
|
|
101
|
+
*/
|
|
102
|
+
sessionSecret: string | string[];
|
|
103
|
+
/** Custom session store implementation (defaults to cookie-based sessions) */
|
|
104
|
+
sessionStore?: SessionStore<StoreOptions>;
|
|
105
|
+
/** Advanced session configuration (cookie settings, timeouts, etc.) */
|
|
106
|
+
sessionConfiguration?: SessionConfiguration;
|
|
107
|
+
/**
|
|
108
|
+
* Legacy compatibility options for migrating from express-openid-connect.
|
|
109
|
+
* When set, the SDK will automatically detect and decrypt sessions from
|
|
110
|
+
* express-openid-connect, allowing seamless migration without forcing users to re-authenticate.
|
|
111
|
+
*/
|
|
112
|
+
legacyCompatibility?: {
|
|
113
|
+
/**
|
|
114
|
+
* The secret(s) that were used by express-openid-connect for session encryption.
|
|
115
|
+
* Supports key rotation: provide an array to try multiple secrets in order.
|
|
116
|
+
* If not provided, uses the same secret as the current sessionSecret.
|
|
117
|
+
*/
|
|
118
|
+
legacySecret?: string | string[];
|
|
119
|
+
/**
|
|
120
|
+
* The audience to assign to access tokens migrated from express-openid-connect sessions.
|
|
121
|
+
*
|
|
122
|
+
* Token sets are looked up by audience, so this must equal the `audience` your app requests
|
|
123
|
+
* (e.g. via `getAccessToken`) or the migrated access token will not be found. The default
|
|
124
|
+
* `'default'` only matches callers that request no audience.
|
|
125
|
+
*
|
|
126
|
+
* @default 'default'
|
|
127
|
+
*/
|
|
128
|
+
legacyAudience?: string;
|
|
129
|
+
/**
|
|
130
|
+
* The scope to assign to access tokens migrated from express-openid-connect sessions.
|
|
131
|
+
* @default 'openid profile email offline_access'
|
|
132
|
+
*/
|
|
133
|
+
legacyScope?: string;
|
|
134
|
+
/**
|
|
135
|
+
* Mirror of express-openid-connect's `requireSignedSessionStoreCookie`. Only applies when a
|
|
136
|
+
* server-side `sessionStore` is configured (stateful sessions); ignored for cookie-based
|
|
137
|
+
* (stateless) sessions, whose payload is already encrypted and authenticated.
|
|
138
|
+
*
|
|
139
|
+
* When `true`, a legacy session-store cookie is only honored if it carries a valid JWS
|
|
140
|
+
* signature (verified against one of {@link legacySecret}); an unsigned cookie or one whose
|
|
141
|
+
* signature does not verify resolves to no session instead of being used verbatim as the
|
|
142
|
+
* store key. Set this when migrating a deployment that ran express-openid-connect with
|
|
143
|
+
* `requireSignedSessionStoreCookie: true`, so the signature remains the required integrity
|
|
144
|
+
* control over the store key.
|
|
145
|
+
*
|
|
146
|
+
* @default false
|
|
147
|
+
*/
|
|
148
|
+
requireSignedLegacyCookie?: boolean;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Whether to mount the default routes for login, logout, callback and backchannel logout.
|
|
152
|
+
* Routes: /auth/login, /auth/callback, /auth/logout, /auth/backchannel-logout
|
|
153
|
+
* @default true
|
|
154
|
+
*/
|
|
155
|
+
mountRoutes?: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Custom fetch implementation for HTTP requests.
|
|
158
|
+
* Useful for proxies, custom headers, or testing.
|
|
159
|
+
*/
|
|
160
|
+
customFetch?: typeof fetch;
|
|
161
|
+
/**
|
|
162
|
+
* Optional discovery cache configuration for OIDC metadata and JWKS.
|
|
163
|
+
* `ttl` is in seconds. Cache entries are scoped per resolved domain, which
|
|
164
|
+
* matters for MCD deployments serving many domains. Defaults to the
|
|
165
|
+
* `ServerClient` defaults (TTL 600s, max 100 entries) when omitted.
|
|
166
|
+
*/
|
|
167
|
+
discoveryCache?: DiscoveryCacheOptions;
|
|
168
|
+
/**
|
|
169
|
+
* Put the SDK in Enterprise Connect mode. Auth0 acts as a pure SSO relay;
|
|
170
|
+
* no Auth0 session is written. `onCallback` is required in this mode.
|
|
171
|
+
*/
|
|
172
|
+
enterpriseConnect?: boolean;
|
|
173
|
+
/**
|
|
174
|
+
* Required when `enterpriseConnect: true`. Called after code exchange with
|
|
175
|
+
* the ID token claims. Write your own session here and call res.redirect().
|
|
176
|
+
*/
|
|
177
|
+
onCallback?: EnterpriseConnectCallbackHook;
|
|
178
|
+
/** Custom paths for authentication routes (only used if mountRoutes is true) */
|
|
179
|
+
routes?: {
|
|
180
|
+
/** Login route path @default '/auth/login' */
|
|
181
|
+
login?: string;
|
|
182
|
+
/** OAuth callback route path @default '/auth/callback' */
|
|
183
|
+
callback?: string;
|
|
184
|
+
/** Logout route path @default '/auth/logout' */
|
|
185
|
+
logout?: string;
|
|
186
|
+
/** Backchannel logout route path @default '/auth/backchannel-logout' */
|
|
187
|
+
backchannelLogout?: string;
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,cAAc,EACd,oBAAoB,EACpB,YAAY,EACZ,UAAU,EACX,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEjD,YAAY,EAAE,cAAc,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEhG;;;;;;GAMG;AACH,MAAM,MAAM,6BAA6B,GAAG,CAC1C,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,MAAM,EAAE;IACN,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,QAAQ,CA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C,CAAC;IACF;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,KAAK,CAAC;IAE3B;;;;;OAKG;IACH,cAAc,CAAC,EAAE,qBAAqB,CAAC;IAEvC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B;;;OAGG;IACH,UAAU,CAAC,EAAE,6BAA6B,CAAC;IAE3C,gFAAgF;IAChF,MAAM,CAAC,EAAE;QACP,8CAA8C;QAC9C,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,0DAA0D;QAC1D,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,gDAAgD;QAChD,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,wEAAwE;QACxE,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC5B,CAAC;CACH"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ServerClient } from '@auth0/auth0-server-js';
|
|
2
|
+
import type { DomainResolver } from '@auth0/auth0-server-js';
|
|
3
|
+
import { Auth0Options, StoreOptions } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Wraps a user-provided domain resolver so it always receives the Express
|
|
6
|
+
* request context. `@auth0/auth0-server-js` invokes the resolver with the
|
|
7
|
+
* `storeOptions` passed to client methods; this SDK relies on
|
|
8
|
+
* `AsyncLocalStorage` instead of passing them explicitly, so when
|
|
9
|
+
* `storeOptions` is absent we recover it via `getRequestContext()` — the same
|
|
10
|
+
* fallback used by `ExpressCookieHandler`.
|
|
11
|
+
*
|
|
12
|
+
* A static string domain is returned unchanged.
|
|
13
|
+
*/
|
|
14
|
+
export declare function wrapDomainResolver(domain: Auth0Options['domain']): string | DomainResolver<StoreOptions>;
|
|
15
|
+
/**
|
|
16
|
+
* Utility function to ensure Route URLs are created correctly when using both the root and subpath as base URL.
|
|
17
|
+
* Accepts a relative path or an absolute same-origin URL, such as one forwarded by a reverse proxy.
|
|
18
|
+
* Validates that the constructed URL has the same origin as the base URL to prevent host override attacks.
|
|
19
|
+
* @param url Relative path (e.g. `/auth/callback`) or absolute same-origin URL.
|
|
20
|
+
* @param base The base URL to use, including any subpath.
|
|
21
|
+
* @returns A URL object, combining the base and url.
|
|
22
|
+
* @throws {Error} If the input contains multiple leading slashes/backslashes or the origin does not match the base URL.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createRouteUrl(url: string, base: string): URL;
|
|
25
|
+
/**
|
|
26
|
+
* Validates a user-supplied redirect URL (e.g. a `returnTo` query parameter) against the application base URL.
|
|
27
|
+
* Accepts relative paths and absolute same-origin URLs. Rejects different-origin URLs and injection attempts.
|
|
28
|
+
* Never throws — returns undefined for any invalid or unsafe input.
|
|
29
|
+
* @param dangerousRedirect Untrusted redirect URL from user input.
|
|
30
|
+
* @param safeBaseUrl The base URL to check against.
|
|
31
|
+
* @returns A safe redirect URL, or undefined if the input is not safe.
|
|
32
|
+
*/
|
|
33
|
+
export declare function toSafeRedirect(dangerousRedirect: string, safeBaseUrl: string): string | undefined;
|
|
34
|
+
export declare function createServerClientInstance(options: Auth0Options): ServerClient<StoreOptions>;
|
|
35
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,YAAY,EAA2C,MAAM,wBAAwB,CAAC;AACvH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAwCxD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,GAC7B,MAAM,GAAG,cAAc,CAAC,YAAY,CAAC,CAMvC;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,OAsCvD;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,iBAAiB,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CASjG;AA+DD,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,YAAY,8BA8B/D"}
|