auth0 6.4.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +20 -15
  2. package/dist/cjs/index.d.ts +0 -2
  3. package/dist/cjs/index.js +0 -2
  4. package/dist/cjs/lib/errors.d.ts +0 -18
  5. package/dist/cjs/lib/errors.js +1 -25
  6. package/dist/cjs/lib/middleware/auth0-client-telemetry.d.ts +3 -7
  7. package/dist/cjs/lib/middleware/auth0-client-telemetry.js +1 -25
  8. package/dist/cjs/lib/models.d.ts +0 -24
  9. package/dist/cjs/lib/models.js +0 -53
  10. package/dist/cjs/management/version.d.ts +1 -1
  11. package/dist/cjs/management/version.js +1 -1
  12. package/dist/cjs/management/wrapper/ManagementClient.d.ts +9 -2
  13. package/dist/cjs/management/wrapper/ManagementClient.js +0 -1
  14. package/dist/cjs/management/wrapper/token-provider.d.ts +4 -2
  15. package/dist/cjs/management/wrapper/token-provider.js +142 -11
  16. package/dist/cjs/utils.d.ts +0 -18
  17. package/dist/cjs/utils.js +1 -32
  18. package/dist/esm/index.d.mts +0 -2
  19. package/dist/esm/index.mjs +0 -2
  20. package/dist/esm/lib/errors.d.mts +0 -18
  21. package/dist/esm/lib/errors.mjs +0 -22
  22. package/dist/esm/lib/middleware/auth0-client-telemetry.d.mts +3 -7
  23. package/dist/esm/lib/middleware/auth0-client-telemetry.mjs +1 -25
  24. package/dist/esm/lib/models.d.mts +0 -24
  25. package/dist/esm/lib/models.mjs +1 -49
  26. package/dist/esm/management/version.d.mts +1 -1
  27. package/dist/esm/management/version.mjs +1 -1
  28. package/dist/esm/management/wrapper/ManagementClient.d.mts +9 -2
  29. package/dist/esm/management/wrapper/ManagementClient.mjs +0 -1
  30. package/dist/esm/management/wrapper/token-provider.d.mts +4 -2
  31. package/dist/esm/management/wrapper/token-provider.mjs +142 -11
  32. package/dist/esm/utils.d.mts +0 -18
  33. package/dist/esm/utils.mjs +0 -30
  34. package/package.json +1 -2
  35. package/dist/cjs/auth/backchannel.d.ts +0 -158
  36. package/dist/cjs/auth/backchannel.js +0 -135
  37. package/dist/cjs/auth/base-auth-api.d.ts +0 -41
  38. package/dist/cjs/auth/base-auth-api.js +0 -109
  39. package/dist/cjs/auth/client-authentication.d.ts +0 -27
  40. package/dist/cjs/auth/client-authentication.js +0 -82
  41. package/dist/cjs/auth/database.d.ts +0 -157
  42. package/dist/cjs/auth/database.js +0 -94
  43. package/dist/cjs/auth/id-token-validator.d.ts +0 -18
  44. package/dist/cjs/auth/id-token-validator.js +0 -158
  45. package/dist/cjs/auth/index.d.ts +0 -65
  46. package/dist/cjs/auth/index.js +0 -80
  47. package/dist/cjs/auth/oauth.d.ts +0 -462
  48. package/dist/cjs/auth/oauth.js +0 -280
  49. package/dist/cjs/auth/passwordless.d.ts +0 -165
  50. package/dist/cjs/auth/passwordless.js +0 -173
  51. package/dist/cjs/auth/tokenExchange.d.ts +0 -166
  52. package/dist/cjs/auth/tokenExchange.js +0 -74
  53. package/dist/cjs/lib/index.d.ts +0 -3
  54. package/dist/cjs/lib/index.js +0 -18
  55. package/dist/cjs/lib/runtime.d.ts +0 -61
  56. package/dist/cjs/lib/runtime.js +0 -222
  57. package/dist/cjs/userinfo/index.d.ts +0 -87
  58. package/dist/cjs/userinfo/index.js +0 -104
  59. package/dist/esm/auth/backchannel.d.mts +0 -158
  60. package/dist/esm/auth/backchannel.mjs +0 -131
  61. package/dist/esm/auth/base-auth-api.d.mts +0 -41
  62. package/dist/esm/auth/base-auth-api.mjs +0 -103
  63. package/dist/esm/auth/client-authentication.d.mts +0 -27
  64. package/dist/esm/auth/client-authentication.mjs +0 -45
  65. package/dist/esm/auth/database.d.mts +0 -157
  66. package/dist/esm/auth/database.mjs +0 -90
  67. package/dist/esm/auth/id-token-validator.d.mts +0 -18
  68. package/dist/esm/auth/id-token-validator.mjs +0 -120
  69. package/dist/esm/auth/index.d.mts +0 -65
  70. package/dist/esm/auth/index.mjs +0 -60
  71. package/dist/esm/auth/oauth.d.mts +0 -462
  72. package/dist/esm/auth/oauth.mjs +0 -276
  73. package/dist/esm/auth/passwordless.d.mts +0 -165
  74. package/dist/esm/auth/passwordless.mjs +0 -169
  75. package/dist/esm/auth/tokenExchange.d.mts +0 -166
  76. package/dist/esm/auth/tokenExchange.mjs +0 -70
  77. package/dist/esm/lib/index.d.mts +0 -3
  78. package/dist/esm/lib/index.mjs +0 -2
  79. package/dist/esm/lib/runtime.d.mts +0 -61
  80. package/dist/esm/lib/runtime.mjs +0 -201
  81. package/dist/esm/userinfo/index.d.mts +0 -87
  82. package/dist/esm/userinfo/index.mjs +0 -98
package/README.md CHANGED
@@ -15,6 +15,8 @@
15
15
  - [SDK Documentation](http://auth0.github.io/node-auth0/) - explore the SDK documentation
16
16
  - [API Reference](https://github.com/auth0/node-auth0/blob/master/reference.md) - full reference for this library
17
17
  - [v6 Migration Guide](https://github.com/auth0/node-auth0/blob/master/v6_MIGRATION_GUIDE.md) - upgrade from v5 to v6
18
+ - [v7 Migration Guide](https://github.com/auth0/node-auth0/blob/master/v7_MIGRATION_GUIDE.md) - upgrade from v6 to v7
19
+ - [Authentication Migration Guide](https://github.com/auth0/node-auth0/tree/master/auth-migration) - migrate the Authentication API layer to `@auth0/auth0-auth-js` / `@auth0/auth0-server-js`
18
20
 
19
21
  ## Getting Started
20
22
 
@@ -34,20 +36,22 @@ npm install auth0
34
36
 
35
37
  ### Configure the SDK
36
38
 
37
- #### Authentication API Client
39
+ #### Authentication
38
40
 
39
- This client can be used to access Auth0's [Authentication API](https://auth0.com/docs/api/authentication).
41
+ For authentication operations (OAuth flows, token management, user sign-up), use [`@auth0/auth0-auth-js`](https://github.com/auth0/auth0-auth-js/tree/main/packages/auth0-auth-js). As of v7, node-auth0 no longer ships `AuthenticationClient` in its main entrypoint. The authentication layer has been separated into a dedicated package.
40
42
 
41
43
  ```js
42
- import { AuthenticationClient } from "auth0";
44
+ import { AuthClient } from "@auth0/auth0-auth-js";
43
45
 
44
- const auth0 = new AuthenticationClient({
46
+ const auth = new AuthClient({
45
47
  domain: "{YOUR_TENANT_AND REGION}.auth0.com",
46
48
  clientId: "{YOUR_CLIENT_ID}",
47
49
  clientSecret: "{OPTIONAL_CLIENT_SECRET}",
48
50
  });
49
51
  ```
50
52
 
53
+ See the [auth0-auth-js documentation](https://github.com/auth0/auth0-auth-js/tree/main/packages/auth0-auth-js) for full API reference.
54
+
51
55
  #### Management API Client
52
56
 
53
57
  The Auth0 Management API is meant to be used by back-end servers or trusted parties performing administrative tasks. Generally speaking, anything that can be done through the Auth0 dashboard (and more) can also be done through this API.
@@ -169,25 +173,28 @@ types from the root `auth0` entry adds nothing to your bundle and does not pull
169
173
  > through a bundler. A plain CommonJS `require()` cannot tree-shake and loads the full
170
174
  > resource graph.
171
175
 
172
- #### UserInfo API Client
176
+ #### User Profile Information
173
177
 
174
- This client can be used to retrieve user profile information.
178
+ As of v7, node-auth0 no longer ships `UserInfoClient`. Use `authClient.getUserInfo` from `@auth0/auth0-auth-js` instead.
175
179
 
176
180
  ```js
177
- import { UserInfoClient } from "auth0";
181
+ import { AuthClient } from "@auth0/auth0-auth-js";
178
182
 
179
- const userInfo = new UserInfoClient({
180
- domain: "{YOUR_TENANT_AND REGION}.auth0.com",
181
- });
183
+ const auth = new AuthClient({ domain: "...", clientId: "..." });
182
184
 
183
- // Get user info with an access token
184
- const userProfile = await userInfo.getUserInfo(accessToken);
185
+ // Requires a default OIDC token (openid scope, no explicit audience).
186
+ // If your app uses MRRT, request https://{domain}/userinfo as the audience.
187
+ const profile = await auth.getUserInfo({ accessToken });
185
188
  ```
186
189
 
190
+ Note: tokens issued with a custom `audience` (e.g. the Management API) are rejected by `/userinfo`. Use a token obtained without an explicit audience, or request `https://{domain}/userinfo` as the audience when using MRRT.
191
+
187
192
  ## Legacy Usage
188
193
 
189
194
  If you are migrating from the legacy `node-auth0` package (v4.x) or need to maintain compatibility with legacy code, you can use the legacy export which provides the `node-auth0` v4.x API interface.
190
195
 
196
+ **Note:** The legacy entrypoint still includes `AuthenticationClient` from the v4.x API. This is separate from the v7 main entrypoint, which no longer ships authentication clients.
197
+
191
198
  ### Installing Legacy Version
192
199
 
193
200
  The legacy version (`node-auth0` v4.x) is available through the `/legacy` export path:
@@ -202,7 +209,7 @@ const { ManagementClient, AuthenticationClient } = require("auth0/legacy");
202
209
 
203
210
  ### Legacy Configuration
204
211
 
205
- The legacy API uses the `node-auth0` v4.x configuration format and method signatures, which are different from the current v6 API:
212
+ The legacy API uses the `node-auth0` v4.x configuration format and method signatures, which are different from the current API:
206
213
 
207
214
  #### Legacy Management Client
208
215
 
@@ -375,8 +382,6 @@ const actions = await client.actions.list(listParams);
375
382
  ### Key Classes
376
383
 
377
384
  - **ManagementClient** - for Auth0 Management API operations
378
- - **AuthenticationClient** - for Auth0 Authentication API operations
379
- - **UserInfoClient** - for retrieving user profile information
380
385
 
381
386
  ## Exception Handling
382
387
 
@@ -1,6 +1,4 @@
1
1
  export * from "./management/index.js";
2
- export * from "./auth/index.js";
3
- export * from "./userinfo/index.js";
4
2
  export * from "./lib/errors.js";
5
3
  export * from "./lib/models.js";
6
4
  export * from "./lib/httpResponseHeadersUtils.js";
package/dist/cjs/index.js CHANGED
@@ -15,8 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./management/index.js"), exports);
18
- __exportStar(require("./auth/index.js"), exports);
19
- __exportStar(require("./userinfo/index.js"), exports);
20
18
  __exportStar(require("./lib/errors.js"), exports);
21
19
  __exportStar(require("./lib/models.js"), exports);
22
20
  __exportStar(require("./lib/httpResponseHeadersUtils.js"), exports);
@@ -1,13 +1,3 @@
1
- /**
2
- * Error thrown when the API returns an error response that can't be parsed to a more specific Error instance.
3
- */
4
- export declare class ResponseError extends Error {
5
- statusCode: number;
6
- body: string;
7
- headers: Headers;
8
- name: "ResponseError";
9
- constructor(statusCode: number, body: string, headers: Headers, msg?: string);
10
- }
11
1
  /**
12
2
  * Error thrown when the request is aborted due to a timeout.
13
3
  */
@@ -15,14 +5,6 @@ export declare class TimeoutError extends Error {
15
5
  name: "TimeoutError";
16
6
  constructor();
17
7
  }
18
- /**
19
- * Error thrown when there is a network error.
20
- */
21
- export declare class FetchError extends Error {
22
- cause: Error;
23
- name: "FetchError";
24
- constructor(cause: Error, msg?: string);
25
- }
26
8
  /**
27
9
  * Error thrown when a required argument was not provided.
28
10
  */
@@ -1,19 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RequiredError = exports.FetchError = exports.TimeoutError = exports.ResponseError = void 0;
4
- /**
5
- * Error thrown when the API returns an error response that can't be parsed to a more specific Error instance.
6
- */
7
- class ResponseError extends Error {
8
- constructor(statusCode, body, headers, msg) {
9
- super(msg);
10
- this.statusCode = statusCode;
11
- this.body = body;
12
- this.headers = headers;
13
- this.name = "ResponseError";
14
- }
15
- }
16
- exports.ResponseError = ResponseError;
3
+ exports.RequiredError = exports.TimeoutError = void 0;
17
4
  /**
18
5
  * Error thrown when the request is aborted due to a timeout.
19
6
  */
@@ -24,17 +11,6 @@ class TimeoutError extends Error {
24
11
  }
25
12
  }
26
13
  exports.TimeoutError = TimeoutError;
27
- /**
28
- * Error thrown when there is a network error.
29
- */
30
- class FetchError extends Error {
31
- constructor(cause, msg) {
32
- super(msg);
33
- this.cause = cause;
34
- this.name = "FetchError";
35
- }
36
- }
37
- exports.FetchError = FetchError;
38
14
  /**
39
15
  * Error thrown when a required argument was not provided.
40
16
  */
@@ -1,10 +1,9 @@
1
- import { Middleware, ClientOptions, FetchParams, RequestContext } from "../runtime.js";
1
+ import { ClientOptions } from "../models.js";
2
2
  /**
3
- * Handles Auth0 client telemetry functionality. Can be used both as middleware
4
- * for automatic header injection and as a standalone utility for manual telemetry header generation.
3
+ * Generates the Auth0-Client telemetry header value.
5
4
  * @private
6
5
  */
7
- export declare class Auth0ClientTelemetry implements Middleware {
6
+ export declare class Auth0ClientTelemetry {
8
7
  clientInfo: {
9
8
  name: string;
10
9
  [key: string]: unknown;
@@ -12,9 +11,6 @@ export declare class Auth0ClientTelemetry implements Middleware {
12
11
  constructor(options: ClientOptions);
13
12
  /**
14
13
  * Get the Auth0-Client header value for telemetry.
15
- * This method can be used when you need to manually add telemetry headers
16
- * instead of using the middleware system.
17
14
  */
18
15
  getAuth0ClientHeader(): string | undefined;
19
- pre?(context: RequestContext): Promise<FetchParams | void>;
20
16
  }
@@ -1,20 +1,10 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.Auth0ClientTelemetry = void 0;
13
4
  const utils_js_1 = require("../../utils.js");
14
5
  const jose_1 = require("jose");
15
6
  /**
16
- * Handles Auth0 client telemetry functionality. Can be used both as middleware
17
- * for automatic header injection and as a standalone utility for manual telemetry header generation.
7
+ * Generates the Auth0-Client telemetry header value.
18
8
  * @private
19
9
  */
20
10
  class Auth0ClientTelemetry {
@@ -23,8 +13,6 @@ class Auth0ClientTelemetry {
23
13
  }
24
14
  /**
25
15
  * Get the Auth0-Client header value for telemetry.
26
- * This method can be used when you need to manually add telemetry headers
27
- * instead of using the middleware system.
28
16
  */
29
17
  getAuth0ClientHeader() {
30
18
  if ("string" === typeof this.clientInfo.name && this.clientInfo.name.length > 0) {
@@ -32,17 +20,5 @@ class Auth0ClientTelemetry {
32
20
  }
33
21
  return undefined;
34
22
  }
35
- pre(context) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- const headerValue = this.getAuth0ClientHeader();
38
- if (headerValue) {
39
- context.init.headers = Object.assign(Object.assign({}, context.init.headers), { "Auth0-Client": headerValue });
40
- }
41
- return {
42
- url: context.url,
43
- init: context.init,
44
- };
45
- });
46
- }
47
23
  }
48
24
  exports.Auth0ClientTelemetry = Auth0ClientTelemetry;
@@ -71,30 +71,6 @@ export interface ApiResponse<T> {
71
71
  status: number;
72
72
  statusText: string;
73
73
  }
74
- export declare class JSONApiResponse<T> implements ApiResponse<T> {
75
- data: T;
76
- headers: Headers;
77
- readonly status: number;
78
- readonly statusText: string;
79
- constructor(data: T, headers: Headers, status: number, statusText: string);
80
- static fromResponse<T = unknown>(raw: Response): Promise<JSONApiResponse<T>>;
81
- }
82
- export declare class VoidApiResponse implements ApiResponse<undefined> {
83
- headers: Headers;
84
- readonly status: number;
85
- readonly statusText: string;
86
- data: undefined;
87
- constructor(headers: Headers, status: number, statusText: string);
88
- static fromResponse(raw: Response): Promise<VoidApiResponse>;
89
- }
90
- export declare class TextApiResponse implements ApiResponse<string> {
91
- data: string;
92
- headers: Headers;
93
- readonly status: number;
94
- readonly statusText: string;
95
- constructor(data: string, headers: Headers, status: number, statusText: string);
96
- static fromResponse(raw: Response): Promise<TextApiResponse>;
97
- }
98
74
  export interface FetchParams {
99
75
  url: string | URL | Request;
100
76
  init: RequestInit;
@@ -1,55 +1,2 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.TextApiResponse = exports.VoidApiResponse = exports.JSONApiResponse = void 0;
13
- class JSONApiResponse {
14
- constructor(data, headers, status, statusText) {
15
- this.data = data;
16
- this.headers = headers;
17
- this.status = status;
18
- this.statusText = statusText;
19
- }
20
- static fromResponse(raw) {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- const value = (yield raw.json());
23
- return new JSONApiResponse(value, raw.headers, raw.status, raw.statusText);
24
- });
25
- }
26
- }
27
- exports.JSONApiResponse = JSONApiResponse;
28
- class VoidApiResponse {
29
- constructor(headers, status, statusText) {
30
- this.headers = headers;
31
- this.status = status;
32
- this.statusText = statusText;
33
- }
34
- static fromResponse(raw) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- return new VoidApiResponse(raw.headers, raw.status, raw.statusText);
37
- });
38
- }
39
- }
40
- exports.VoidApiResponse = VoidApiResponse;
41
- class TextApiResponse {
42
- constructor(data, headers, status, statusText) {
43
- this.data = data;
44
- this.headers = headers;
45
- this.status = status;
46
- this.statusText = statusText;
47
- }
48
- static fromResponse(raw) {
49
- return __awaiter(this, void 0, void 0, function* () {
50
- const value = yield raw.text();
51
- return new TextApiResponse(value, raw.headers, raw.status, raw.statusText);
52
- });
53
- }
54
- }
55
- exports.TextApiResponse = TextApiResponse;
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "6.4.0";
1
+ export declare const SDK_VERSION = "7.0.0";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = "6.4.0";
4
+ exports.SDK_VERSION = "7.0.0";
@@ -15,7 +15,7 @@ export declare namespace ManagementClient {
15
15
  * @group Management API
16
16
  * @public
17
17
  */
18
- interface ManagementClientOptions extends Omit<FernClient.Options, "token" | "environment" | "fetcher" | "baseUrl" | "fetch"> {
18
+ interface ManagementClientOptions extends Omit<FernClient.Options, "token" | "environment" | "fetcher" | "baseUrl"> {
19
19
  /** Auth0 domain (e.g., 'your-tenant.auth0.com') */
20
20
  domain: string;
21
21
  /**
@@ -114,7 +114,14 @@ export declare namespace ManagementClient {
114
114
  clientAssertionSigningKey: string;
115
115
  /** Algorithm for signing the client assertion. Defaults to RS256 */
116
116
  clientAssertionSigningAlg?: string;
117
- /** Enable mTLS for token endpoint calls */
117
+ /**
118
+ * Enable mTLS for token endpoint calls.
119
+ *
120
+ * mTLS (RFC 8705) is a transport-layer concern that is independent of the client
121
+ * authentication method: a client authenticating with `private_key_jwt` can still present a
122
+ * TLS client certificate to obtain a certificate-bound access token. This mirrors v6, which
123
+ * added the `mtls.` endpoint alias from `useMTLS` alone regardless of the auth method.
124
+ */
118
125
  useMTLS?: boolean;
119
126
  }
120
127
  /**
@@ -74,7 +74,6 @@ class ManagementClient extends Client_js_1.ManagementClient {
74
74
  const token = (0, auth_helpers_js_1.createTokenSupplier)(_options);
75
75
  // Temporarily remove fetcher from options to avoid people passing it for now
76
76
  delete _options.fetcher;
77
- delete _options.fetch;
78
77
  // Prepare the base client options
79
78
  let clientOptions = Object.assign(Object.assign({}, _options), { baseUrl,
80
79
  headers,
@@ -1,7 +1,6 @@
1
- import { ManagementClient } from "./ManagementClient.js";
1
+ import type { ManagementClient } from "./ManagementClient.js";
2
2
  export declare class TokenProvider {
3
3
  private readonly options;
4
- private authenticationClient;
5
4
  private expiresAt;
6
5
  private accessToken;
7
6
  private pending;
@@ -12,4 +11,7 @@ export declare class TokenProvider {
12
11
  audience: string;
13
12
  });
14
13
  getAccessToken(): Promise<string>;
14
+ private fetchToken;
15
+ private buildClientAssertion;
16
+ private buildTelemetryHeader;
15
17
  }
@@ -10,31 +10,162 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.TokenProvider = void 0;
13
- const index_js_1 = require("../../auth/index.js");
14
- const LEEWAY = 10 * 1000;
13
+ const jose_1 = require("jose");
14
+ const utils_js_1 = require("../../utils.js");
15
+ const ManagementError_js_1 = require("../errors/ManagementError.js");
16
+ const LEEWAY = 10 * 1000; // 10s refresh-ahead in ms
15
17
  class TokenProvider {
16
18
  constructor(options) {
17
19
  this.options = options;
18
20
  this.expiresAt = 0;
19
21
  this.accessToken = "";
20
- this.authenticationClient = new index_js_1.AuthenticationClient(Object.assign(Object.assign({}, options), { headers: options.headers }));
22
+ // Validate domain: must be a bare hostname, no slashes or query strings.
23
+ if (/[/?#]/.test(options.domain)) {
24
+ throw new Error(`ManagementClient: invalid domain "${options.domain}". Provide a bare hostname, e.g. "tenant.auth0.com".`);
25
+ }
26
+ if (options.useMTLS) {
27
+ const { fetch: customFetch } = options;
28
+ if (!customFetch) {
29
+ throw new Error("ManagementClient: useMTLS requires a custom fetch implementation. " +
30
+ "Provide a `fetch` option configured with your mTLS client certificate.");
31
+ }
32
+ // mTLS (RFC 8705) is a transport-layer concern independent of the client authentication
33
+ // method. It combines with both `clientSecret` and `clientAssertionSigningKey`: the TLS
34
+ // client certificate yields a certificate-bound token regardless of how the client
35
+ // authenticates. v6 supported this, so no auth-method restriction is imposed here.
36
+ }
21
37
  }
22
38
  getAccessToken() {
23
39
  return __awaiter(this, void 0, void 0, function* () {
24
40
  if (!this.accessToken || Date.now() > this.expiresAt - LEEWAY) {
25
- this.pending =
26
- this.pending ||
27
- this.authenticationClient.oauth.clientCredentialsGrant({
28
- audience: this.options.audience,
29
- });
30
- const { data: { access_token: accessToken, expires_in: expiresIn }, } = yield this.pending.finally(() => {
41
+ this.pending = this.pending || this.fetchToken();
42
+ const result = yield this.pending.finally(() => {
31
43
  delete this.pending;
32
44
  });
33
- this.expiresAt = Date.now() + expiresIn * 1000;
34
- this.accessToken = accessToken;
45
+ this.expiresAt = result.expiresAt;
46
+ this.accessToken = result.accessToken;
35
47
  }
36
48
  return this.accessToken;
37
49
  });
38
50
  }
51
+ fetchToken() {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ var _a;
54
+ const { domain, clientId, audience } = this.options;
55
+ const tokenUrl = this.options.useMTLS ? `https://mtls.${domain}/oauth/token` : `https://${domain}/oauth/token`;
56
+ const body = new URLSearchParams({
57
+ grant_type: "client_credentials",
58
+ client_id: clientId,
59
+ audience,
60
+ });
61
+ if ("clientSecret" in this.options) {
62
+ body.set("client_secret", this.options.clientSecret);
63
+ }
64
+ else if ("clientAssertionSigningKey" in this.options) {
65
+ const assertion = yield this.buildClientAssertion(domain, clientId);
66
+ body.set("client_assertion", assertion);
67
+ body.set("client_assertion_type", "urn:ietf:params:oauth:client-assertion-type:jwt-bearer");
68
+ }
69
+ // Build request headers. Start with user-supplied plain-string headers so they can be
70
+ // overridden by SDK-controlled values (Content-Type, Auth0-Client) set below.
71
+ // Supplier-function headers (Fern's Supplier<string | null | undefined> type) are skipped —
72
+ // they require async resolution and are not supported on the token endpoint path.
73
+ const userHeaders = (_a = this.options.headers) !== null && _a !== void 0 ? _a : {};
74
+ const headers = {};
75
+ for (const [key, value] of Object.entries(userHeaders)) {
76
+ if (typeof value === "string") {
77
+ headers[key.toLowerCase()] = value;
78
+ }
79
+ }
80
+ headers["content-type"] = "application/x-www-form-urlencoded";
81
+ const telemetryHeader = this.buildTelemetryHeader();
82
+ if (telemetryHeader) {
83
+ headers["auth0-client"] = telemetryHeader;
84
+ }
85
+ // Use custom fetch for mTLS, else global fetch.
86
+ // `fetch` is defined on BaseClientOptions (src/management/BaseClient.ts) which is Fern-generated.
87
+ // If that file is regenerated, verify `fetch?: typeof fetch` is still present — token acquisition
88
+ // for mTLS depends on it being forwarded here.
89
+ const { fetch: customFetch } = this.options;
90
+ const fetcher = customFetch !== null && customFetch !== void 0 ? customFetch : fetch;
91
+ let response;
92
+ try {
93
+ response = yield fetcher(tokenUrl, {
94
+ method: "POST",
95
+ headers,
96
+ body: body.toString(),
97
+ signal: AbortSignal.timeout(10000),
98
+ });
99
+ }
100
+ catch (err) {
101
+ // Built-in fetch aborts with a "TimeoutError"; node-fetch (used on the mTLS path with a
102
+ // custom fetch) aborts with an "AbortError". Match both so a token-request timeout maps
103
+ // to a 408 regardless of the underlying fetch implementation.
104
+ if (err instanceof Error && (err.name === "TimeoutError" || err.name === "AbortError")) {
105
+ throw new ManagementError_js_1.ManagementError({
106
+ message: "ManagementClient: token request timed out",
107
+ statusCode: 408,
108
+ });
109
+ }
110
+ throw err;
111
+ }
112
+ if (!response.ok) {
113
+ // Read the body exactly once. `response.json()` followed by `response.text()` throws
114
+ // "Body has already been read", which would swallow non-JSON error payloads (e.g. proxy
115
+ // or WAF 502s). Read text, then attempt to parse it as JSON.
116
+ const raw = yield response.text().catch(() => "");
117
+ let errorBody;
118
+ try {
119
+ errorBody = raw ? JSON.parse(raw) : response.statusText;
120
+ }
121
+ catch (_b) {
122
+ errorBody = raw || response.statusText;
123
+ }
124
+ throw new ManagementError_js_1.ManagementError({
125
+ message: "ManagementClient: token request failed",
126
+ statusCode: response.status,
127
+ body: errorBody,
128
+ });
129
+ }
130
+ const json = (yield response.json());
131
+ return {
132
+ accessToken: json.access_token,
133
+ expiresAt: Date.now() + json.expires_in * 1000,
134
+ };
135
+ });
136
+ }
137
+ buildClientAssertion(domain, clientId) {
138
+ return __awaiter(this, void 0, void 0, function* () {
139
+ const { clientAssertionSigningKey, clientAssertionSigningAlg = "RS256" } = this
140
+ .options;
141
+ const key = yield (0, jose_1.importPKCS8)(clientAssertionSigningKey, clientAssertionSigningAlg);
142
+ const now = Math.floor(Date.now() / 1000);
143
+ return new jose_1.SignJWT({})
144
+ .setProtectedHeader({ alg: clientAssertionSigningAlg })
145
+ .setIssuedAt(now)
146
+ .setIssuer(clientId)
147
+ .setSubject(clientId)
148
+ .setAudience(`https://${domain}/`)
149
+ .setExpirationTime(now + 180) // 3 min lifetime
150
+ .setJti(crypto.randomUUID())
151
+ .sign(key);
152
+ });
153
+ }
154
+ buildTelemetryHeader() {
155
+ var _a;
156
+ const opts = this.options;
157
+ if (opts.telemetry === false)
158
+ return null;
159
+ const nodeAuth0Info = (0, utils_js_1.generateClientInfo)();
160
+ const info = opts.clientInfo
161
+ ? { name: opts.clientInfo.name, version: String((_a = opts.clientInfo.version) !== null && _a !== void 0 ? _a : nodeAuth0Info.version) }
162
+ : { name: nodeAuth0Info.name, version: nodeAuth0Info.version };
163
+ // NOTE: auth0-auth-js TelemetryConfig does not support env fields.
164
+ // The runtime fingerprint (env.node / env.cloudflare-workers) present in the
165
+ // original node-auth0 Auth0-Client header is intentionally omitted here.
166
+ // This is a known, accepted delta vs the pre-v7 token request telemetry shape.
167
+ // Use jose's base64url encoder for runtime portability (Buffer is Node-only).
168
+ return jose_1.base64url.encode(new TextEncoder().encode(JSON.stringify(info)));
169
+ }
39
170
  }
40
171
  exports.TokenProvider = TokenProvider;
@@ -5,21 +5,3 @@ export declare const generateClientInfo: () => {
5
5
  [x: string]: string;
6
6
  };
7
7
  };
8
- /**
9
- * @private
10
- */
11
- export declare const mtlsPrefix = "mtls";
12
- type SyncGetter<T> = () => T;
13
- type AsyncGetter<T> = () => Promise<T>;
14
- /**
15
- * Resolves a value that can be a static value, a synchronous function, or an asynchronous function.
16
- *
17
- * @template T - The type of the value to be resolved.
18
- * @param {T | SyncGetter<T> | AsyncGetter<T>} value - The value to be resolved. It can be:
19
- * - A static value of type T.
20
- * - A synchronous function that returns a value of type T.
21
- * - An asynchronous function that returns a Promise of type T.
22
- * @returns {Promise<T>} A promise that resolves to the value of type T.
23
- */
24
- export declare const resolveValueToPromise: <T>(value: T | SyncGetter<T> | AsyncGetter<T>) => Promise<T>;
25
- export {};
package/dist/cjs/utils.js CHANGED
@@ -1,15 +1,6 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.resolveValueToPromise = exports.mtlsPrefix = exports.generateClientInfo = void 0;
3
+ exports.generateClientInfo = void 0;
13
4
  const version_js_1 = require("./management/version.js");
14
5
  const index_js_1 = require("./management/core/index.js");
15
6
  const generateClientInfo = () => {
@@ -26,25 +17,3 @@ const generateClientInfo = () => {
26
17
  };
27
18
  };
28
19
  exports.generateClientInfo = generateClientInfo;
29
- /**
30
- * @private
31
- */
32
- exports.mtlsPrefix = "mtls";
33
- /**
34
- * Resolves a value that can be a static value, a synchronous function, or an asynchronous function.
35
- *
36
- * @template T - The type of the value to be resolved.
37
- * @param {T | SyncGetter<T> | AsyncGetter<T>} value - The value to be resolved. It can be:
38
- * - A static value of type T.
39
- * - A synchronous function that returns a value of type T.
40
- * - An asynchronous function that returns a Promise of type T.
41
- * @returns {Promise<T>} A promise that resolves to the value of type T.
42
- */
43
- const resolveValueToPromise = (value) => __awaiter(void 0, void 0, void 0, function* () {
44
- if (typeof value === "function") {
45
- const result = value(); // Call the function
46
- return result instanceof Promise ? result : Promise.resolve(result); // Handle sync/async
47
- }
48
- return Promise.resolve(value); // Static value
49
- });
50
- exports.resolveValueToPromise = resolveValueToPromise;
@@ -1,6 +1,4 @@
1
1
  export * from "./management/index.mjs";
2
- export * from "./auth/index.mjs";
3
- export * from "./userinfo/index.mjs";
4
2
  export * from "./lib/errors.mjs";
5
3
  export * from "./lib/models.mjs";
6
4
  export * from "./lib/httpResponseHeadersUtils.mjs";
@@ -1,6 +1,4 @@
1
1
  export * from "./management/index.mjs";
2
- export * from "./auth/index.mjs";
3
- export * from "./userinfo/index.mjs";
4
2
  export * from "./lib/errors.mjs";
5
3
  export * from "./lib/models.mjs";
6
4
  export * from "./lib/httpResponseHeadersUtils.mjs";