@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.
Files changed (105) hide show
  1. package/README.md +26 -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 +106 -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 +106 -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 +30 -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 +83 -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 +22 -0
  29. package/dist/handlers/logout-handler.js.map +1 -0
  30. package/dist/handlers/start-enterprise-login.d.ts +21 -0
  31. package/dist/handlers/start-enterprise-login.d.ts.map +1 -0
  32. package/dist/handlers/start-enterprise-login.js +26 -0
  33. package/dist/handlers/start-enterprise-login.js.map +1 -0
  34. package/dist/index.d.ts +14 -343
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +10 -521
  37. package/dist/index.js.map +1 -1
  38. package/dist/middleware/claim-auth.d.ts +28 -0
  39. package/dist/middleware/claim-auth.d.ts.map +1 -0
  40. package/dist/middleware/claim-auth.js +2 -0
  41. package/dist/middleware/claim-auth.js.map +1 -0
  42. package/dist/middleware/claim-check.d.ts +41 -0
  43. package/dist/middleware/claim-check.d.ts.map +1 -0
  44. package/dist/middleware/claim-check.js +62 -0
  45. package/dist/middleware/claim-check.js.map +1 -0
  46. package/dist/middleware/claim-equals.d.ts +27 -0
  47. package/dist/middleware/claim-equals.d.ts.map +1 -0
  48. package/dist/middleware/claim-equals.js +48 -0
  49. package/dist/middleware/claim-equals.js.map +1 -0
  50. package/dist/middleware/claim-includes.d.ts +37 -0
  51. package/dist/middleware/claim-includes.d.ts.map +1 -0
  52. package/dist/middleware/claim-includes.js +68 -0
  53. package/dist/middleware/claim-includes.js.map +1 -0
  54. package/dist/middleware/require-auth.d.ts +48 -0
  55. package/dist/middleware/require-auth.d.ts.map +1 -0
  56. package/dist/middleware/require-auth.js +61 -0
  57. package/dist/middleware/require-auth.js.map +1 -0
  58. package/dist/migration/index.d.ts +5 -0
  59. package/dist/migration/index.d.ts.map +1 -0
  60. package/dist/migration/index.js +3 -0
  61. package/dist/migration/index.js.map +1 -0
  62. package/dist/router.d.ts +34 -0
  63. package/dist/router.d.ts.map +1 -0
  64. package/dist/router.js +76 -0
  65. package/dist/router.js.map +1 -0
  66. package/dist/store/express-cookie-handler.d.ts +17 -0
  67. package/dist/store/express-cookie-handler.d.ts.map +1 -0
  68. package/dist/store/express-cookie-handler.js +30 -0
  69. package/dist/store/express-cookie-handler.js.map +1 -0
  70. package/dist/store/express-oidc-hkdf.d.ts +2 -0
  71. package/dist/store/express-oidc-hkdf.d.ts.map +1 -0
  72. package/dist/store/express-oidc-hkdf.js +11 -0
  73. package/dist/store/express-oidc-hkdf.js.map +1 -0
  74. package/dist/store/legacy-compatible-stateful-state-store.d.ts +139 -0
  75. package/dist/store/legacy-compatible-stateful-state-store.d.ts.map +1 -0
  76. package/dist/store/legacy-compatible-stateful-state-store.js +234 -0
  77. package/dist/store/legacy-compatible-stateful-state-store.js.map +1 -0
  78. package/dist/store/legacy-compatible-stateless-state-store.d.ts +82 -0
  79. package/dist/store/legacy-compatible-stateless-state-store.d.ts.map +1 -0
  80. package/dist/store/legacy-compatible-stateless-state-store.js +135 -0
  81. package/dist/store/legacy-compatible-stateless-state-store.js.map +1 -0
  82. package/dist/store/legacy-session-transformer.d.ts +67 -0
  83. package/dist/store/legacy-session-transformer.d.ts.map +1 -0
  84. package/dist/store/legacy-session-transformer.js +118 -0
  85. package/dist/store/legacy-session-transformer.js.map +1 -0
  86. package/dist/store/request-context.d.ts +36 -0
  87. package/dist/store/request-context.d.ts.map +1 -0
  88. package/dist/store/request-context.js +49 -0
  89. package/dist/store/request-context.js.map +1 -0
  90. package/dist/types/express.d.ts +13 -0
  91. package/dist/types/express.d.ts.map +1 -0
  92. package/dist/types/express.js +2 -0
  93. package/dist/types/express.js.map +1 -0
  94. package/dist/types.d.ts +190 -0
  95. package/dist/types.d.ts.map +1 -0
  96. package/dist/types.js +2 -0
  97. package/dist/types.js.map +1 -0
  98. package/dist/utils.d.ts +35 -0
  99. package/dist/utils.d.ts.map +1 -0
  100. package/dist/utils.js +186 -0
  101. package/dist/utils.js.map +1 -0
  102. package/package.json +22 -14
  103. package/dist/index.cjs +0 -566
  104. package/dist/index.cjs.map +0 -1
  105. package/dist/index.d.cts +0 -343
package/README.md CHANGED
@@ -8,13 +8,35 @@ The Auth0 Express SDK is a library for implementing user authentication in Expre
8
8
  ![Downloads](https://img.shields.io/npm/dw/@auth0/auth0-express)
9
9
  [![License](https://img.shields.io/badge/license-Apache%20License%202.0-blue)](https://opensource.org/license/apache-2-0)
10
10
 
11
- 📚 [Documentation](#documentation) - 🚀 [Getting Started](#getting-started) - 💬 [Feedback](#feedback)
11
+ 📚 [Documentation](#documentation) - 🔎 [Features](#features) - 🚀 [Getting Started](#getting-started) - 💬 [Feedback](#feedback)
12
12
 
13
13
  ## Documentation
14
14
 
15
15
  - [Examples](https://github.com/auth0/auth0-express/blob/main/packages/auth0-express/EXAMPLES.md) - examples for your different use cases.
16
16
  - [Docs Site](https://auth0.com/docs) - explore our docs site and learn more about Auth0.
17
17
 
18
+ ## Features
19
+
20
+ Jump straight to the capability you need.
21
+
22
+ | Feature | What it does |
23
+ | --- | --- |
24
+ | [Quick start](#getting-started) | Mount Auth0 with `createAuth0` in a few lines |
25
+ | [Environment variables](#using-environment-variables) | Configure from `AUTH0_*` env vars instead of hardcoding |
26
+ | [Migrate from `express-openid-connect`](#using-environment-variables) | Supported legacy env var aliases for an easier move |
27
+ | [Built-in routes](#routes) | `/auth/login`, `/logout`, `/callback`, back-channel logout |
28
+ | [Custom login / logout / callback](#3-adding-login-and-logout) | Roll your own routes instead of the mounted ones |
29
+ | [Configure mounted routes](./EXAMPLES.md#configuring-the-mounted-routes) | Rename, re-path, or disable the built-in routes |
30
+ | [Protect a route with a session](#4-protecting-routes) | Gate server-rendered pages behind a login session |
31
+ | [Get the current session / user](#4-protecting-routes) | Read the authenticated user from `req.auth0` |
32
+ | [Call an API (`getAccessToken`)](#requesting-an-access-token-to-call-an-api) | Get an access token to call APIs as the user |
33
+ | [Authorization with claims](./EXAMPLES.md#authorization-with-claims) | Restrict routes with `claimEquals`, `claimIncludes`, `claimCheck` |
34
+ | [Dynamic app base URLs](./EXAMPLES.md#dynamic-application-base-urls) | Infer the base URL per host or use an allow-list |
35
+ | [Enterprise Connect](./EXAMPLES.md#enterprise-connect) | Use Auth0 as a pure SSO relay while your app owns the session |
36
+ | [Multiple Custom Domains (MCD)](./EXAMPLES.md#multiple-custom-domains-mcd) | Resolve the Auth0 domain per request |
37
+ | [Custom `fetch`](./EXAMPLES.md#configuring-a-customfetch-implementation) | Swap in your own fetch (proxies, retries, instrumentation) |
38
+ | [Discovery cache](./EXAMPLES.md#discovery-cache) | Control caching of OIDC discovery metadata |
39
+
18
40
  ## Getting Started
19
41
 
20
42
  ### 1. Install the SDK
@@ -23,7 +45,7 @@ The Auth0 Express SDK is a library for implementing user authentication in Expre
23
45
  npm i @auth0/auth0-express@beta
24
46
  ```
25
47
 
26
- This library requires Node.js 20 LTS and newer LTS versions.
48
+ This library requires Node.js 22 LTS and newer LTS versions.
27
49
 
28
50
  ### 2. Register the Auth0 Express Router
29
51
 
@@ -52,6 +74,8 @@ The `SESSION_SECRET` is the key used to encrypt the session cookie. You can gene
52
74
  openssl rand -hex 64
53
75
  ```
54
76
 
77
+ To rotate the session secret without logging existing users out, pass an array (`sessionSecret: [newSecret, oldSecret]`) or a comma-separated `AUTH0_SESSION_SECRET`. The first secret encrypts new cookies; all secrets are tried, in order, when decrypting. Once every session has been re-encrypted under the new secret, drop the old one.
78
+
55
79
  The `APP_BASE_URL` is the URL that your application is running on. When developing locally, this is most commonly `http://localhost:3000`. `APP_BASE_URL` is optional. Omit it to infer the base URL from the request host (useful for preview deployments), or provide a comma-separated list of allowed URLs. See [Dynamic Application Base URLs](./EXAMPLES.md#dynamic-application-base-urls).
56
80
 
57
81
  #### Using Environment Variables
@@ -0,0 +1,31 @@
1
+ import type { Request } from 'express';
2
+ /**
3
+ * Checks if a string is a valid HTTP or HTTPS URL.
4
+ */
5
+ export declare function isUrl(value: string): boolean;
6
+ /**
7
+ * Infers the application base URL from the incoming request.
8
+ *
9
+ * The protocol comes from `req.protocol`, which already honors `trust proxy`
10
+ * (reading `X-Forwarded-Proto` only when the proxy is trusted) on both Express
11
+ * 4 and 5. For the host we only consult `X-Forwarded-Host` when `trust proxy`
12
+ * trusts the peer; otherwise we use the raw `Host` header. We read the header
13
+ * directly rather than `req.host`/`req.hostname` because the Express 4 getters
14
+ * strip the port (and `req.host` is deprecated there), whereas the allow-list
15
+ * matches on origin including the port.
16
+ *
17
+ * Returns null when a valid origin cannot be built.
18
+ */
19
+ export declare function inferBaseUrlFromRequest(req: Request): string | null;
20
+ /**
21
+ * Resolves the application base URL for the current request.
22
+ *
23
+ * - `string`: used as-is (static configuration).
24
+ * - `undefined`: inferred from the request host (dynamic mode).
25
+ * - `string[]`: the request origin is matched against the allow-list; the
26
+ * matching origin is returned, otherwise an error is thrown.
27
+ *
28
+ * @throws {InvalidConfigurationError} When the base URL cannot be resolved.
29
+ */
30
+ export declare function resolveAppBaseUrl(appBaseUrl: string | string[] | undefined, req?: Request): string;
31
+ //# sourceMappingURL=app-base-url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-base-url.d.ts","sourceRoot":"","sources":["../src/app-base-url.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAKvC;;GAEG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAO5C;AA2BD;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAgBnE;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,EAAE,GAAG,CAAC,EAAE,OAAO,GAAG,MAAM,CAyClG"}
@@ -0,0 +1,106 @@
1
+ import { InvalidConfigurationError } from './errors/index.js';
2
+ const HTTP_PROTOCOLS = new Set(['http:', 'https:']);
3
+ /**
4
+ * Checks if a string is a valid HTTP or HTTPS URL.
5
+ */
6
+ export function isUrl(value) {
7
+ try {
8
+ const parsed = new URL(value);
9
+ return HTTP_PROTOCOLS.has(parsed.protocol);
10
+ }
11
+ catch {
12
+ return false;
13
+ }
14
+ }
15
+ function getFirstHeaderValue(value) {
16
+ if (!value) {
17
+ return undefined;
18
+ }
19
+ const raw = Array.isArray(value) ? value[0] : value;
20
+ if (!raw) {
21
+ return undefined;
22
+ }
23
+ const [first] = raw.split(',');
24
+ return first?.trim() || undefined;
25
+ }
26
+ /**
27
+ * Returns true when Express has been configured to trust the peer that sent
28
+ * this request (`trust proxy`), meaning forwarded headers may be honored.
29
+ *
30
+ * We reuse Express's own compiled `trust proxy fn` rather than reimplementing
31
+ * the trust policy, so this matches how `req.protocol`/`req.secure` decide
32
+ * whether to trust `X-Forwarded-*`. This works identically on Express 4 and 5.
33
+ */
34
+ function isProxyTrusted(req) {
35
+ const trust = req.app?.get('trust proxy fn');
36
+ return typeof trust === 'function' && trust(req.socket?.remoteAddress, 0);
37
+ }
38
+ /**
39
+ * Infers the application base URL from the incoming request.
40
+ *
41
+ * The protocol comes from `req.protocol`, which already honors `trust proxy`
42
+ * (reading `X-Forwarded-Proto` only when the proxy is trusted) on both Express
43
+ * 4 and 5. For the host we only consult `X-Forwarded-Host` when `trust proxy`
44
+ * trusts the peer; otherwise we use the raw `Host` header. We read the header
45
+ * directly rather than `req.host`/`req.hostname` because the Express 4 getters
46
+ * strip the port (and `req.host` is deprecated there), whereas the allow-list
47
+ * matches on origin including the port.
48
+ *
49
+ * Returns null when a valid origin cannot be built.
50
+ */
51
+ export function inferBaseUrlFromRequest(req) {
52
+ const trusted = isProxyTrusted(req);
53
+ const forwardedHost = trusted ? getFirstHeaderValue(req.headers['x-forwarded-host']) : undefined;
54
+ const host = forwardedHost || getFirstHeaderValue(req.headers['host']);
55
+ const proto = req.protocol;
56
+ // Reject hosts containing userinfo (`@`). A value like `legitimate.com@evil.com`
57
+ // is parsed by the URL constructor as userinfo `legitimate.com` with origin
58
+ // `evil.com`, which would let an attacker smuggle an attacker-controlled origin
59
+ // past the origin checks that consume this base URL.
60
+ if (!host || !proto || host.includes('@')) {
61
+ return null;
62
+ }
63
+ const candidate = `${proto}://${host}`;
64
+ return isUrl(candidate) ? candidate : null;
65
+ }
66
+ /**
67
+ * Resolves the application base URL for the current request.
68
+ *
69
+ * - `string`: used as-is (static configuration).
70
+ * - `undefined`: inferred from the request host (dynamic mode).
71
+ * - `string[]`: the request origin is matched against the allow-list; the
72
+ * matching origin is returned, otherwise an error is thrown.
73
+ *
74
+ * @throws {InvalidConfigurationError} When the base URL cannot be resolved.
75
+ */
76
+ export function resolveAppBaseUrl(appBaseUrl, req) {
77
+ const staticAppBaseUrl = typeof appBaseUrl === 'string' ? appBaseUrl : undefined;
78
+ const allowedAppBaseUrls = typeof appBaseUrl === 'string' ? undefined : appBaseUrl;
79
+ if (staticAppBaseUrl) {
80
+ return staticAppBaseUrl;
81
+ }
82
+ if (!req) {
83
+ throw new InvalidConfigurationError('APP_BASE_URL is not configured as a static string, and a request context is not available.');
84
+ }
85
+ const inferred = inferBaseUrlFromRequest(req);
86
+ if (!inferred) {
87
+ throw new InvalidConfigurationError('APP_BASE_URL is not configured as a static string, and the request origin could not be determined from the request context.');
88
+ }
89
+ if (!allowedAppBaseUrls) {
90
+ return inferred;
91
+ }
92
+ const requestOrigin = new URL(inferred).origin;
93
+ const matchedEntry = allowedAppBaseUrls.find((allowedUrl) => {
94
+ try {
95
+ return new URL(allowedUrl).origin === requestOrigin;
96
+ }
97
+ catch {
98
+ return false;
99
+ }
100
+ });
101
+ if (matchedEntry !== undefined) {
102
+ return matchedEntry;
103
+ }
104
+ throw new InvalidConfigurationError('APP_BASE_URL is not configured as a static string, and the APP_BASE_URL configuration does not contain a match for the current request origin.');
105
+ }
106
+ //# sourceMappingURL=app-base-url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-base-url.js","sourceRoot":"","sources":["../src/app-base-url.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAE9D,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;AAEpD;;GAEG;AACH,MAAM,UAAU,KAAK,CAAC,KAAa;IACjC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;QAC9B,OAAO,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAAC,MAAM,CAAC;Q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OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,MAAM,IAAI,yBAAyB,CACjC,gJAAgJ,CACjJ,CAAC;AACJ,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { Auth0Options } from './types.js';
2
+ /**
3
+ * Merges environment variables with provided configuration options.
4
+ * Environment variables are used as defaults and can be overridden by explicitly provided options.
5
+ *
6
+ * Supported environment variables:
7
+ * - AUTH0_DOMAIN or ISSUER_BASE_URL
8
+ * - AUTH0_CLIENT_ID or CLIENT_ID: Auth0 application client ID
9
+ * - AUTH0_CLIENT_SECRET or CLIENT_SECRET: Auth0 application client secret
10
+ * - APP_BASE_URL or BASE_URL: Application base URL
11
+ * - AUTH0_SESSION_SECRET or SECRET: Session secret for cookie signing
12
+ * - AUTH0_AUDIENCE: Optional API audience
13
+ */
14
+ export declare function getConfig(config?: Partial<Auth0Options>): Auth0Options;
15
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AA6E/C;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,MAAM,GAAE,OAAO,CAAC,YAAY,CAAM,GAAG,YAAY,CAiD1E"}
package/dist/config.js ADDED
@@ -0,0 +1,106 @@
1
+ import { MissingRequiredArgumentError } from '@auth0/auth0-server-js';
2
+ import { isUrl } from './app-base-url.js';
3
+ import { InvalidConfigurationError } from './errors/index.js';
4
+ function stripProtocol(url) {
5
+ return url ? url.replace(/^https?:\/\//, '') : url;
6
+ }
7
+ function parseCommaSeparatedEnv(value) {
8
+ if (!value) {
9
+ return undefined;
10
+ }
11
+ if (value.includes(',')) {
12
+ const entries = value
13
+ .split(',')
14
+ .map((entry) => entry.trim())
15
+ .filter(Boolean);
16
+ return entries.length === 1 ? entries[0] : entries;
17
+ }
18
+ return value;
19
+ }
20
+ function validateAppBaseUrl(appBaseUrl) {
21
+ if (appBaseUrl === undefined) {
22
+ return; // dynamic mode
23
+ }
24
+ if (Array.isArray(appBaseUrl)) {
25
+ if (appBaseUrl.length === 0) {
26
+ throw new InvalidConfigurationError('APP_BASE_URL array configuration cannot be empty.');
27
+ }
28
+ const invalid = appBaseUrl.filter((url) => !isUrl(url));
29
+ if (invalid.length > 0) {
30
+ throw new InvalidConfigurationError(`APP_BASE_URL array contains invalid URLs: ${invalid.join(', ')}`);
31
+ }
32
+ return;
33
+ }
34
+ if (!isUrl(appBaseUrl)) {
35
+ throw new InvalidConfigurationError(`APP_BASE_URL must be a valid http(s) URL: ${appBaseUrl}`);
36
+ }
37
+ }
38
+ function enforceSecureCookies(config) {
39
+ const isProduction = process.env.NODE_ENV === 'production';
40
+ const isDynamic = typeof config.appBaseUrl !== 'string';
41
+ if (!isProduction || !isDynamic) {
42
+ return;
43
+ }
44
+ const explicitSecure = config.sessionConfiguration?.cookie?.secure;
45
+ if (explicitSecure === false) {
46
+ throw new InvalidConfigurationError('Secure cookies are required when relying on dynamic base URLs in production. ' +
47
+ 'Remove the explicit `sessionConfiguration.cookie.secure = false` or set a static APP_BASE_URL.');
48
+ }
49
+ config.sessionConfiguration = {
50
+ ...config.sessionConfiguration,
51
+ cookie: {
52
+ ...config.sessionConfiguration?.cookie,
53
+ secure: true,
54
+ },
55
+ };
56
+ }
57
+ /**
58
+ * Merges environment variables with provided configuration options.
59
+ * Environment variables are used as defaults and can be overridden by explicitly provided options.
60
+ *
61
+ * Supported environment variables:
62
+ * - AUTH0_DOMAIN or ISSUER_BASE_URL
63
+ * - AUTH0_CLIENT_ID or CLIENT_ID: Auth0 application client ID
64
+ * - AUTH0_CLIENT_SECRET or CLIENT_SECRET: Auth0 application client secret
65
+ * - APP_BASE_URL or BASE_URL: Application base URL
66
+ * - AUTH0_SESSION_SECRET or SECRET: Session secret for cookie signing
67
+ * - AUTH0_AUDIENCE: Optional API audience
68
+ */
69
+ export function getConfig(config = {}) {
70
+ const mergedConfig = {
71
+ domain: process.env.AUTH0_DOMAIN || stripProtocol(process.env.ISSUER_BASE_URL),
72
+ clientId: process.env.AUTH0_CLIENT_ID || process.env.CLIENT_ID,
73
+ clientSecret: process.env.AUTH0_CLIENT_SECRET || process.env.CLIENT_SECRET,
74
+ appBaseUrl: parseCommaSeparatedEnv(process.env.APP_BASE_URL || process.env.BASE_URL),
75
+ sessionSecret: parseCommaSeparatedEnv(process.env.AUTH0_SESSION_SECRET || process.env.SECRET),
76
+ audience: process.env.AUTH0_AUDIENCE,
77
+ ...config,
78
+ };
79
+ // A comma-separated value is normalized into an array whether it comes from
80
+ // the environment or is passed explicitly as `appBaseUrl`/`sessionSecret`,
81
+ // so both sources behave identically.
82
+ if (typeof mergedConfig.appBaseUrl === 'string') {
83
+ mergedConfig.appBaseUrl = parseCommaSeparatedEnv(mergedConfig.appBaseUrl);
84
+ }
85
+ if (typeof mergedConfig.sessionSecret === 'string') {
86
+ mergedConfig.sessionSecret = parseCommaSeparatedEnv(mergedConfig.sessionSecret);
87
+ }
88
+ if (!mergedConfig.domain) {
89
+ throw new MissingRequiredArgumentError('domain');
90
+ }
91
+ if (!mergedConfig.clientId) {
92
+ throw new MissingRequiredArgumentError('clientId');
93
+ }
94
+ validateAppBaseUrl(mergedConfig.appBaseUrl);
95
+ if (!mergedConfig.sessionSecret ||
96
+ (Array.isArray(mergedConfig.sessionSecret) && mergedConfig.sessionSecret.length === 0)) {
97
+ throw new MissingRequiredArgumentError('sessionSecret');
98
+ }
99
+ enforceSecureCookies(mergedConfig);
100
+ if (mergedConfig.enterpriseConnect && !mergedConfig.onCallback) {
101
+ throw new InvalidConfigurationError('`onCallback` is required when `enterpriseConnect: true`. ' +
102
+ 'Write your own session inside the hook and call res.redirect().');
103
+ }
104
+ return mergedConfig;
105
+ }
106
+ //# sourceMapping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EACtF,CAAC;QACD,MAAM,IAAI,4BAA4B,CAAC,eAAe,CAAC,CAAC;IAC1D,CAAC;IAED,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAEnC,IAAI,YAAY,CAAC,iBAAiB,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,CAAC;QAC/D,MAAM,IAAI,yBAAyB,CACjC,2DAA2D;YACzD,iEAAiE,CACpE,CAAC;IACJ,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { InvalidConfigurationError } from '@auth0/auth0-server-js';
2
+ export declare class MissingStoreOptionsError extends Error {
3
+ code: string;
4
+ constructor(message?: string);
5
+ }
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAEnE,qBAAa,wBAAyB,SAAQ,KAAK;IAC1C,IAAI,EAAE,MAAM,CAAiC;gBAExC,OAAO,CAAC,EAAE,MAAM;CAI7B"}
@@ -0,0 +1,9 @@
1
+ export { InvalidConfigurationError } from '@auth0/auth0-server-js';
2
+ export class MissingStoreOptionsError extends Error {
3
+ code = 'missing_store_options_error';
4
+ constructor(message) {
5
+ super(message ?? 'The store options are missing, making it impossible to interact with the store.');
6
+ this.name = 'MissingStoreOptionsError';
7
+ }
8
+ }
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAEnE,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IAC1C,IAAI,GAAW,6BAA6B,CAAC;IAEpD,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,IAAI,iFAAiF,CAAC,CAAC;QACpG,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ import { Request, Response } from 'express';
2
+ export declare function handleBackchannelLogout(req: Request, res: Response): Promise<void>;
3
+ //# sourceMappingURL=backchannel-logout-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backchannel-logout-handler.d.ts","sourceRoot":"","sources":["../../src/handlers/backchannel-logout-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE5C,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAcxF"}
@@ -0,0 +1,15 @@
1
+ export async function handleBackchannelLogout(req, res) {
2
+ const logoutToken = req.body.logout_token;
3
+ if (!logoutToken) {
4
+ res.status(400).send('Missing `logout_token` in the request body.');
5
+ return;
6
+ }
7
+ try {
8
+ await req.auth0.client.handleBackchannelLogout(logoutToken);
9
+ res.status(204).send(null);
10
+ }
11
+ catch (e) {
12
+ res.status(400).send(e.message);
13
+ }
14
+ }
15
+ //# sourceMappingURL=backchannel-logout-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backchannel-logout-handler.js","sourceRoot":"","sources":["../../src/handlers/backchannel-logout-handler.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,GAAY,EAAE,GAAa;IACvE,MAAM,WAAW,GAAG,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC;IAE1C,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC;QACpE,OAAO;IACT,CAAC;IAED,IAAI,CAAC;QACH,MAAM,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,uBAAuB,CAAC,WAAW,CAAC,CAAC;QAC5D,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAE,CAAW,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { Request, Response } from 'express';
2
+ import { Auth0Options } from '../types.js';
3
+ export declare function handleCallback(req: Request, res: Response, options: Auth0Options): Promise<void>;
4
+ //# sourceMappingURL=callback-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callback-handler.d.ts","sourceRoot":"","sources":["../../src/handlers/callback-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,wBAAsB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAiCtG"}
@@ -0,0 +1,30 @@
1
+ import { createRouteUrl } from '../utils.js';
2
+ import { resolveAppBaseUrl } from '../app-base-url.js';
3
+ export async function handleCallback(req, res, options) {
4
+ try {
5
+ const appBaseUrl = resolveAppBaseUrl(options.appBaseUrl, req);
6
+ if (options.enterpriseConnect) {
7
+ const result = await req.auth0.client.completeInteractiveLogin(createRouteUrl(req.url, appBaseUrl));
8
+ await options.onCallback(req, res, {
9
+ idTokenClaims: result.idTokenClaims,
10
+ user: result.user,
11
+ appState: result.appState,
12
+ });
13
+ if (!res.headersSent) {
14
+ res.status(500).json({ error: 'callback_not_resolved', message: 'onCallback resolved without ending the response' });
15
+ }
16
+ return;
17
+ }
18
+ const { appState } = await req.auth0.client.completeInteractiveLogin(createRouteUrl(req.url, appBaseUrl));
19
+ res.redirect(appState?.returnTo ?? appBaseUrl);
20
+ }
21
+ catch (e) {
22
+ /* eslint-disable @typescript-eslint/no-explicit-any */
23
+ const error = e;
24
+ res.status(500).json({
25
+ error: error.cause?.error || error.name,
26
+ message: error.cause?.error_description || error.message,
27
+ });
28
+ }
29
+ }
30
+ //# sourceMappingURL=callback-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callback-handler.js","sourceRoot":"","sources":["../../src/handlers/callback-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAGvD,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,GAAY,EAAE,GAAa,EAAE,OAAqB;IACrF,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,iBAAiB,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QAE9D,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;YAC9B,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,wBAAwB,CAC5D,cAAc,CAAC,GAAG,CAAC,GAAG,EAAE,UAAU,CAAC,CACpC,CAAC;YACF,MAAM,OAAO,CAAC,UAAW,CAAC,GAAG,EAAE,GAAG,EAAE;gBAClC,aAAa,EAAE,MAAM,CAAC,aAAa;gBACnC,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,QAAQ,EAAE,MAAM,CAAC,QAAQ;aAC1B,CAAC,CAAC;YACH,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;gBACrB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,uBAAuB,EAAE,OAAO,EAAE,iDAAiD,EAAE,CAAC,CAAC;YACvH,CAAC;YACD,OAAO;QACT,CAAC;QAED,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,wBAAwB,CAClE,cAAc,CAAC,GAAG,CAAC,GAAG,EAAE,UAAU,CAAC,CACpC,CAAC;QAEF,GAAG,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,IAAI,UAAU,CAAC,CAAC;IACjD,CAAC;IAAC,OAAO,CAAU,EAAE,CAAC;QACpB,uDAAuD;QACvD,MAAM,KAAK,GAAG,CAAQ,CAAC;QAEvB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;YACnB,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,IAAI,KAAK,CAAC,IAAI;YACvC,OAAO,EAAE,KAAK,CAAC,KAAK,EAAE,iBAAiB,IAAI,KAAK,CAAC,OAAO;SACzD,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { Request, Response } from 'express';
2
+ import { Auth0Options } from '../index.js';
3
+ export declare function handleLogin(req: Request, res: Response, options: Auth0Options): Promise<void>;
4
+ //# sourceMappingURL=login-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login-handler.d.ts","sourceRoot":"","sources":["../../src/handlers/login-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AA+D3C,wBAAsB,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CA0BnG"}
@@ -0,0 +1,83 @@
1
+ import { createRouteUrl, toSafeRedirect } from '../utils.js';
2
+ import { resolveAppBaseUrl } from '../app-base-url.js';
3
+ // Block both Object.prototype own-property names and commonly abused
4
+ // prototype-pollution keys that are not own-properties of Object.prototype.
5
+ const DENIED_KEYS = new Set([
6
+ ...Object.getOwnPropertyNames(Object.prototype),
7
+ '__proto__',
8
+ 'constructor',
9
+ 'prototype',
10
+ ]);
11
+ // OAuth/OIDC protocol parameters that must be SDK-controlled, not user-supplied
12
+ const RESERVED_OAUTH_PARAMS = new Set([
13
+ 'response_type',
14
+ 'state',
15
+ 'code_challenge',
16
+ 'code_challenge_method',
17
+ 'client_id',
18
+ 'redirect_uri',
19
+ 'nonce',
20
+ 'scope',
21
+ // Target-API params are one family: the transaction only records `audience`, so a link
22
+ // supplying an alias (`resource`, etc.) would mint a token for that target while it is stored
23
+ // under our own audience key, and `getAccessToken()` would later hand the app a token minted
24
+ // for someone else's resource. Reserve the whole family, matching auth0-auth-js's denylist.
25
+ 'audience',
26
+ 'aud',
27
+ 'resource',
28
+ 'resources',
29
+ 'resource_indicator',
30
+ // Request Objects and related params must be SDK/tenant-controlled, not
31
+ // user-supplied via a login link. prompt/login_hint are
32
+ // intentionally NOT reserved — integrators commonly forward them.
33
+ 'request',
34
+ 'request_uri',
35
+ 'id_token_hint',
36
+ 'claims',
37
+ 'response_mode',
38
+ // Rich Authorization Requests: a crafted link must not be able to inject its own grant
39
+ // details, which an app reading `authorizationDetails` in its callback would then act on.
40
+ 'authorization_details',
41
+ ]);
42
+ /**
43
+ * Filters out reserved OAuth parameters and any additional disallowed parameters from the input record.
44
+ * This ensures that only safe, non-reserved parameters are included in the authorization request.
45
+ * @param params The record of parameters to filter.
46
+ * @param disallowed An array of parameter names that should be excluded.
47
+ * @returns An object containing only the allowed parameters, or undefined if none are allowed.
48
+ */
49
+ function filterAuthorizationParams(params, disallowed) {
50
+ const filtered = Object.create(null);
51
+ for (const [key, value] of Object.entries(params)) {
52
+ if (!DENIED_KEYS.has(key) && !disallowed.includes(key) && !RESERVED_OAUTH_PARAMS.has(key)) {
53
+ filtered[key] = value;
54
+ }
55
+ }
56
+ return Object.keys(filtered).length > 0 ? filtered : undefined;
57
+ }
58
+ export async function handleLogin(req, res, options) {
59
+ try {
60
+ const appBaseUrl = resolveAppBaseUrl(options.appBaseUrl, req);
61
+ const callbackPath = options.routes?.callback ?? '/auth/callback';
62
+ const redirectUri = createRouteUrl(callbackPath, appBaseUrl);
63
+ const query = req.query;
64
+ const dangerousReturnTo = query.returnTo;
65
+ const sanitizedReturnTo = toSafeRedirect(dangerousReturnTo || '/', appBaseUrl);
66
+ const authorizationUrl = await req.auth0.client.startInteractiveLogin({
67
+ pushedAuthorizationRequests: options.pushedAuthorizationRequests,
68
+ appState: { returnTo: sanitizedReturnTo },
69
+ authorizationParams: {
70
+ ...filterAuthorizationParams(query, ['returnTo']),
71
+ redirect_uri: redirectUri.toString(),
72
+ },
73
+ });
74
+ res.redirect(authorizationUrl.href);
75
+ }
76
+ catch (error) {
77
+ res.status(500).json({
78
+ error: error.name,
79
+ message: error.message,
80
+ });
81
+ }
82
+ }
83
+ //# sourceMappingURL=login-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login-handler.js","sourceRoot":"","sources":["../../src/handlers/login-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAGvD,qEAAqE;AACrE,4EAA4E;AAC5E,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC;IAC1B,GAAG,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC,SAAS,CAAC;IAC/C,WAAW;IACX,aAAa;IACb,WAAW;CACZ,CAAC,CAAC;AAEH,gFAAgF;AAChF,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,eAAe;IACf,OAAO;IACP,gBAAgB;IAChB,uBAAuB;IACvB,WAAW;IACX,cAAc;IACd,OAAO;IACP,OAAO;IACP,uFAAuF;IACvF,8FAA8F;IAC9F,6FAA6F;IAC7F,4FAA4F;IAC5F,UAAU;IACV,KAAK;IACL,UAAU;IACV,WAAW;IACX,oBAAoB;IACpB,wEAAwE;IACxE,wDAAwD;IACxD,kEAAkE;IAClE,SAAS;IACT,aAAa;IACb,e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,MAAM,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,qBAAqB,CAAC;YACpE,2BAA2B,EAAE,OAAO,CAAC,2BAA2B;YAChE,QAAQ,EAAE,EAAE,QAAQ,EAAE,iBAAiB,EAAE;YACzC,mBAAmB,EAAE;gBACnB,GAAG,yBAAyB,CAAC,KAAK,EAAE,CAAC,UAAU,CAAC,CAAC;gBACjD,YAAY,EAAE,WAAW,CAAC,QAAQ,EAAE;aACrC;SACF,CAAC,CAAC;QAEH,GAAG,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;YACnB,KAAK,EAAG,KAAe,CAAC,IAAI;YAC5B,OAAO,EAAG,KAAe,CAAC,OAAO;SAClC,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { Request, Response } from 'express';
2
+ import { Auth0Options } from '../types.js';
3
+ export declare function handleLogout(req: Request, res: Response, options: Auth0Options): Promise<void>;
4
+ //# sourceMappingURL=logout-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logout-handler.d.ts","sourceRoot":"","sources":["../../src/handlers/logout-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,wBAAsB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAqBpG"}
@@ -0,0 +1,22 @@
1
+ import { resolveAppBaseUrl } from '../app-base-url.js';
2
+ export async function handleLogout(req, res, options) {
3
+ try {
4
+ const returnTo = resolveAppBaseUrl(options.appBaseUrl, req);
5
+ // In Enterprise Connect mode the mounted route always forces a federated
6
+ // logout so the enterprise IdP session is ended too. In classic mode we
7
+ // forward ?federated=true when the caller asks for it. Any warning about
8
+ // federated=false is emitted by the upstream client.logout(), not here.
9
+ const federated = options.enterpriseConnect || req.query.federated === 'true'
10
+ ? { federated: true }
11
+ : {};
12
+ const logoutUrl = await req.auth0.client.logout({ returnTo, ...federated });
13
+ res.redirect(logoutUrl.href);
14
+ }
15
+ catch (error) {
16
+ res.status(500).json({
17
+ error: error.name,
18
+ message: error.message,
19
+ });
20
+ }
21
+ }
22
+ //# sourceMappingURL=logout-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logout-handler.js","sourceRoot":"","sources":["../../src/handlers/logout-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAGvD,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,GAAY,EAAE,GAAa,EAAE,OAAqB;IACnF,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,iBAAiB,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QAC5D,yEAAyE;QACzE,wEAAwE;QACxE,yEAAyE;QACzE,wEAAwE;QACxE,MAAM,SAAS,GACb,OAAO,CAAC,iBAAiB,IAAI,GAAG,CAAC,KAAK,CAAC,SAAS,KAAK,MAAM;YACzD,CAAC,CAAC,EAAE,SAAS,EAAE,IAAa,EAAE;YAC9B,CAAC,CAAC,EAAE,CAAC;QAET,MAAM,SAAS,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC;QAE5E,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;YACnB,KAAK,EAAG,KAAe,CAAC,IAAI;YAC5B,OAAO,EAAG,KAAe,CAAC,OAAO;SAClC,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { Request, Response } from 'express';
2
+ import type { StartEnterpriseLoginOptions } from '@auth0/auth0-server-js';
3
+ /**
4
+ * Starts an Enterprise Connect login for the email in `options`.
5
+ *
6
+ * The upstream `@auth0/auth0-server-js` client runs WebFinger domain discovery
7
+ * and returns the authorize URL for a federated domain or `null` for a
8
+ * non-federated one (it also degrades transient discovery failures — 429,
9
+ * network errors — to `null` internally, so those never surface here).
10
+ *
11
+ * We intentionally do not swallow errors: any error the client does throw
12
+ * (e.g. misconfiguration, `EnterpriseConnectNotSupportedError`) propagates to
13
+ * the caller so real failures are visible instead of being masked as "not
14
+ * federated".
15
+ *
16
+ * @returns `true` when the domain is federated and the response was redirected
17
+ * to Auth0; `false` when the domain is not federated, so the caller can fall
18
+ * back to its own non-enterprise login.
19
+ */
20
+ export declare function startEnterpriseLogin(req: Request, res: Response, options: StartEnterpriseLoginOptions): Promise<boolean>;
21
+ //# sourceMappingURL=start-enterprise-login.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start-enterprise-login.d.ts","sourceRoot":"","sources":["../../src/handlers/start-enterprise-login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAE1E;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,OAAO,CAAC,CAOlB"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Starts an Enterprise Connect login for the email in `options`.
3
+ *
4
+ * The upstream `@auth0/auth0-server-js` client runs WebFinger domain discovery
5
+ * and returns the authorize URL for a federated domain or `null` for a
6
+ * non-federated one (it also degrades transient discovery failures — 429,
7
+ * network errors — to `null` internally, so those never surface here).
8
+ *
9
+ * We intentionally do not swallow errors: any error the client does throw
10
+ * (e.g. misconfiguration, `EnterpriseConnectNotSupportedError`) propagates to
11
+ * the caller so real failures are visible instead of being masked as "not
12
+ * federated".
13
+ *
14
+ * @returns `true` when the domain is federated and the response was redirected
15
+ * to Auth0; `false` when the domain is not federated, so the caller can fall
16
+ * back to its own non-enterprise login.
17
+ */
18
+ export async function startEnterpriseLogin(req, res, options) {
19
+ const authUrl = await req.auth0.client.startEnterpriseLogin(options);
20
+ if (authUrl) {
21
+ res.redirect(authUrl.href);
22
+ return true;
23
+ }
24
+ return false;
25
+ }
26
+ //# sourceMappingURL=start-enterprise-login.js.map