@auth0/auth0-express 1.0.0-beta.1 → 1.0.0-beta.2

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.
Files changed (81) hide show
  1. package/README.md +25 -2
  2. package/dist/app-base-url.d.ts +31 -0
  3. package/dist/app-base-url.d.ts.map +1 -0
  4. package/dist/app-base-url.js +102 -0
  5. package/dist/app-base-url.js.map +1 -0
  6. package/dist/config.d.ts +15 -0
  7. package/dist/config.d.ts.map +1 -0
  8. package/dist/config.js +102 -0
  9. package/dist/config.js.map +1 -0
  10. package/dist/errors/index.d.ts +6 -0
  11. package/dist/errors/index.d.ts.map +1 -0
  12. package/dist/errors/index.js +9 -0
  13. package/dist/errors/index.js.map +1 -0
  14. package/dist/handlers/backchannel-logout-handler.d.ts +3 -0
  15. package/dist/handlers/backchannel-logout-handler.d.ts.map +1 -0
  16. package/dist/handlers/backchannel-logout-handler.js +15 -0
  17. package/dist/handlers/backchannel-logout-handler.js.map +1 -0
  18. package/dist/handlers/callback-handler.d.ts +4 -0
  19. package/dist/handlers/callback-handler.d.ts.map +1 -0
  20. package/dist/handlers/callback-handler.js +18 -0
  21. package/dist/handlers/callback-handler.js.map +1 -0
  22. package/dist/handlers/login-handler.d.ts +4 -0
  23. package/dist/handlers/login-handler.d.ts.map +1 -0
  24. package/dist/handlers/login-handler.js +64 -0
  25. package/dist/handlers/login-handler.js.map +1 -0
  26. package/dist/handlers/logout-handler.d.ts +4 -0
  27. package/dist/handlers/logout-handler.d.ts.map +1 -0
  28. package/dist/handlers/logout-handler.js +15 -0
  29. package/dist/handlers/logout-handler.js.map +1 -0
  30. package/dist/index.d.ts +11 -343
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +8 -521
  33. package/dist/index.js.map +1 -1
  34. package/dist/middleware/claim-auth.d.ts +28 -0
  35. package/dist/middleware/claim-auth.d.ts.map +1 -0
  36. package/dist/middleware/claim-auth.js +2 -0
  37. package/dist/middleware/claim-auth.js.map +1 -0
  38. package/dist/middleware/claim-check.d.ts +41 -0
  39. package/dist/middleware/claim-check.d.ts.map +1 -0
  40. package/dist/middleware/claim-check.js +62 -0
  41. package/dist/middleware/claim-check.js.map +1 -0
  42. package/dist/middleware/claim-equals.d.ts +27 -0
  43. package/dist/middleware/claim-equals.d.ts.map +1 -0
  44. package/dist/middleware/claim-equals.js +48 -0
  45. package/dist/middleware/claim-equals.js.map +1 -0
  46. package/dist/middleware/claim-includes.d.ts +37 -0
  47. package/dist/middleware/claim-includes.d.ts.map +1 -0
  48. package/dist/middleware/claim-includes.js +68 -0
  49. package/dist/middleware/claim-includes.js.map +1 -0
  50. package/dist/middleware/require-auth.d.ts +44 -0
  51. package/dist/middleware/require-auth.d.ts.map +1 -0
  52. package/dist/middleware/require-auth.js +57 -0
  53. package/dist/middleware/require-auth.js.map +1 -0
  54. package/dist/router.d.ts +34 -0
  55. package/dist/router.d.ts.map +1 -0
  56. package/dist/router.js +76 -0
  57. package/dist/router.js.map +1 -0
  58. package/dist/store/express-cookie-handler.d.ts +17 -0
  59. package/dist/store/express-cookie-handler.d.ts.map +1 -0
  60. package/dist/store/express-cookie-handler.js +30 -0
  61. package/dist/store/express-cookie-handler.js.map +1 -0
  62. package/dist/store/request-context.d.ts +36 -0
  63. package/dist/store/request-context.d.ts.map +1 -0
  64. package/dist/store/request-context.js +49 -0
  65. package/dist/store/request-context.js.map +1 -0
  66. package/dist/types/express.d.ts +13 -0
  67. package/dist/types/express.d.ts.map +1 -0
  68. package/dist/types/express.js +2 -0
  69. package/dist/types/express.js.map +1 -0
  70. package/dist/types.d.ts +125 -0
  71. package/dist/types.d.ts.map +1 -0
  72. package/dist/types.js +2 -0
  73. package/dist/types.js.map +1 -0
  74. package/dist/utils.d.ts +35 -0
  75. package/dist/utils.d.ts.map +1 -0
  76. package/dist/utils.js +146 -0
  77. package/dist/utils.js.map +1 -0
  78. package/package.json +9 -8
  79. package/dist/index.cjs +0 -566
  80. package/dist/index.cjs.map +0 -1
  81. package/dist/index.d.cts +0 -343
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claim-auth.js","sourceRoot":"","sources":["../../src/middleware/claim-auth.ts"],"names":[],"mappings":""}
@@ -0,0 +1,41 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ import { ClaimAuthOptions, ClaimCheckFunction } from './claim-auth.js';
3
+ /**
4
+ * Middleware to check claims using a custom validation function.
5
+ *
6
+ * Returns 403 Forbidden if the validation function returns false
7
+ * or user is not authenticated.
8
+ *
9
+ * @param checkFn - A function that receives the Express request and the user
10
+ * claims and returns true if authorized
11
+ * @param options - Optional configuration
12
+ * @returns Express middleware function
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * // Custom claim validation
17
+ * app.get('/premium', claimCheck((req, claims) => {
18
+ * return claims.subscription === 'premium' && !claims.subscription_expired;
19
+ * }), (req, res) => {
20
+ * res.send('Premium content');
21
+ * });
22
+ *
23
+ * // Complex authorization logic using the request
24
+ * app.delete('/posts/:id', claimCheck(async (req, claims) => {
25
+ * const post = await getPost(req.params.id);
26
+ * return claims.sub === post.authorId || claims.role === 'admin';
27
+ * }), (req, res) => {
28
+ * res.send('Post deleted');
29
+ * });
30
+ *
31
+ * // With custom error message
32
+ * app.get('/beta', claimCheck(
33
+ * (req, claims) => claims.beta_access === true,
34
+ * { errorMessage: 'Beta access required' }
35
+ * ), (req, res) => {
36
+ * res.send('Beta features');
37
+ * });
38
+ * ```
39
+ */
40
+ export declare function claimCheck(checkFn: ClaimCheckFunction, options?: ClaimAuthOptions): (req: Request, res: Response, next: NextFunction) => Promise<Response<any, Record<string, any>> | undefined>;
41
+ //# sourceMappingURL=claim-check.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claim-check.d.ts","sourceRoot":"","sources":["../../src/middleware/claim-check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,gBAAgB,IAClE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,6DAyB9D"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Middleware to check claims using a custom validation function.
3
+ *
4
+ * Returns 403 Forbidden if the validation function returns false
5
+ * or user is not authenticated.
6
+ *
7
+ * @param checkFn - A function that receives the Express request and the user
8
+ * claims and returns true if authorized
9
+ * @param options - Optional configuration
10
+ * @returns Express middleware function
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * // Custom claim validation
15
+ * app.get('/premium', claimCheck((req, claims) => {
16
+ * return claims.subscription === 'premium' && !claims.subscription_expired;
17
+ * }), (req, res) => {
18
+ * res.send('Premium content');
19
+ * });
20
+ *
21
+ * // Complex authorization logic using the request
22
+ * app.delete('/posts/:id', claimCheck(async (req, claims) => {
23
+ * const post = await getPost(req.params.id);
24
+ * return claims.sub === post.authorId || claims.role === 'admin';
25
+ * }), (req, res) => {
26
+ * res.send('Post deleted');
27
+ * });
28
+ *
29
+ * // With custom error message
30
+ * app.get('/beta', claimCheck(
31
+ * (req, claims) => claims.beta_access === true,
32
+ * { errorMessage: 'Beta access required' }
33
+ * ), (req, res) => {
34
+ * res.send('Beta features');
35
+ * });
36
+ * ```
37
+ */
38
+ export function claimCheck(checkFn, options) {
39
+ return async (req, res, next) => {
40
+ try {
41
+ const user = await req.auth0.client.getUser();
42
+ if (!user) {
43
+ return res.status(401).json({
44
+ error: 'unauthorized',
45
+ message: 'Authentication required',
46
+ });
47
+ }
48
+ const isAuthorized = await checkFn(req, user);
49
+ if (!isAuthorized) {
50
+ return res.status(options?.statusCode || 403).json({
51
+ error: 'forbidden',
52
+ message: options?.errorMessage || 'Access denied',
53
+ });
54
+ }
55
+ next();
56
+ }
57
+ catch (error) {
58
+ next(error);
59
+ }
60
+ };
61
+ }
62
+ //# sourceMappingURL=claim-check.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claim-check.js","sourceRoot":"","sources":["../../src/middleware/claim-check.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,UAAU,UAAU,CAAC,OAA2B,EAAE,OAA0B;IAChF,OAAO,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;QAC/D,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAE9C,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;oBAC1B,KAAK,EAAE,cAAc;oBACrB,OAAO,EAAE,yBAAyB;iBACnC,CAAC,CAAC;YACL,CAAC;YAED,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE,IAA+B,CAAC,CAAC;YAEzE,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,OAAO,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;oBACjD,KAAK,EAAE,WAAW;oBAClB,OAAO,EAAE,OAAO,EAAE,YAAY,IAAI,eAAe;iBAClD,CAAC,CAAC;YACL,CAAC;YAED,IAAI,EAAE,CAAC;QACT,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,KAAK,CAAC,CAAC;QACd,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ import { ClaimAuthOptions, JSONPrimitive } from './claim-auth.js';
3
+ /**
4
+ * Middleware to check if a claim equals a specific value.
5
+ *
6
+ * Returns 403 Forbidden if the claim doesn't match or user is not authenticated.
7
+ *
8
+ * @param claim - The name of the claim to check
9
+ * @param value - The expected value of the claim
10
+ * @param options - Optional configuration
11
+ * @returns Express middleware function
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * // Require user to be an admin
16
+ * app.get('/admin', claimEquals('role', 'admin'), (req, res) => {
17
+ * res.send('Admin dashboard');
18
+ * });
19
+ *
20
+ * // Check organization membership
21
+ * app.get('/org', claimEquals('org_id', 'org_123'), (req, res) => {
22
+ * res.send('Organization page');
23
+ * });
24
+ * ```
25
+ */
26
+ export declare function claimEquals(claim: string, value: JSONPrimitive, options?: ClaimAuthOptions): (req: Request, res: Response, next: NextFunction) => Promise<Response<any, Record<string, any>> | undefined>;
27
+ //# sourceMappingURL=claim-equals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claim-equals.d.ts","sourceRoot":"","sources":["../../src/middleware/claim-equals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAElE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,gBAAgB,IAC3E,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,6DAyB9D"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Middleware to check if a claim equals a specific value.
3
+ *
4
+ * Returns 403 Forbidden if the claim doesn't match or user is not authenticated.
5
+ *
6
+ * @param claim - The name of the claim to check
7
+ * @param value - The expected value of the claim
8
+ * @param options - Optional configuration
9
+ * @returns Express middleware function
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * // Require user to be an admin
14
+ * app.get('/admin', claimEquals('role', 'admin'), (req, res) => {
15
+ * res.send('Admin dashboard');
16
+ * });
17
+ *
18
+ * // Check organization membership
19
+ * app.get('/org', claimEquals('org_id', 'org_123'), (req, res) => {
20
+ * res.send('Organization page');
21
+ * });
22
+ * ```
23
+ */
24
+ export function claimEquals(claim, value, options) {
25
+ return async (req, res, next) => {
26
+ try {
27
+ const user = await req.auth0.client.getUser();
28
+ if (!user) {
29
+ return res.status(401).json({
30
+ error: 'unauthorized',
31
+ message: 'Authentication required',
32
+ });
33
+ }
34
+ const claimValue = user[claim];
35
+ if (claimValue !== value) {
36
+ return res.status(options?.statusCode || 403).json({
37
+ error: 'forbidden',
38
+ message: options?.errorMessage || `Access denied`,
39
+ });
40
+ }
41
+ next();
42
+ }
43
+ catch (error) {
44
+ next(error);
45
+ }
46
+ };
47
+ }
48
+ //# sourceMappingURL=claim-equals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claim-equals.js","sourceRoot":"","sources":["../../src/middleware/claim-equals.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,KAAoB,EAAE,OAA0B;IACzF,OAAO,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;QAC/D,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAE9C,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;oBAC1B,KAAK,EAAE,cAAc;oBACrB,OAAO,EAAE,yBAAyB;iBACnC,CAAC,CAAC;YACL,CAAC;YAED,MAAM,UAAU,GAAI,IAAgC,CAAC,KAAK,CAAC,CAAC;YAE5D,IAAI,UAAU,KAAK,KAAK,EAAE,CAAC;gBACzB,OAAO,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;oBACjD,KAAK,EAAE,WAAW;oBAClB,OAAO,EAAE,OAAO,EAAE,YAAY,IAAI,eAAe;iBAClD,CAAC,CAAC;YACL,CAAC;YAED,IAAI,EAAE,CAAC;QACT,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,KAAK,CAAC,CAAC;QACd,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ import { ClaimAuthOptions } from './claim-auth.js';
3
+ /**
4
+ * Middleware to check if a claim includes specific values.
5
+ *
6
+ * The claim may be an array, or a space-delimited string (such as a
7
+ * scope-style `"read:users delete:users"` claim), which is split on spaces
8
+ * before checking.
9
+ *
10
+ * Returns 403 Forbidden if the claim doesn't include all required values
11
+ * or user is not authenticated.
12
+ *
13
+ * @param claim - The name of the claim to check
14
+ * @param values - The values that must be present in the claim
15
+ * @param options - Optional configuration
16
+ * @returns Express middleware function
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // Require user to have specific permissions
21
+ * app.delete('/users/:id', claimIncludes('permissions', ['delete:users']), (req, res) => {
22
+ * res.send('User deleted');
23
+ * });
24
+ *
25
+ * // Require multiple permissions
26
+ * app.post('/admin/users', claimIncludes('permissions', ['create:users', 'admin:access']), (req, res) => {
27
+ * res.send('User created');
28
+ * });
29
+ *
30
+ * // Check roles
31
+ * app.get('/dashboard', claimIncludes('roles', ['editor', 'admin']), (req, res) => {
32
+ * res.send('Dashboard');
33
+ * });
34
+ * ```
35
+ */
36
+ export declare function claimIncludes(claim: string, values: unknown[], options?: ClaimAuthOptions): (req: Request, res: Response, next: NextFunction) => Promise<Response<any, Record<string, any>> | undefined>;
37
+ //# sourceMappingURL=claim-includes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claim-includes.d.ts","sourceRoot":"","sources":["../../src/middleware/claim-includes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,EAAE,gBAAgB,IAC1E,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,6DAuC9D"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Middleware to check if a claim includes specific values.
3
+ *
4
+ * The claim may be an array, or a space-delimited string (such as a
5
+ * scope-style `"read:users delete:users"` claim), which is split on spaces
6
+ * before checking.
7
+ *
8
+ * Returns 403 Forbidden if the claim doesn't include all required values
9
+ * or user is not authenticated.
10
+ *
11
+ * @param claim - The name of the claim to check
12
+ * @param values - The values that must be present in the claim
13
+ * @param options - Optional configuration
14
+ * @returns Express middleware function
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * // Require user to have specific permissions
19
+ * app.delete('/users/:id', claimIncludes('permissions', ['delete:users']), (req, res) => {
20
+ * res.send('User deleted');
21
+ * });
22
+ *
23
+ * // Require multiple permissions
24
+ * app.post('/admin/users', claimIncludes('permissions', ['create:users', 'admin:access']), (req, res) => {
25
+ * res.send('User created');
26
+ * });
27
+ *
28
+ * // Check roles
29
+ * app.get('/dashboard', claimIncludes('roles', ['editor', 'admin']), (req, res) => {
30
+ * res.send('Dashboard');
31
+ * });
32
+ * ```
33
+ */
34
+ export function claimIncludes(claim, values, options) {
35
+ return async (req, res, next) => {
36
+ try {
37
+ const user = await req.auth0.client.getUser();
38
+ if (!user) {
39
+ return res.status(401).json({
40
+ error: 'unauthorized',
41
+ message: 'Authentication required',
42
+ });
43
+ }
44
+ const rawClaim = user[claim];
45
+ // Accept both array claims and space-delimited string claims
46
+ // (e.g. scope-style `"read:users delete:users"`).
47
+ const claimValue = typeof rawClaim === 'string' ? rawClaim.split(' ') : rawClaim;
48
+ if (!Array.isArray(claimValue)) {
49
+ return res.status(options?.statusCode || 403).json({
50
+ error: 'forbidden',
51
+ message: options?.errorMessage || `Access denied`,
52
+ });
53
+ }
54
+ const hasAllValues = values.every((value) => claimValue.includes(value));
55
+ if (!hasAllValues) {
56
+ return res.status(options?.statusCode || 403).json({
57
+ error: 'forbidden',
58
+ message: options?.errorMessage || `Access denied`,
59
+ });
60
+ }
61
+ next();
62
+ }
63
+ catch (error) {
64
+ next(error);
65
+ }
66
+ };
67
+ }
68
+ //# sourceMappingURL=claim-includes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claim-includes.js","sourceRoot":"","sources":["../../src/middleware/claim-includes.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa,EAAE,MAAiB,EAAE,OAA0B;IACxF,OAAO,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;QAC/D,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAE9C,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;oBAC1B,KAAK,EAAE,cAAc;oBACrB,OAAO,EAAE,yBAAyB;iBACnC,CAAC,CAAC;YACL,CAAC;YAED,MAAM,QAAQ,GAAI,IAAgC,CAAC,KAAK,CAAC,CAAC;YAE1D,6DAA6D;YAC7D,kDAAkD;YAClD,MAAM,UAAU,GACd,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;YAEhE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC/B,OAAO,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;oBACjD,KAAK,EAAE,WAAW;oBAClB,OAAO,EAAE,OAAO,EAAE,YAAY,IAAI,eAAe;iBAClD,CAAC,CAAC;YACL,CAAC;YAED,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;YAEzE,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,OAAO,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;oBACjD,KAAK,EAAE,WAAW;oBAClB,OAAO,EAAE,OAAO,EAAE,YAAY,IAAI,eAAe;iBAClD,CAAC,CAAC;YACL,CAAC;YAED,IAAI,EAAE,CAAC;QACT,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,KAAK,CAAC,CAAC;QACd,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ /**
3
+ * Options for the requiresAuth middleware.
4
+ */
5
+ export interface RequiresAuthOptions {
6
+ /**
7
+ * If true, returns a 401 status instead of redirecting to login.
8
+ * Useful for API routes that should not redirect.
9
+ *
10
+ * Default: false (redirects to login)
11
+ */
12
+ returnTo?: string;
13
+ }
14
+ /**
15
+ * Middleware to require authentication for a route.
16
+ *
17
+ * If the user is not authenticated:
18
+ * - For HTML requests (browser): Redirects to /auth/login with returnTo parameter
19
+ * - For API requests (JSON): Returns 401 Unauthorized
20
+ *
21
+ * @param options - Optional configuration for the middleware
22
+ * @returns Express middleware function
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * // Protect a route
27
+ * app.get('/profile', requiresAuth(), (req, res) => {
28
+ * res.json({ user: await req.auth0.client.getUser() });
29
+ * });
30
+ *
31
+ * // Protect an API route (returns 401 instead of redirecting)
32
+ * app.get('/api/me', requiresAuth(), async (req, res) => {
33
+ * const user = await req.auth0.client.getUser();
34
+ * res.json({ user });
35
+ * });
36
+ *
37
+ * // Custom return URL after login
38
+ * app.get('/admin', requiresAuth({ returnTo: '/admin' }), (req, res) => {
39
+ * res.send('Admin page');
40
+ * });
41
+ * ```
42
+ */
43
+ export declare function requiresAuth(options?: RequiresAuthOptions): (req: Request, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
44
+ //# sourceMappingURL=require-auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"require-auth.d.ts","sourceRoot":"","sources":["../../src/middleware/require-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,mBAAmB,IAC1C,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,wDA4B9D"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Middleware to require authentication for a route.
3
+ *
4
+ * If the user is not authenticated:
5
+ * - For HTML requests (browser): Redirects to /auth/login with returnTo parameter
6
+ * - For API requests (JSON): Returns 401 Unauthorized
7
+ *
8
+ * @param options - Optional configuration for the middleware
9
+ * @returns Express middleware function
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * // Protect a route
14
+ * app.get('/profile', requiresAuth(), (req, res) => {
15
+ * res.json({ user: await req.auth0.client.getUser() });
16
+ * });
17
+ *
18
+ * // Protect an API route (returns 401 instead of redirecting)
19
+ * app.get('/api/me', requiresAuth(), async (req, res) => {
20
+ * const user = await req.auth0.client.getUser();
21
+ * res.json({ user });
22
+ * });
23
+ *
24
+ * // Custom return URL after login
25
+ * app.get('/admin', requiresAuth({ returnTo: '/admin' }), (req, res) => {
26
+ * res.send('Admin page');
27
+ * });
28
+ * ```
29
+ */
30
+ export function requiresAuth(options) {
31
+ return async (req, res, next) => {
32
+ try {
33
+ const user = await req.auth0.client.getUser();
34
+ if (!user) {
35
+ // Check if this is an API request (wants JSON response)
36
+ const acceptsJson = req.accepts('json') && !req.accepts('html');
37
+ if (acceptsJson) {
38
+ return res.status(401).json({
39
+ error: 'unauthorized',
40
+ message: 'Authentication required',
41
+ });
42
+ }
43
+ // For HTML requests, redirect to login with returnTo
44
+ const returnTo = options?.returnTo || req.originalUrl;
45
+ const loginPath = req.app.locals.auth0ClientOptions?.routes?.login || '/auth/login';
46
+ const loginUrl = `${loginPath}?returnTo=${encodeURIComponent(returnTo)}`;
47
+ return res.redirect(loginUrl);
48
+ }
49
+ // User is authenticated, continue
50
+ next();
51
+ }
52
+ catch (error) {
53
+ next(error);
54
+ }
55
+ };
56
+ }
57
+ //# sourceMappingURL=require-auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"require-auth.js","sourceRoot":"","sources":["../../src/middleware/require-auth.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,YAAY,CAAC,OAA6B;IACxD,OAAO,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;QAC/D,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAE9C,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,wDAAwD;gBACxD,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;gBAEhE,IAAI,WAAW,EAAE,CAAC;oBAChB,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;wBAC1B,KAAK,EAAE,cAAc;wBACrB,OAAO,EAAE,yBAAyB;qBACnC,CAAC,CAAC;gBACL,CAAC;gBAED,qDAAqD;gBACrD,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,GAAG,CAAC,WAAW,CAAC;gBACtD,MAAM,SAAS,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,kBAAkB,EAAE,MAAM,EAAE,KAAK,IAAI,aAAa,CAAC;gBACpF,MAAM,QAAQ,GAAG,GAAG,SAAS,aAAa,kBAAkB,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACzE,OAAO,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAChC,CAAC;YAED,kCAAkC;YAClC,IAAI,EAAE,CAAC;QACT,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,KAAK,CAAC,CAAC;QACd,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { Router } from 'express';
2
+ import type { Auth0Options } from './types.js';
3
+ import './types/express.js';
4
+ /**
5
+ * Creates an Express router with Auth0 authentication middleware.
6
+ *
7
+ * This is the main entry point for the Auth0 Express SDK. It configures
8
+ * authentication routes and attaches the Auth0 client to the request object.
9
+ *
10
+ * @param opts - Configuration options for Auth0 authentication
11
+ * @returns Express Router configured with Auth0 authentication
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import express from 'express';
16
+ * import { createAuth0 } from '@auth0/auth0-express';
17
+ *
18
+ * const app = express();
19
+ *
20
+ * // Using environment variables (AUTH0_DOMAIN, AUTH0_CLIENT_ID, etc.)
21
+ * app.use(createAuth0());
22
+ *
23
+ * // Or with explicit configuration
24
+ * app.use(createAuth0({
25
+ * domain: 'tenant.auth0.com',
26
+ * clientId: 'your_client_id',
27
+ * clientSecret: 'your_client_secret',
28
+ * appBaseUrl: 'http://localhost:3000',
29
+ * sessionSecret: process.env.SESSION_SECRET
30
+ * }));
31
+ * ```
32
+ */
33
+ export declare function createAuth0(opts?: Partial<Auth0Options>): Router;
34
+ //# sourceMappingURL=router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAmC,MAAM,SAAS,CAAC;AAElE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAQ/C,OAAO,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,WAAW,CAAC,IAAI,GAAE,OAAO,CAAC,YAAY,CAAM,GAAG,MAAM,CA2CpE"}
package/dist/router.js ADDED
@@ -0,0 +1,76 @@
1
+ import { Router } from 'express';
2
+ import cookieParser from 'cookie-parser';
3
+ import { createServerClientInstance } from './utils.js';
4
+ import { handleLogin } from './handlers/login-handler.js';
5
+ import { handleCallback } from './handlers/callback-handler.js';
6
+ import { handleLogout } from './handlers/logout-handler.js';
7
+ import { handleBackchannelLogout } from './handlers/backchannel-logout-handler.js';
8
+ import { runWithContext } from './store/request-context.js';
9
+ import { getConfig } from './config.js';
10
+ import './types/express.js';
11
+ /**
12
+ * Creates an Express router with Auth0 authentication middleware.
13
+ *
14
+ * This is the main entry point for the Auth0 Express SDK. It configures
15
+ * authentication routes and attaches the Auth0 client to the request object.
16
+ *
17
+ * @param opts - Configuration options for Auth0 authentication
18
+ * @returns Express Router configured with Auth0 authentication
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * import express from 'express';
23
+ * import { createAuth0 } from '@auth0/auth0-express';
24
+ *
25
+ * const app = express();
26
+ *
27
+ * // Using environment variables (AUTH0_DOMAIN, AUTH0_CLIENT_ID, etc.)
28
+ * app.use(createAuth0());
29
+ *
30
+ * // Or with explicit configuration
31
+ * app.use(createAuth0({
32
+ * domain: 'tenant.auth0.com',
33
+ * clientId: 'your_client_id',
34
+ * clientSecret: 'your_client_secret',
35
+ * appBaseUrl: 'http://localhost:3000',
36
+ * sessionSecret: process.env.SESSION_SECRET
37
+ * }));
38
+ * ```
39
+ */
40
+ export function createAuth0(opts = {}) {
41
+ const options = getConfig(opts);
42
+ const router = Router();
43
+ // Cookie parsing
44
+ router.use(cookieParser());
45
+ // Establish AsyncLocalStorage context for the request lifecycle
46
+ router.use((request, response, next) => {
47
+ runWithContext({ request, response }, () => next());
48
+ });
49
+ // Initialize auth0Client
50
+ const auth0Client = createServerClientInstance(options);
51
+ // Attach to request
52
+ router.use((req, res, next) => {
53
+ req.auth0 = { client: auth0Client };
54
+ req.app.locals.auth0Client = auth0Client;
55
+ req.app.locals.auth0ClientOptions = options;
56
+ req.app.locals.appBaseUrl = options.appBaseUrl;
57
+ req.app.locals.pushedAuthorizationRequests = options.pushedAuthorizationRequests;
58
+ next();
59
+ });
60
+ // Mount routes
61
+ const shouldMountRoutes = options.mountRoutes ?? true;
62
+ if (shouldMountRoutes) {
63
+ const routes = {
64
+ login: options.routes?.login ?? '/auth/login',
65
+ callback: options.routes?.callback ?? '/auth/callback',
66
+ logout: options.routes?.logout ?? '/auth/logout',
67
+ backchannelLogout: options.routes?.backchannelLogout ?? '/auth/backchannel-logout',
68
+ };
69
+ router.get(routes.login, (req, res) => handleLogin(req, res, options));
70
+ router.get(routes.callback, (req, res) => handleCallback(req, res, options));
71
+ router.get(routes.logout, (req, res) => handleLogout(req, res, options));
72
+ router.post(routes.backchannelLogout, (req, res) => handleBackchannelLogout(req, res));
73
+ }
74
+ return router;
75
+ }
76
+ //# sourceMappingURL=router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,17 @@
1
+ import { CookieHandler, CookieSerializeOptions } from '@auth0/auth0-server-js';
2
+ import { StoreOptions } from '../types.js';
3
+ /**
4
+ * Express-specific cookie handler that uses AsyncLocalStorage to automatically
5
+ * access the current request and response objects.
6
+ *
7
+ * This implementation supports both explicit storeOptions and AsyncLocalStorage context.
8
+ * When storeOptions are provided, they take precedence. Otherwise, it falls back to
9
+ * retrieving the request context from AsyncLocalStorage.
10
+ */
11
+ export declare class ExpressCookieHandler implements CookieHandler<StoreOptions> {
12
+ setCookie(name: string, value: string, options?: CookieSerializeOptions, storeOptions?: StoreOptions): void;
13
+ getCookie(name: string, storeOptions?: StoreOptions): string | undefined;
14
+ getCookies(storeOptions?: StoreOptions): Record<string, string>;
15
+ deleteCookie(name: string, storeOptions?: StoreOptions): void;
16
+ }
17
+ //# sourceMappingURL=express-cookie-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"express-cookie-handler.d.ts","sourceRoot":"","sources":["../../src/store/express-cookie-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C;;;;;;;GAOG;AACH,qBAAa,oBAAqB,YAAW,aAAa,CAAC,YAAY,CAAC;IACtE,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB,EAAE,YAAY,CAAC,EAAE,YAAY,GAAG,IAAI;IAS3G,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS;IAKxE,UAAU,CAAC,YAAY,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAK/D,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,YAAY,GAAG,IAAI;CAI9D"}
@@ -0,0 +1,30 @@
1
+ import { getRequestContext } from './request-context.js';
2
+ /**
3
+ * Express-specific cookie handler that uses AsyncLocalStorage to automatically
4
+ * access the current request and response objects.
5
+ *
6
+ * This implementation supports both explicit storeOptions and AsyncLocalStorage context.
7
+ * When storeOptions are provided, they take precedence. Otherwise, it falls back to
8
+ * retrieving the request context from AsyncLocalStorage.
9
+ */
10
+ export class ExpressCookieHandler {
11
+ setCookie(name, value, options, storeOptions) {
12
+ const { response } = storeOptions ?? getRequestContext();
13
+ // options.maxAge is in seconds, but Express expects milliseconds
14
+ const maxAge = options?.maxAge != null ? options.maxAge * 1000 : undefined;
15
+ response.cookie(name, value, { ...options, maxAge });
16
+ }
17
+ getCookie(name, storeOptions) {
18
+ const { request } = storeOptions ?? getRequestContext();
19
+ return request.cookies?.[name];
20
+ }
21
+ getCookies(storeOptions) {
22
+ const { request } = storeOptions ?? getRequestContext();
23
+ return request.cookies;
24
+ }
25
+ deleteCookie(name, storeOptions) {
26
+ const { response } = storeOptions ?? getRequestContext();
27
+ response.clearCookie(name);
28
+ }
29
+ }
30
+ //# sourceMappingURL=express-cookie-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"express-cookie-handler.js","sourceRoot":"","sources":["../../src/store/express-cookie-handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD;;;;;;;GAOG;AACH,MAAM,OAAO,oBAAoB;IAC/B,SAAS,CAAC,IAAY,EAAE,KAAa,EAAE,OAAgC,EAAE,YAA2B;QAClG,MAAM,EAAE,QAAQ,EAAE,GAAG,YAAY,IAAI,iBAAiB,EAAE,CAAC;QAEzD,iEAAiE;QACjE,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;QAE3E,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IACvD,CAAC;IAED,SAAS,CAAC,IAAY,EAAE,YAA2B;QACjD,MAAM,EAAE,OAAO,EAAE,GAAG,YAAY,IAAI,iBAAiB,EAAE,CAAC;QACxD,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAED,UAAU,CAAC,YAA2B;QACpC,MAAM,EAAE,OAAO,EAAE,GAAG,YAAY,IAAI,iBAAiB,EAAE,CAAC;QACxD,OAAO,OAAO,CAAC,OAAiC,CAAC;IACnD,CAAC;IAED,YAAY,CAAC,IAAY,EAAE,YAA2B;QACpD,MAAM,EAAE,QAAQ,EAAE,GAAG,YAAY,IAAI,iBAAiB,EAAE,CAAC;QACzD,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;CACF"}
@@ -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"}