auth0 6.3.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 (160) 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/Client.d.ts +3 -0
  11. package/dist/cjs/management/Client.js +45 -40
  12. package/dist/cjs/management/api/errors/UnprocessableEntityError.d.ts +5 -0
  13. package/dist/cjs/management/api/errors/UnprocessableEntityError.js +54 -0
  14. package/dist/cjs/management/api/errors/index.d.ts +1 -0
  15. package/dist/cjs/management/api/errors/index.js +1 -0
  16. package/dist/cjs/management/api/requests/requests.d.ts +91 -0
  17. package/dist/cjs/management/api/resources/connections/client/Client.d.ts +2 -0
  18. package/dist/cjs/management/api/resources/connections/client/Client.js +6 -0
  19. package/dist/cjs/management/api/resources/connections/resources/scimConfiguration/client/Client.d.ts +1 -0
  20. package/dist/cjs/management/api/resources/connections/resources/scimConfiguration/client/Client.js +3 -0
  21. package/dist/cjs/management/api/resources/index.d.ts +1 -0
  22. package/dist/cjs/management/api/resources/index.js +2 -1
  23. package/dist/cjs/management/api/resources/keys/resources/networkAcls/client/Client.d.ts +17 -0
  24. package/dist/cjs/management/api/resources/keys/resources/networkAcls/client/Client.js +60 -0
  25. package/dist/cjs/management/api/resources/organizationTemplates/client/Client.d.ts +106 -0
  26. package/dist/cjs/management/api/resources/organizationTemplates/client/Client.js +411 -0
  27. package/dist/cjs/management/api/resources/organizationTemplates/client/index.d.ts +1 -0
  28. package/dist/cjs/management/api/resources/organizationTemplates/client/index.js +2 -0
  29. package/dist/cjs/management/api/resources/organizationTemplates/exports.d.ts +2 -0
  30. package/dist/cjs/management/api/resources/organizationTemplates/exports.js +21 -0
  31. package/dist/cjs/management/api/resources/organizationTemplates/index.d.ts +1 -0
  32. package/dist/cjs/{lib → management/api/resources/organizationTemplates}/index.js +1 -2
  33. package/dist/cjs/management/api/resources/organizations/client/Client.d.ts +3 -0
  34. package/dist/cjs/management/api/resources/organizations/client/Client.js +7 -2
  35. package/dist/cjs/management/api/resources/organizations/resources/index.d.ts +1 -0
  36. package/dist/cjs/management/api/resources/organizations/resources/index.js +2 -1
  37. package/dist/cjs/management/api/resources/organizations/resources/organizationTemplate/client/Client.d.ts +63 -0
  38. package/dist/cjs/management/api/resources/organizations/resources/organizationTemplate/client/Client.js +232 -0
  39. package/dist/cjs/management/api/resources/organizations/resources/organizationTemplate/client/index.d.ts +1 -0
  40. package/dist/cjs/management/api/resources/organizations/resources/organizationTemplate/client/index.js +2 -0
  41. package/dist/cjs/management/api/resources/organizations/resources/organizationTemplate/exports.d.ts +2 -0
  42. package/dist/cjs/management/api/resources/organizations/resources/organizationTemplate/exports.js +21 -0
  43. package/dist/cjs/management/api/resources/organizations/resources/organizationTemplate/index.d.ts +1 -0
  44. package/dist/cjs/management/api/resources/organizations/resources/organizationTemplate/index.js +17 -0
  45. package/dist/cjs/management/api/resources/users/resources/organizations/client/Client.d.ts +17 -0
  46. package/dist/cjs/management/api/resources/users/resources/organizations/client/Client.js +19 -0
  47. package/dist/cjs/management/api/types/types.d.ts +8896 -2027
  48. package/dist/cjs/management/api/types/types.js +1455 -166
  49. package/dist/cjs/management/version.d.ts +1 -1
  50. package/dist/cjs/management/version.js +1 -1
  51. package/dist/cjs/management/wrapper/ManagementClient.d.ts +9 -2
  52. package/dist/cjs/management/wrapper/ManagementClient.js +0 -1
  53. package/dist/cjs/management/wrapper/token-provider.d.ts +4 -2
  54. package/dist/cjs/management/wrapper/token-provider.js +142 -11
  55. package/dist/cjs/utils.d.ts +0 -18
  56. package/dist/cjs/utils.js +1 -32
  57. package/dist/esm/index.d.mts +0 -2
  58. package/dist/esm/index.mjs +0 -2
  59. package/dist/esm/lib/errors.d.mts +0 -18
  60. package/dist/esm/lib/errors.mjs +0 -22
  61. package/dist/esm/lib/middleware/auth0-client-telemetry.d.mts +3 -7
  62. package/dist/esm/lib/middleware/auth0-client-telemetry.mjs +1 -25
  63. package/dist/esm/lib/models.d.mts +0 -24
  64. package/dist/esm/lib/models.mjs +1 -49
  65. package/dist/esm/management/Client.d.mts +3 -0
  66. package/dist/esm/management/Client.mjs +5 -0
  67. package/dist/esm/management/api/errors/UnprocessableEntityError.d.mts +5 -0
  68. package/dist/esm/management/api/errors/UnprocessableEntityError.mjs +17 -0
  69. package/dist/esm/management/api/errors/index.d.mts +1 -0
  70. package/dist/esm/management/api/errors/index.mjs +1 -0
  71. package/dist/esm/management/api/requests/requests.d.mts +91 -0
  72. package/dist/esm/management/api/resources/connections/client/Client.d.mts +2 -0
  73. package/dist/esm/management/api/resources/connections/client/Client.mjs +6 -0
  74. package/dist/esm/management/api/resources/connections/resources/scimConfiguration/client/Client.d.mts +1 -0
  75. package/dist/esm/management/api/resources/connections/resources/scimConfiguration/client/Client.mjs +3 -0
  76. package/dist/esm/management/api/resources/index.d.mts +1 -0
  77. package/dist/esm/management/api/resources/index.mjs +1 -0
  78. package/dist/esm/management/api/resources/keys/resources/networkAcls/client/Client.d.mts +17 -0
  79. package/dist/esm/management/api/resources/keys/resources/networkAcls/client/Client.mjs +60 -0
  80. package/dist/esm/management/api/resources/organizationTemplates/client/Client.d.mts +106 -0
  81. package/dist/esm/management/api/resources/organizationTemplates/client/Client.mjs +374 -0
  82. package/dist/esm/management/api/resources/organizationTemplates/client/index.d.mts +1 -0
  83. package/dist/esm/management/api/resources/organizationTemplates/client/index.mjs +1 -0
  84. package/dist/esm/management/api/resources/organizationTemplates/exports.d.mts +2 -0
  85. package/dist/esm/management/api/resources/organizationTemplates/exports.mjs +3 -0
  86. package/dist/esm/management/api/resources/organizationTemplates/index.d.mts +1 -0
  87. package/dist/esm/management/api/resources/organizationTemplates/index.mjs +1 -0
  88. package/dist/esm/management/api/resources/organizations/client/Client.d.mts +3 -0
  89. package/dist/esm/management/api/resources/organizations/client/Client.mjs +5 -0
  90. package/dist/esm/management/api/resources/organizations/resources/index.d.mts +1 -0
  91. package/dist/esm/management/api/resources/organizations/resources/index.mjs +1 -0
  92. package/dist/esm/management/api/resources/organizations/resources/organizationTemplate/client/Client.d.mts +63 -0
  93. package/dist/esm/management/api/resources/organizations/resources/organizationTemplate/client/Client.mjs +195 -0
  94. package/dist/esm/management/api/resources/organizations/resources/organizationTemplate/client/index.d.mts +1 -0
  95. package/dist/esm/management/api/resources/organizations/resources/organizationTemplate/client/index.mjs +1 -0
  96. package/dist/esm/management/api/resources/organizations/resources/organizationTemplate/exports.d.mts +2 -0
  97. package/dist/esm/management/api/resources/organizations/resources/organizationTemplate/exports.mjs +3 -0
  98. package/dist/esm/management/api/resources/organizations/resources/organizationTemplate/index.d.mts +1 -0
  99. package/dist/esm/management/api/resources/organizations/resources/organizationTemplate/index.mjs +1 -0
  100. package/dist/esm/management/api/resources/users/resources/organizations/client/Client.d.mts +17 -0
  101. package/dist/esm/management/api/resources/users/resources/organizations/client/Client.mjs +19 -0
  102. package/dist/esm/management/api/types/types.d.mts +8896 -2027
  103. package/dist/esm/management/api/types/types.mjs +1434 -150
  104. package/dist/esm/management/version.d.mts +1 -1
  105. package/dist/esm/management/version.mjs +1 -1
  106. package/dist/esm/management/wrapper/ManagementClient.d.mts +9 -2
  107. package/dist/esm/management/wrapper/ManagementClient.mjs +0 -1
  108. package/dist/esm/management/wrapper/token-provider.d.mts +4 -2
  109. package/dist/esm/management/wrapper/token-provider.mjs +142 -11
  110. package/dist/esm/utils.d.mts +0 -18
  111. package/dist/esm/utils.mjs +0 -30
  112. package/package.json +23 -2
  113. package/reference.md +688 -28
  114. package/dist/cjs/auth/backchannel.d.ts +0 -158
  115. package/dist/cjs/auth/backchannel.js +0 -135
  116. package/dist/cjs/auth/base-auth-api.d.ts +0 -41
  117. package/dist/cjs/auth/base-auth-api.js +0 -109
  118. package/dist/cjs/auth/client-authentication.d.ts +0 -27
  119. package/dist/cjs/auth/client-authentication.js +0 -82
  120. package/dist/cjs/auth/database.d.ts +0 -157
  121. package/dist/cjs/auth/database.js +0 -94
  122. package/dist/cjs/auth/id-token-validator.d.ts +0 -18
  123. package/dist/cjs/auth/id-token-validator.js +0 -158
  124. package/dist/cjs/auth/index.d.ts +0 -65
  125. package/dist/cjs/auth/index.js +0 -80
  126. package/dist/cjs/auth/oauth.d.ts +0 -462
  127. package/dist/cjs/auth/oauth.js +0 -280
  128. package/dist/cjs/auth/passwordless.d.ts +0 -165
  129. package/dist/cjs/auth/passwordless.js +0 -173
  130. package/dist/cjs/auth/tokenExchange.d.ts +0 -166
  131. package/dist/cjs/auth/tokenExchange.js +0 -74
  132. package/dist/cjs/lib/index.d.ts +0 -3
  133. package/dist/cjs/lib/runtime.d.ts +0 -61
  134. package/dist/cjs/lib/runtime.js +0 -222
  135. package/dist/cjs/userinfo/index.d.ts +0 -87
  136. package/dist/cjs/userinfo/index.js +0 -104
  137. package/dist/esm/auth/backchannel.d.mts +0 -158
  138. package/dist/esm/auth/backchannel.mjs +0 -131
  139. package/dist/esm/auth/base-auth-api.d.mts +0 -41
  140. package/dist/esm/auth/base-auth-api.mjs +0 -103
  141. package/dist/esm/auth/client-authentication.d.mts +0 -27
  142. package/dist/esm/auth/client-authentication.mjs +0 -45
  143. package/dist/esm/auth/database.d.mts +0 -157
  144. package/dist/esm/auth/database.mjs +0 -90
  145. package/dist/esm/auth/id-token-validator.d.mts +0 -18
  146. package/dist/esm/auth/id-token-validator.mjs +0 -120
  147. package/dist/esm/auth/index.d.mts +0 -65
  148. package/dist/esm/auth/index.mjs +0 -60
  149. package/dist/esm/auth/oauth.d.mts +0 -462
  150. package/dist/esm/auth/oauth.mjs +0 -276
  151. package/dist/esm/auth/passwordless.d.mts +0 -165
  152. package/dist/esm/auth/passwordless.mjs +0 -169
  153. package/dist/esm/auth/tokenExchange.d.mts +0 -166
  154. package/dist/esm/auth/tokenExchange.mjs +0 -70
  155. package/dist/esm/lib/index.d.mts +0 -3
  156. package/dist/esm/lib/index.mjs +0 -2
  157. package/dist/esm/lib/runtime.d.mts +0 -61
  158. package/dist/esm/lib/runtime.mjs +0 -201
  159. package/dist/esm/userinfo/index.d.mts +0 -87
  160. package/dist/esm/userinfo/index.mjs +0 -98
@@ -1,104 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.UserInfoClient = exports.UserInfoError = void 0;
13
- exports.parseError = parseError;
14
- const errors_js_1 = require("../lib/errors.js");
15
- const auth0_client_telemetry_js_1 = require("../lib/middleware/auth0-client-telemetry.js");
16
- const models_js_1 = require("../lib/models.js");
17
- const runtime_js_1 = require("../lib/runtime.js");
18
- class UserInfoError extends Error {
19
- constructor(error, error_description, statusCode, body, headers) {
20
- super(error_description || error);
21
- this.error = error;
22
- this.error_description = error_description;
23
- this.statusCode = statusCode;
24
- this.body = body;
25
- this.headers = headers;
26
- this.name = "UserInfoError";
27
- }
28
- }
29
- exports.UserInfoError = UserInfoError;
30
- function parseError(response) {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- // Errors typically have a specific format:
33
- // {
34
- // error: 'invalid_body',
35
- // error_description: 'Bad Request',
36
- // }
37
- const body = yield response.text();
38
- let data;
39
- try {
40
- data = JSON.parse(body);
41
- return new UserInfoError(data.error, data.error_description, response.status, body, response.headers);
42
- }
43
- catch (_a) {
44
- return new errors_js_1.ResponseError(response.status, body, response.headers, "Response returned an error code");
45
- }
46
- });
47
- }
48
- /**
49
- * Auth0 UserInfo API Client
50
- *
51
- * Provides access to the UserInfo endpoint to retrieve user profile information
52
- * using an access token obtained during authentication.
53
- *
54
- * @group UserInfo API
55
- *
56
- * @example Basic usage
57
- * ```typescript
58
- * import { UserInfoClient } from 'auth0';
59
- *
60
- * const userInfoClient = new UserInfoClient({
61
- * domain: 'your-tenant.auth0.com'
62
- * });
63
- *
64
- * const userInfo = await userInfoClient.getUserInfo(accessToken);
65
- * console.log(userInfo.data.sub, userInfo.data.email);
66
- * ```
67
- */
68
- class UserInfoClient extends runtime_js_1.BaseAPI {
69
- /**
70
- * Create a new UserInfo API client
71
- * @param options - Configuration options including domain and client settings
72
- */
73
- constructor(options) {
74
- super(Object.assign(Object.assign({}, options), { baseUrl: `https://${options.domain}`, middleware: options.telemetry !== false ? [new auth0_client_telemetry_js_1.Auth0ClientTelemetry(options)] : [], parseError }));
75
- }
76
- /**
77
- * Given an access token get the user profile linked to it.
78
- *
79
- * @example <caption>
80
- * Get the user information based on the Auth0 access token (obtained during
81
- * login). Find more information in the
82
- * <a href="https://auth0.com/docs/auth-api#!#get--userinfo">API Docs</a>.
83
- * </caption>
84
- *
85
- * const userInfoClient = new UserInfoClient({
86
- * domain: '...'
87
- * });
88
-
89
- * const userInfo = await userInfoClient.getUserInfo(accessToken);
90
- */
91
- getUserInfo(accessToken, initOverrides) {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- const response = yield this.request({
94
- path: `/userinfo`,
95
- method: "GET",
96
- headers: {
97
- Authorization: `Bearer ${accessToken}`,
98
- },
99
- }, initOverrides);
100
- return models_js_1.JSONApiResponse.fromResponse(response);
101
- });
102
- }
103
- }
104
- exports.UserInfoClient = UserInfoClient;
@@ -1,158 +0,0 @@
1
- import { BaseAuthAPI } from "./base-auth-api.mjs";
2
- /**
3
- * The response from the authorize endpoint.
4
- */
5
- export type AuthorizeResponse = {
6
- /**
7
- * The authorization request ID.
8
- */
9
- auth_req_id: string;
10
- /**
11
- * The duration in seconds until the authentication request expires.
12
- */
13
- expires_in: number;
14
- /**
15
- * The interval in seconds to wait between poll requests.
16
- */
17
- interval: number;
18
- };
19
- /**
20
- * Options for the authorize request.
21
- */
22
- export type AuthorizeOptions = {
23
- /**
24
- * A human-readable string intended to be displayed on both the device calling /bc-authorize and the user’s authentication device.
25
- */
26
- binding_message: string;
27
- /**
28
- * A space-separated list of OIDC and custom API scopes.
29
- */
30
- scope: string;
31
- /**
32
- * Unique identifier of the audience for an issued token.
33
- */
34
- audience?: string;
35
- /**
36
- * Custom expiry time in seconds for this request.
37
- * @deprecated Use {@link AuthorizeOptions.requested_expiry} instead.
38
- */
39
- request_expiry?: string;
40
- /**
41
- * Custom expiry time in seconds for this request.
42
- */
43
- requested_expiry?: string;
44
- /**
45
- * The user ID.
46
- */
47
- userId: string;
48
- /**
49
- * Optional parameter for subject issuer context.
50
- */
51
- subjectIssuerContext?: string;
52
- /**
53
- * Optional authorization details to use Rich Authorization Requests (RAR).
54
- * @see https://auth0.com/docs/get-started/apis/configure-rich-authorization-requests
55
- */
56
- authorization_details?: string;
57
- } & Record<string, string>;
58
- export interface AuthorizationDetails {
59
- readonly type: string;
60
- readonly [parameter: string]: unknown;
61
- }
62
- /**
63
- * The response from the token endpoint.
64
- */
65
- export type TokenResponse = {
66
- /**
67
- * The access token.
68
- */
69
- access_token: string;
70
- /**
71
- * The refresh token, available with the `offline_access` scope.
72
- */
73
- refresh_token?: string;
74
- /**
75
- * The user's ID Token.
76
- */
77
- id_token: string;
78
- /**
79
- * The token type of the access token.
80
- */
81
- token_type?: string;
82
- /**
83
- * The duration in seconds that the access token is valid.
84
- */
85
- expires_in: number;
86
- /**
87
- * The scopes associated with the token.
88
- */
89
- scope: string;
90
- /**
91
- * Optional authorization details when using Rich Authorization Requests (RAR).
92
- * @see https://auth0.com/docs/get-started/apis/configure-rich-authorization-requests
93
- */
94
- authorization_details?: AuthorizationDetails[];
95
- };
96
- /**
97
- * Options for the token request.
98
- */
99
- export type TokenOptions = {
100
- /**
101
- * The authorization request ID.
102
- */
103
- auth_req_id: string;
104
- };
105
- /**
106
- * Interface for the backchannel authentication.
107
- */
108
- export interface IBackchannel {
109
- authorize: (options: AuthorizeOptions) => Promise<AuthorizeResponse>;
110
- backchannelGrant: (options: TokenOptions) => Promise<TokenResponse>;
111
- }
112
- /**
113
- * Class implementing the backchannel authentication flow.
114
- */
115
- export declare class Backchannel extends BaseAuthAPI implements IBackchannel {
116
- /**
117
- * Initiates a CIBA authorization request.
118
- *
119
- * @param {AuthorizeOptions} options - The options for the request.
120
- * @returns {Promise<AuthorizeResponse>} - The authorization response.
121
- *
122
- * @throws {Error} - If the request fails.
123
- */
124
- authorize({ userId, ...options }: AuthorizeOptions): Promise<AuthorizeResponse>;
125
- /**
126
- * Handles the backchannel grant flow for authentication. Client can poll this method at regular intervals to check if the backchannel auth request has been approved.
127
- *
128
- * @param {string} auth_req_id - The authorization request ID. This value is returned from the call to /bc-authorize. Once you have exchanged an auth_req_id for an ID and access token, it is no longer usable.
129
- * @returns {Promise<TokenResponse>} - A promise that resolves to the token response.
130
- *
131
- * @throws {Error} - Throws an error if the request fails.
132
- *
133
- * If the authorizing user has not yet approved or rejected the request, you will receive a response like this:
134
- * ```json
135
- * {
136
- * "error": "authorization_pending",
137
- * "error_description": "The end-user authorization is pending"
138
- * }
139
- * ```
140
- *
141
- * If the authorizing user rejects the request, you will receive a response like this:
142
- * ```json
143
- * {
144
- * "error": "access_denied",
145
- * "error_description": "The end-user denied the authorization request or it has been expired"
146
- * }
147
- * ```
148
- *
149
- * If you are polling too quickly (faster than the interval value returned from /bc-authorize), you will receive a response like this:
150
- * ```json
151
- * {
152
- * "error": "slow_down",
153
- * "error_description": "You are polling faster than allowed. Try again in 10 seconds."
154
- * }
155
- * ```
156
- */
157
- backchannelGrant({ auth_req_id }: TokenOptions): Promise<TokenResponse>;
158
- }
@@ -1,131 +0,0 @@
1
- // Wednesday, 8 January, 2025
2
- // Client Initiated Backchannel Authentication (CIBA)
3
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
- return new (P || (P = Promise))(function (resolve, reject) {
6
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
- step((generator = generator.apply(thisArg, _arguments || [])).next());
10
- });
11
- };
12
- var __rest = (this && this.__rest) || function (s, e) {
13
- var t = {};
14
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
- t[p] = s[p];
16
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
- t[p[i]] = s[p[i]];
20
- }
21
- return t;
22
- };
23
- // CIBA is an OpenID Foundation standard for a decoupled authentication flow. It enables
24
- // solution developers to build authentication flows where the user logging in does not do so
25
- // directly on the device that receives the ID or access tokens (the “Consumption Device”), but
26
- // instead on a separate “Authorization Device”.
27
- import { JSONApiResponse } from "../lib/models.mjs";
28
- import { BaseAuthAPI } from "./base-auth-api.mjs";
29
- /**
30
- * Generates the login hint for the user.
31
- *
32
- * @param {string} userId - The user ID.
33
- * @param {string} domain - The tenant domain.
34
- * @returns {string} - The login hint as a JSON string.
35
- */
36
- const getLoginHint = (userId, domain) => {
37
- // remove trailing '/' from domain, added later for uniformity
38
- const trimmedDomain = domain.endsWith("/") ? domain.slice(0, -1) : domain;
39
- const loginHint = {
40
- format: "iss_sub",
41
- iss: `https://${trimmedDomain}/`,
42
- sub: `${userId}`,
43
- };
44
- return JSON.stringify(loginHint);
45
- };
46
- const CIBA_GRANT_TYPE = "urn:openid:params:grant-type:ciba";
47
- const CIBA_AUTHORIZE_URL = "/bc-authorize";
48
- const CIBA_TOKEN_URL = "/oauth/token";
49
- /**
50
- * Class implementing the backchannel authentication flow.
51
- */
52
- export class Backchannel extends BaseAuthAPI {
53
- /**
54
- * Initiates a CIBA authorization request.
55
- *
56
- * @param {AuthorizeOptions} options - The options for the request.
57
- * @returns {Promise<AuthorizeResponse>} - The authorization response.
58
- *
59
- * @throws {Error} - If the request fails.
60
- */
61
- authorize(_a) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- var { userId } = _a, options = __rest(_a, ["userId"]);
64
- const body = Object.assign(Object.assign({}, options), { login_hint: getLoginHint(userId, this.domain), client_id: this.clientId });
65
- // The correct parameter is `requested_expiry`, but we also accept the deprecated `request_expiry` for backwards compatibility
66
- const requestedExpiry = options.requested_expiry || options.request_expiry;
67
- if (requestedExpiry) {
68
- body.requested_expiry = requestedExpiry;
69
- }
70
- yield this.addClientAuthentication(body);
71
- const response = yield this.request.bind(this)({
72
- path: CIBA_AUTHORIZE_URL,
73
- method: "POST",
74
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
75
- body: new URLSearchParams(body),
76
- }, {});
77
- const r = yield JSONApiResponse.fromResponse(response);
78
- return r.data;
79
- });
80
- }
81
- /**
82
- * Handles the backchannel grant flow for authentication. Client can poll this method at regular intervals to check if the backchannel auth request has been approved.
83
- *
84
- * @param {string} auth_req_id - The authorization request ID. This value is returned from the call to /bc-authorize. Once you have exchanged an auth_req_id for an ID and access token, it is no longer usable.
85
- * @returns {Promise<TokenResponse>} - A promise that resolves to the token response.
86
- *
87
- * @throws {Error} - Throws an error if the request fails.
88
- *
89
- * If the authorizing user has not yet approved or rejected the request, you will receive a response like this:
90
- * ```json
91
- * {
92
- * "error": "authorization_pending",
93
- * "error_description": "The end-user authorization is pending"
94
- * }
95
- * ```
96
- *
97
- * If the authorizing user rejects the request, you will receive a response like this:
98
- * ```json
99
- * {
100
- * "error": "access_denied",
101
- * "error_description": "The end-user denied the authorization request or it has been expired"
102
- * }
103
- * ```
104
- *
105
- * If you are polling too quickly (faster than the interval value returned from /bc-authorize), you will receive a response like this:
106
- * ```json
107
- * {
108
- * "error": "slow_down",
109
- * "error_description": "You are polling faster than allowed. Try again in 10 seconds."
110
- * }
111
- * ```
112
- */
113
- backchannelGrant(_a) {
114
- return __awaiter(this, arguments, void 0, function* ({ auth_req_id }) {
115
- const body = {
116
- client_id: this.clientId,
117
- auth_req_id,
118
- grant_type: CIBA_GRANT_TYPE,
119
- };
120
- yield this.addClientAuthentication(body);
121
- const response = yield this.request.bind(this)({
122
- path: CIBA_TOKEN_URL,
123
- method: "POST",
124
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
125
- body: new URLSearchParams(body),
126
- }, {});
127
- const r = yield JSONApiResponse.fromResponse(response);
128
- return r.data;
129
- });
130
- }
131
- }
@@ -1,41 +0,0 @@
1
- import { BaseAPI, ClientOptions, InitOverrideFunction, JSONApiResponse, RequestOpts } from "../lib/runtime.mjs";
2
- import { AddClientAuthenticationPayload } from "./client-authentication.mjs";
3
- import { IDTokenValidator } from "./id-token-validator.mjs";
4
- import { GrantOptions, TokenSet } from "./oauth.mjs";
5
- export interface AuthenticationClientOptions extends ClientOptions {
6
- domain: string;
7
- clientId: string;
8
- clientSecret?: string;
9
- clientAssertionSigningKey?: string;
10
- clientAssertionSigningAlg?: string;
11
- idTokenSigningAlg?: string;
12
- clockTolerance?: number;
13
- useMTLS?: boolean;
14
- }
15
- export declare class AuthApiError extends Error {
16
- error: string;
17
- error_description: string;
18
- statusCode: number;
19
- body: string;
20
- headers: Headers;
21
- name: "AuthApiError";
22
- constructor(error: string, error_description: string, statusCode: number, body: string, headers: Headers);
23
- }
24
- export declare class BaseAuthAPI extends BaseAPI {
25
- domain: string;
26
- clientId: string;
27
- clientSecret?: string;
28
- clientAssertionSigningKey?: string;
29
- clientAssertionSigningAlg?: string;
30
- useMTLS?: boolean;
31
- constructor(options: AuthenticationClientOptions);
32
- /**
33
- * @private
34
- */
35
- protected addClientAuthentication(payload: AddClientAuthenticationPayload): Promise<AddClientAuthenticationPayload>;
36
- }
37
- /**
38
- * @private
39
- * Perform an OAuth 2.0 grant.
40
- */
41
- export declare function grant(grantType: string, bodyParameters: Record<string, any>, { idTokenValidateOptions, initOverrides }: GrantOptions | undefined, clientId: string, idTokenValidator: IDTokenValidator, request: (context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction) => Promise<Response>): Promise<JSONApiResponse<TokenSet>>;
@@ -1,103 +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 { BaseAPI, JSONApiResponse } from "../lib/runtime.mjs";
12
- import { addClientAuthentication } from "./client-authentication.mjs";
13
- import { Auth0ClientTelemetry } from "../lib/middleware/auth0-client-telemetry.mjs";
14
- export class AuthApiError 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 = "AuthApiError";
23
- }
24
- }
25
- function parseErrorBody(body) {
26
- const rawData = JSON.parse(body);
27
- let data;
28
- if (rawData.error) {
29
- data = rawData;
30
- }
31
- else {
32
- data = {
33
- error: rawData.code,
34
- error_description: rawData.description,
35
- };
36
- }
37
- return data;
38
- }
39
- function parseError(response) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- // Errors typically have a specific format:
42
- // {
43
- // error: 'invalid_body',
44
- // error_description: 'Bad Request',
45
- // }
46
- const body = yield response.text();
47
- try {
48
- const data = parseErrorBody(body);
49
- return new AuthApiError(data.error, data.error_description, response.status, body, response.headers);
50
- }
51
- catch (_a) {
52
- return new ResponseError(response.status, body, response.headers, "Response returned an error code");
53
- }
54
- });
55
- }
56
- export class BaseAuthAPI extends BaseAPI {
57
- constructor(options) {
58
- super(Object.assign(Object.assign({}, options), { baseUrl: `https://${options.domain}`, middleware: options.telemetry !== false ? [new Auth0ClientTelemetry(options)] : [], parseError, retry: Object.assign({ enabled: false }, options.retry) }));
59
- this.domain = options.domain;
60
- this.clientId = options.clientId;
61
- this.clientSecret = options.clientSecret;
62
- this.clientAssertionSigningKey = options.clientAssertionSigningKey;
63
- this.clientAssertionSigningAlg = options.clientAssertionSigningAlg;
64
- this.useMTLS = options.useMTLS;
65
- }
66
- /**
67
- * @private
68
- */
69
- addClientAuthentication(payload) {
70
- return __awaiter(this, void 0, void 0, function* () {
71
- return addClientAuthentication({
72
- payload,
73
- domain: this.domain,
74
- clientId: this.clientId,
75
- clientSecret: this.clientSecret,
76
- clientAssertionSigningKey: this.clientAssertionSigningKey,
77
- clientAssertionSigningAlg: this.clientAssertionSigningAlg,
78
- useMTLS: this.useMTLS,
79
- });
80
- });
81
- }
82
- }
83
- /**
84
- * @private
85
- * Perform an OAuth 2.0 grant.
86
- */
87
- export function grant(grantType_1, bodyParameters_1) {
88
- return __awaiter(this, arguments, void 0, function* (grantType, bodyParameters, { idTokenValidateOptions, initOverrides } = {}, clientId, idTokenValidator, request) {
89
- const response = yield request({
90
- path: "/oauth/token",
91
- method: "POST",
92
- headers: {
93
- "Content-Type": "application/x-www-form-urlencoded",
94
- },
95
- body: new URLSearchParams(Object.assign(Object.assign({ client_id: clientId }, bodyParameters), { grant_type: grantType })),
96
- }, initOverrides);
97
- const res = yield JSONApiResponse.fromResponse(response);
98
- if (res.data.id_token) {
99
- yield idTokenValidator.validate(res.data.id_token, idTokenValidateOptions);
100
- }
101
- return res;
102
- });
103
- }
@@ -1,27 +0,0 @@
1
- export interface AddClientAuthenticationPayload {
2
- client_id?: string;
3
- client_secret?: string;
4
- client_assertion?: string;
5
- client_assertion_type?: string;
6
- [key: string]: any;
7
- }
8
- interface AddClientAuthenticationOptions {
9
- payload: AddClientAuthenticationPayload;
10
- domain: string;
11
- clientId: string;
12
- required?: boolean;
13
- clientAssertionSigningKey?: string;
14
- clientAssertionSigningAlg?: string;
15
- clientSecret?: string;
16
- useMTLS?: boolean;
17
- }
18
- /**
19
- * Adds client authentication, if available, to the provided payload.
20
- *
21
- * Adds `client_secret` for Client Secret Post token endpoint auth method (the SDK doesn't use Client Secret Basic)
22
- * Adds `client_assertion` and `client_assertion_type` for Private Key JWT token endpoint auth method.
23
- *
24
- * If `clientAssertionSigningKey` is provided it takes precedent over `clientSecret` .
25
- */
26
- export declare const addClientAuthentication: ({ payload, domain, clientId, clientAssertionSigningKey, clientAssertionSigningAlg, clientSecret, useMTLS, }: AddClientAuthenticationOptions) => Promise<Record<string, unknown>>;
27
- export {};
@@ -1,45 +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 * as jose from "jose";
11
- import { v4 as uuid } from "uuid";
12
- /**
13
- * Adds client authentication, if available, to the provided payload.
14
- *
15
- * Adds `client_secret` for Client Secret Post token endpoint auth method (the SDK doesn't use Client Secret Basic)
16
- * Adds `client_assertion` and `client_assertion_type` for Private Key JWT token endpoint auth method.
17
- *
18
- * If `clientAssertionSigningKey` is provided it takes precedent over `clientSecret` .
19
- */
20
- export const addClientAuthentication = (_a) => __awaiter(void 0, [_a], void 0, function* ({ payload, domain, clientId, clientAssertionSigningKey, clientAssertionSigningAlg, clientSecret, useMTLS, }) {
21
- const cid = payload.client_id || clientId;
22
- if (clientAssertionSigningKey && !payload.client_assertion) {
23
- const alg = clientAssertionSigningAlg || "RS256";
24
- const privateKey = yield jose.importPKCS8(clientAssertionSigningKey, alg);
25
- payload.client_assertion = yield new jose.SignJWT({})
26
- .setProtectedHeader({ alg })
27
- .setIssuedAt()
28
- .setSubject(cid)
29
- .setJti(uuid())
30
- .setIssuer(cid)
31
- .setAudience(`https://${domain}/`)
32
- .setExpirationTime("2mins")
33
- .sign(privateKey);
34
- payload.client_assertion_type = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer";
35
- }
36
- else if (clientSecret && !payload.client_secret) {
37
- payload.client_secret = clientSecret;
38
- }
39
- if ((!payload.client_secret || payload.client_secret.trim().length === 0) &&
40
- (!payload.client_assertion || payload.client_assertion.trim().length === 0) &&
41
- !useMTLS) {
42
- throw new Error("The client_secret or client_assertion field is required, or it should be mTLS request.");
43
- }
44
- return payload;
45
- });