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
@@ -1,166 +0,0 @@
1
- import { BaseAuthAPI } from "./base-auth-api.mjs";
2
- /**
3
- * Represents the configuration options required for initiating a Custom Token Exchange request
4
- * following RFC 8693 specifications.
5
- *
6
- * @see {@link https://www.rfc-editor.org/rfc/rfc8693 | RFC 8693: OAuth 2.0 Token Exchange}
7
- */
8
- export type CustomTokenExchangeOptions = {
9
- /**
10
- * The type identifier for the subject token being exchanged
11
- *
12
- * @pattern
13
- * - Must be a namespaced URI under your organization's control
14
- * - Forbidden patterns:
15
- * - `^urn:ietf:params:oauth:*` (IETF reserved)
16
- * - `^https:\/\/auth0\.com/*` (Auth0 reserved)
17
- * - `^urn:auth0:*` (Auth0 reserved)
18
- *
19
- * @example
20
- * "urn:acme:legacy-system-token"
21
- * "https://api.yourcompany.com/token-type/v1"
22
- */
23
- subject_token_type: string;
24
- /**
25
- * The opaque token value being exchanged for Auth0 tokens
26
- *
27
- * @security
28
- * - Must be validated in Auth0 Actions using strong cryptographic verification
29
- * - Implement replay attack protection
30
- * - Recommended validation libraries: `jose`, `jsonwebtoken`
31
- *
32
- * @example
33
- * "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
34
- */
35
- subject_token: string;
36
- /**
37
- * The target audience for the requested Auth0 token
38
- *
39
- * @remarks
40
- * Must match exactly with an API identifier configured in your Auth0 tenant
41
- *
42
- * @example
43
- * "https://api.your-service.com/v1"
44
- */
45
- audience: string;
46
- /**
47
- * Space-separated list of OAuth 2.0 scopes being requested
48
- *
49
- * @remarks
50
- * Subject to API authorization policies configured in Auth0
51
- *
52
- * @example
53
- * "openid profile email read:data write:data"
54
- */
55
- scope?: string;
56
- /**
57
- * Additional custom parameters for Auth0 Action processing
58
- *
59
- * @remarks
60
- * Accessible in Action code via `event.request.body`
61
- *
62
- * @example
63
- * ```typescript
64
- * {
65
- * custom_parameter: "session_context",
66
- * device_fingerprint: "a3d8f7...",
67
- * }
68
- * ```
69
- */
70
- [key: string]: unknown;
71
- };
72
- /**
73
- * Interface defining Custom Token Exchange operations
74
- *
75
- * @see {@link https://auth0.com/docs/authenticate/protocols/custom-token-exchange | Auth0 Custom Token Exchange Docs}
76
- */
77
- export interface ICustomTokenExchange {
78
- /**
79
- * Executes RFC 8693-compliant token exchange flow
80
- *
81
- * @throws {Auth0Error} For structured error responses
82
- * @throws {Error} For generic errors with these codes:
83
- * - `invalid_request`: Invalid parameters
84
- * - `consent_required`: Enable "Allow Skipping User Consent" in API settings
85
- * - `too_many_attempts`: Suspicious IP throttling triggered
86
- *
87
- * @example
88
- * ```typescript
89
- * // External IdP migration scenario
90
- * const tokens = await auth0.customTokenExchange.exchangeToken({
91
- * subject_token_type: 'urn:external-idp:legacy',
92
- * subject_token: externalIdPToken,
93
- * audience: 'https://api.your-service.com',
94
- * scope: 'openid profile'
95
- * });
96
- * ```
97
- */
98
- exchangeToken(options: CustomTokenExchangeOptions): Promise<TokenResponse>;
99
- }
100
- /**
101
- * Implements Auth0's Custom Token Exchange functionality with security best practices
102
- *
103
- * @security
104
- * - **HTTPS Enforcement**: All requests require TLS encryption
105
- * - **Credential Protection**: Client secrets never exposed in browser contexts
106
- * - **Input Validation**: Strict namespace enforcement for token types
107
- *
108
- * @example
109
- * ```typescript
110
- * // Secure token validation in Auth0 Action
111
- * exports.onExecuteCustomTokenExchange = async (event, api) => {
112
- * const { jws } = require('jose');
113
- * const { createRemoteJWKSet } = require('jose/jwks');
114
- *
115
- * const JWKS = createRemoteJWKSet(new URL('https://external-idp.com/.well-known/jwks.json'));
116
- *
117
- * try {
118
- * const { payload } = await jws.verify(event.transaction.subject_token, JWKS);
119
- * api.authentication.setUserById(payload.sub);
120
- * } catch (error) {
121
- * api.access.rejectInvalidSubjectToken('Invalid token signature');
122
- * }
123
- * };
124
- * ```
125
- */
126
- export declare class CustomTokenExchange extends BaseAuthAPI implements ICustomTokenExchange {
127
- /**
128
- * Executes token exchange flow with security validations
129
- *
130
- * @param options - Exchange configuration parameters
131
- * @returns Auth0-issued tokens with requested claims
132
- *
133
- * @throws {Error} When:
134
- * - `subject_token_type` uses prohibited namespace
135
- * - Network failures occur
136
- * - Auth0 returns error responses (4xx/5xx)
137
- */
138
- exchangeToken(options: CustomTokenExchangeOptions): Promise<TokenResponse>;
139
- }
140
- /**
141
- * Standardized token response structure for Auth0 authentication flows
142
- *
143
- * @remarks
144
- * **Token Lifetime Management**:
145
- * - Cache tokens according to `expires_in` value
146
- * - Rotate refresh tokens using `offline_access` scope
147
- * - Revoke compromised tokens immediately
148
- *
149
- * @security
150
- * - Store tokens in secure, encrypted storage
151
- * - Never expose in client-side code or logs
152
- */
153
- export type TokenResponse = {
154
- /** Bearer token for API authorization */
155
- access_token: string;
156
- /** Refresh token (requires `offline_access` scope) */
157
- refresh_token?: string;
158
- /** JWT containing user identity claims */
159
- id_token: string;
160
- /** Typically "Bearer" */
161
- token_type?: string;
162
- /** Token validity in seconds (default: 86400) */
163
- expires_in: number;
164
- /** Granted permissions space */
165
- scope: string;
166
- };
@@ -1,70 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { JSONApiResponse } from "../lib/models.mjs";
11
- import { BaseAuthAPI } from "./base-auth-api.mjs";
12
- /** RFC 8693-defined grant type for token exchange */
13
- const TOKEN_EXCHANGE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:token-exchange";
14
- /** Auth0 token endpoint path */
15
- const TOKEN_URL = "/oauth/token";
16
- /**
17
- * Implements Auth0's Custom Token Exchange functionality with security best practices
18
- *
19
- * @security
20
- * - **HTTPS Enforcement**: All requests require TLS encryption
21
- * - **Credential Protection**: Client secrets never exposed in browser contexts
22
- * - **Input Validation**: Strict namespace enforcement for token types
23
- *
24
- * @example
25
- * ```typescript
26
- * // Secure token validation in Auth0 Action
27
- * exports.onExecuteCustomTokenExchange = async (event, api) => {
28
- * const { jws } = require('jose');
29
- * const { createRemoteJWKSet } = require('jose/jwks');
30
- *
31
- * const JWKS = createRemoteJWKSet(new URL('https://external-idp.com/.well-known/jwks.json'));
32
- *
33
- * try {
34
- * const { payload } = await jws.verify(event.transaction.subject_token, JWKS);
35
- * api.authentication.setUserById(payload.sub);
36
- * } catch (error) {
37
- * api.access.rejectInvalidSubjectToken('Invalid token signature');
38
- * }
39
- * };
40
- * ```
41
- */
42
- export class CustomTokenExchange extends BaseAuthAPI {
43
- /**
44
- * Executes token exchange flow with security validations
45
- *
46
- * @param options - Exchange configuration parameters
47
- * @returns Auth0-issued tokens with requested claims
48
- *
49
- * @throws {Error} When:
50
- * - `subject_token_type` uses prohibited namespace
51
- * - Network failures occur
52
- * - Auth0 returns error responses (4xx/5xx)
53
- */
54
- exchangeToken(options) {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- const body = Object.assign(Object.assign({}, options), { grant_type: TOKEN_EXCHANGE_GRANT_TYPE, client_id: this.clientId });
57
- yield this.addClientAuthentication(body);
58
- const response = yield this.request({
59
- path: TOKEN_URL,
60
- method: "POST",
61
- headers: {
62
- "Content-Type": "application/x-www-form-urlencoded",
63
- },
64
- body: new URLSearchParams(body),
65
- }, {});
66
- const r = yield JSONApiResponse.fromResponse(response);
67
- return r.data;
68
- });
69
- }
70
- }
@@ -1,3 +0,0 @@
1
- export * from "./errors.mjs";
2
- export * from "./models.mjs";
3
- export { RetryConfiguration } from "./retry.mjs";
@@ -1,2 +0,0 @@
1
- export * from "./errors.mjs";
2
- export * from "./models.mjs";
@@ -1,61 +0,0 @@
1
- import { RequestOpts, InitOverrideFunction, Configuration } from "./models.mjs";
2
- export * from "./models.mjs";
3
- /**
4
- * @private
5
- * This is the base class for all generated API classes.
6
- */
7
- export declare class BaseAPI {
8
- protected configuration: Configuration;
9
- private middleware;
10
- private fetchApi;
11
- private parseError;
12
- private timeoutDuration;
13
- constructor(configuration: Configuration);
14
- protected request(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction): Promise<Response>;
15
- private createFetchParams;
16
- private fetchWithTimeout;
17
- private fetch;
18
- }
19
- /**
20
- * @private
21
- */
22
- export declare const COLLECTION_FORMATS: {
23
- csv: string;
24
- ssv: string;
25
- tsv: string;
26
- pipes: string;
27
- };
28
- /**
29
- * @private
30
- */
31
- export type ModelPropertyNaming = "camelCase" | "snake_case" | "PascalCase" | "original";
32
- /**
33
- * @private
34
- */
35
- export interface Consume {
36
- contentType: string;
37
- }
38
- /**
39
- * @private
40
- */
41
- export declare function validateRequiredRequestParams<TRequestParams extends {
42
- [key: string]: any;
43
- }>(requestParameters: TRequestParams, keys: Array<Extract<keyof TRequestParams, string>>): void;
44
- type QueryParamConfig = {
45
- isArray?: boolean;
46
- isCollectionFormatMulti?: boolean;
47
- collectionFormat?: keyof typeof COLLECTION_FORMATS;
48
- };
49
- /**
50
- * @private
51
- */
52
- export declare function applyQueryParams<TRequestParams extends {
53
- [key: string]: any;
54
- }, Key extends Extract<keyof TRequestParams, string>>(requestParameters: TRequestParams, keys: Array<{
55
- key: Key;
56
- config: QueryParamConfig;
57
- }>): Pick<TRequestParams, ReadonlyArray<Key>[number]>;
58
- /**
59
- * @private
60
- */
61
- export declare function parseFormParam(originalValue: number | boolean | string | Blob): Promise<string | Blob>;
@@ -1,201 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { retry } from "./retry.mjs";
11
- import { FetchError, RequiredError, TimeoutError } from "./errors.mjs";
12
- export * from "./models.mjs";
13
- /**
14
- * @private
15
- * This is the base class for all generated API classes.
16
- */
17
- export class BaseAPI {
18
- constructor(configuration) {
19
- this.configuration = configuration;
20
- this.fetchWithTimeout = (url, init) => __awaiter(this, void 0, void 0, function* () {
21
- const controller = new AbortController();
22
- const timeout = setTimeout(() => {
23
- controller.abort();
24
- }, this.timeoutDuration);
25
- try {
26
- return yield this.fetchApi(url, Object.assign({ signal: controller.signal }, init));
27
- }
28
- catch (e) {
29
- if (e.name === "AbortError") {
30
- throw new TimeoutError();
31
- }
32
- throw e;
33
- }
34
- finally {
35
- clearTimeout(timeout);
36
- }
37
- });
38
- this.fetch = (url, init) => __awaiter(this, void 0, void 0, function* () {
39
- var _a;
40
- let fetchParams = { url, init };
41
- for (const middleware of this.middleware) {
42
- if (middleware.pre) {
43
- fetchParams =
44
- (yield middleware.pre(Object.assign({ fetch: this.fetchWithTimeout }, fetchParams))) || fetchParams;
45
- }
46
- }
47
- let response = undefined;
48
- let error = undefined;
49
- try {
50
- response =
51
- ((_a = this.configuration.retry) === null || _a === void 0 ? void 0 : _a.enabled) !== false
52
- ? yield retry(() => this.fetchWithTimeout(fetchParams.url, fetchParams.init), Object.assign({}, this.configuration.retry))
53
- : yield this.fetchWithTimeout(fetchParams.url, fetchParams.init);
54
- }
55
- catch (e) {
56
- error = e;
57
- }
58
- if (error || !response.ok) {
59
- for (const middleware of this.middleware) {
60
- if (middleware.onError) {
61
- response =
62
- (yield middleware.onError(Object.assign(Object.assign({ fetch: this.fetchWithTimeout }, fetchParams), { error, response: response ? response.clone() : undefined }))) || response;
63
- }
64
- }
65
- if (response === undefined) {
66
- throw new FetchError(error, "The request failed and the interceptors did not return an alternative response");
67
- }
68
- }
69
- else {
70
- for (const middleware of this.middleware) {
71
- if (middleware.post) {
72
- response =
73
- (yield middleware.post(Object.assign(Object.assign({ fetch: this.fetchApi }, fetchParams), { response: response.clone() }))) || response;
74
- }
75
- }
76
- }
77
- return response;
78
- });
79
- if (configuration.baseUrl === null || configuration.baseUrl === undefined) {
80
- throw new Error("Must provide a base URL for the API");
81
- }
82
- if ("string" !== typeof configuration.baseUrl || configuration.baseUrl.length === 0) {
83
- throw new Error("The provided base URL is invalid");
84
- }
85
- this.middleware = configuration.middleware || [];
86
- this.fetchApi = configuration.fetch || globalThis.fetch.bind(globalThis);
87
- this.parseError = configuration.parseError;
88
- this.timeoutDuration =
89
- typeof configuration.timeoutDuration === "number" ? configuration.timeoutDuration : 10000;
90
- }
91
- request(context, initOverrides) {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- const { url, init } = yield this.createFetchParams(context, initOverrides);
94
- const response = yield this.fetch(url, init);
95
- if (response && response.status >= 200 && response.status < 300) {
96
- return response;
97
- }
98
- const error = yield this.parseError(response);
99
- throw error;
100
- });
101
- }
102
- createFetchParams(context, initOverrides) {
103
- return __awaiter(this, void 0, void 0, function* () {
104
- let url = this.configuration.baseUrl + context.path;
105
- if (context.query !== undefined && Object.keys(context.query).length !== 0) {
106
- // only add the querystring to the URL if there are query parameters.
107
- // this is done to avoid urls ending with a "?" character which buggy webservers
108
- // do not handle correctly sometimes.
109
- url += `?${querystring(context.query)}`;
110
- }
111
- const headers = Object.assign({}, this.configuration.headers, context.headers);
112
- Object.keys(headers).forEach((key) => (headers[key] === undefined ? delete headers[key] : {}));
113
- const initOverrideFn = typeof initOverrides === "function" ? initOverrides : () => __awaiter(this, void 0, void 0, function* () { return initOverrides; });
114
- const initParams = {
115
- method: context.method,
116
- headers,
117
- body: context.body,
118
- dispatcher: this.configuration.agent,
119
- };
120
- const overriddenInit = Object.assign(Object.assign({}, initParams), (yield initOverrideFn({
121
- init: initParams,
122
- context,
123
- })));
124
- const init = Object.assign(Object.assign({}, overriddenInit), { body: overriddenInit.body instanceof FormData ||
125
- overriddenInit.body instanceof URLSearchParams ||
126
- overriddenInit.body instanceof Blob
127
- ? overriddenInit.body
128
- : JSON.stringify(overriddenInit.body) });
129
- return { url, init };
130
- });
131
- }
132
- }
133
- /**
134
- * @private
135
- */
136
- export const COLLECTION_FORMATS = {
137
- csv: ",",
138
- ssv: " ",
139
- tsv: "\t",
140
- pipes: "|",
141
- };
142
- /**
143
- * @private
144
- */
145
- function querystring(params) {
146
- return Object.keys(params)
147
- .map((key) => querystringSingleKey(key, params[key]))
148
- .filter((part) => part.length > 0)
149
- .join("&");
150
- }
151
- function querystringSingleKey(key, value) {
152
- if (value instanceof Array) {
153
- const multiValue = value
154
- .map((singleValue) => encodeURIComponent(String(singleValue)))
155
- .join(`&${encodeURIComponent(key)}=`);
156
- return `${encodeURIComponent(key)}=${multiValue}`;
157
- }
158
- return `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`;
159
- }
160
- /**
161
- * @private
162
- */
163
- export function validateRequiredRequestParams(requestParameters, keys) {
164
- keys.forEach((key) => {
165
- if (requestParameters[key] === null || requestParameters[key] === undefined) {
166
- throw new RequiredError(key, `Required parameter requestParameters.${key} was null or undefined.`);
167
- }
168
- });
169
- }
170
- /**
171
- * @private
172
- */
173
- export function applyQueryParams(requestParameters, keys) {
174
- return keys.reduce((acc, { key, config, }) => {
175
- let value;
176
- if (config.isArray) {
177
- if (config.isCollectionFormatMulti) {
178
- value = requestParameters[key];
179
- }
180
- else {
181
- value = requestParameters[key].join(COLLECTION_FORMATS[config.collectionFormat]);
182
- }
183
- }
184
- else {
185
- if (requestParameters[key] !== undefined) {
186
- value = requestParameters[key];
187
- }
188
- }
189
- return value !== undefined ? Object.assign(Object.assign({}, acc), { [key]: value }) : acc;
190
- }, {});
191
- }
192
- /**
193
- * @private
194
- */
195
- export function parseFormParam(originalValue) {
196
- return __awaiter(this, void 0, void 0, function* () {
197
- let value = originalValue;
198
- value = typeof value == "number" || typeof value == "boolean" ? "" + value : value;
199
- return value;
200
- });
201
- }
@@ -1,87 +0,0 @@
1
- import { ResponseError } from "../lib/errors.mjs";
2
- import { ClientOptions, InitOverride, JSONApiResponse } from "../lib/models.mjs";
3
- import { BaseAPI } from "../lib/runtime.mjs";
4
- /**
5
- * Response interface for the UserInfo endpoint
6
- * @group UserInfo API
7
- */
8
- export interface UserInfoResponse {
9
- sub: string;
10
- name: string;
11
- given_name?: string;
12
- family_name?: string;
13
- middle_name?: string;
14
- nickname: string;
15
- preferred_username?: string;
16
- profile?: string;
17
- picture?: string;
18
- website?: string;
19
- email: string;
20
- email_verified: boolean;
21
- gender?: string;
22
- birthdate?: string;
23
- zoneinfo?: string;
24
- locale?: string;
25
- phone_number?: string;
26
- phone_number_verified?: string;
27
- address?: {
28
- country?: string;
29
- };
30
- updated_at: string;
31
- [key: string]: unknown;
32
- }
33
- export declare class UserInfoError extends Error {
34
- error: string;
35
- error_description: string;
36
- statusCode: number;
37
- body: string;
38
- headers: Headers;
39
- name: "UserInfoError";
40
- constructor(error: string, error_description: string, statusCode: number, body: string, headers: Headers);
41
- }
42
- export declare function parseError(response: Response): Promise<ResponseError | UserInfoError>;
43
- /**
44
- * Auth0 UserInfo API Client
45
- *
46
- * Provides access to the UserInfo endpoint to retrieve user profile information
47
- * using an access token obtained during authentication.
48
- *
49
- * @group UserInfo API
50
- *
51
- * @example Basic usage
52
- * ```typescript
53
- * import { UserInfoClient } from 'auth0';
54
- *
55
- * const userInfoClient = new UserInfoClient({
56
- * domain: 'your-tenant.auth0.com'
57
- * });
58
- *
59
- * const userInfo = await userInfoClient.getUserInfo(accessToken);
60
- * console.log(userInfo.data.sub, userInfo.data.email);
61
- * ```
62
- */
63
- export declare class UserInfoClient extends BaseAPI {
64
- /**
65
- * Create a new UserInfo API client
66
- * @param options - Configuration options including domain and client settings
67
- */
68
- constructor(options: {
69
- domain: string;
70
- } & ClientOptions);
71
- /**
72
- * Given an access token get the user profile linked to it.
73
- *
74
- * @example <caption>
75
- * Get the user information based on the Auth0 access token (obtained during
76
- * login). Find more information in the
77
- * <a href="https://auth0.com/docs/auth-api#!#get--userinfo">API Docs</a>.
78
- * </caption>
79
- *
80
- * const userInfoClient = new UserInfoClient({
81
- * domain: '...'
82
- * });
83
-
84
- * const userInfo = await userInfoClient.getUserInfo(accessToken);
85
- */
86
- getUserInfo(accessToken: string, initOverrides?: InitOverride): Promise<JSONApiResponse<UserInfoResponse>>;
87
- }
@@ -1,98 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { ResponseError } from "../lib/errors.mjs";
11
- import { Auth0ClientTelemetry } from "../lib/middleware/auth0-client-telemetry.mjs";
12
- import { JSONApiResponse } from "../lib/models.mjs";
13
- import { BaseAPI } from "../lib/runtime.mjs";
14
- export class UserInfoError extends Error {
15
- constructor(error, error_description, statusCode, body, headers) {
16
- super(error_description || error);
17
- this.error = error;
18
- this.error_description = error_description;
19
- this.statusCode = statusCode;
20
- this.body = body;
21
- this.headers = headers;
22
- this.name = "UserInfoError";
23
- }
24
- }
25
- export function parseError(response) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- // Errors typically have a specific format:
28
- // {
29
- // error: 'invalid_body',
30
- // error_description: 'Bad Request',
31
- // }
32
- const body = yield response.text();
33
- let data;
34
- try {
35
- data = JSON.parse(body);
36
- return new UserInfoError(data.error, data.error_description, response.status, body, response.headers);
37
- }
38
- catch (_a) {
39
- return new ResponseError(response.status, body, response.headers, "Response returned an error code");
40
- }
41
- });
42
- }
43
- /**
44
- * Auth0 UserInfo API Client
45
- *
46
- * Provides access to the UserInfo endpoint to retrieve user profile information
47
- * using an access token obtained during authentication.
48
- *
49
- * @group UserInfo API
50
- *
51
- * @example Basic usage
52
- * ```typescript
53
- * import { UserInfoClient } from 'auth0';
54
- *
55
- * const userInfoClient = new UserInfoClient({
56
- * domain: 'your-tenant.auth0.com'
57
- * });
58
- *
59
- * const userInfo = await userInfoClient.getUserInfo(accessToken);
60
- * console.log(userInfo.data.sub, userInfo.data.email);
61
- * ```
62
- */
63
- export class UserInfoClient extends BaseAPI {
64
- /**
65
- * Create a new UserInfo API client
66
- * @param options - Configuration options including domain and client settings
67
- */
68
- constructor(options) {
69
- super(Object.assign(Object.assign({}, options), { baseUrl: `https://${options.domain}`, middleware: options.telemetry !== false ? [new Auth0ClientTelemetry(options)] : [], parseError }));
70
- }
71
- /**
72
- * Given an access token get the user profile linked to it.
73
- *
74
- * @example <caption>
75
- * Get the user information based on the Auth0 access token (obtained during
76
- * login). Find more information in the
77
- * <a href="https://auth0.com/docs/auth-api#!#get--userinfo">API Docs</a>.
78
- * </caption>
79
- *
80
- * const userInfoClient = new UserInfoClient({
81
- * domain: '...'
82
- * });
83
-
84
- * const userInfo = await userInfoClient.getUserInfo(accessToken);
85
- */
86
- getUserInfo(accessToken, initOverrides) {
87
- return __awaiter(this, void 0, void 0, function* () {
88
- const response = yield this.request({
89
- path: `/userinfo`,
90
- method: "GET",
91
- headers: {
92
- Authorization: `Bearer ${accessToken}`,
93
- },
94
- }, initOverrides);
95
- return JSONApiResponse.fromResponse(response);
96
- });
97
- }
98
- }