auth0 6.4.0 → 7.1.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 (186) 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 +5 -5
  11. package/dist/cjs/management/Client.js +28 -28
  12. package/dist/cjs/management/api/errors/GatewayTimeoutError.d.ts +5 -0
  13. package/dist/cjs/management/api/errors/GatewayTimeoutError.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 +112 -88
  17. package/dist/cjs/management/api/resources/experimentation/client/Client.d.ts +12 -0
  18. package/dist/cjs/management/api/resources/experimentation/client/Client.js +16 -0
  19. package/dist/cjs/management/api/resources/experimentation/exports.d.ts +3 -0
  20. package/dist/cjs/management/api/resources/experimentation/exports.js +22 -0
  21. package/dist/cjs/management/api/resources/experimentation/index.d.ts +2 -0
  22. package/dist/cjs/management/api/resources/experimentation/index.js +18 -0
  23. package/dist/cjs/management/api/resources/experimentation/resources/experiments/client/Client.d.ts +34 -0
  24. package/dist/cjs/management/api/resources/experimentation/resources/experiments/client/Client.js +131 -0
  25. package/dist/cjs/management/api/resources/experimentation/resources/experiments/client/index.js +2 -0
  26. package/dist/cjs/management/api/resources/experimentation/resources/experiments/exports.d.ts +2 -0
  27. package/dist/cjs/management/api/resources/{organizationTemplates → experimentation/resources/experiments}/exports.js +2 -2
  28. package/dist/cjs/management/api/resources/experimentation/resources/index.d.ts +1 -0
  29. package/dist/cjs/management/api/resources/experimentation/resources/index.js +37 -0
  30. package/dist/cjs/management/api/resources/guardian/client/Client.d.ts +40 -1
  31. package/dist/cjs/management/api/resources/guardian/client/Client.js +172 -0
  32. package/dist/cjs/management/api/resources/guardian/resources/factors/client/Client.d.ts +3 -0
  33. package/dist/cjs/management/api/resources/guardian/resources/factors/client/Client.js +11 -6
  34. package/dist/cjs/management/api/resources/guardian/resources/factors/resources/email/client/Client.d.ts +46 -0
  35. package/dist/cjs/management/api/resources/guardian/resources/factors/resources/email/client/Client.js +181 -0
  36. package/dist/cjs/management/api/resources/guardian/resources/factors/resources/email/client/index.js +2 -0
  37. package/dist/cjs/management/api/resources/guardian/resources/factors/resources/email/exports.d.ts +2 -0
  38. package/dist/cjs/management/api/resources/guardian/resources/factors/resources/email/exports.js +21 -0
  39. package/dist/cjs/management/api/resources/guardian/resources/factors/resources/email/index.d.ts +1 -0
  40. package/dist/cjs/{lib → management/api/resources/guardian/resources/factors/resources/email}/index.js +1 -2
  41. package/dist/cjs/management/api/resources/guardian/resources/factors/resources/index.d.ts +1 -0
  42. package/dist/cjs/management/api/resources/guardian/resources/factors/resources/index.js +2 -1
  43. package/dist/cjs/management/api/resources/guardian/resources/factors/resources/phone/client/Client.d.ts +33 -0
  44. package/dist/cjs/management/api/resources/guardian/resources/factors/resources/phone/client/Client.js +122 -0
  45. package/dist/cjs/management/api/resources/index.d.ts +1 -1
  46. package/dist/cjs/management/api/resources/index.js +2 -2
  47. package/dist/cjs/management/api/resources/organizations/client/Client.d.ts +36 -0
  48. package/dist/cjs/management/api/resources/organizations/client/Client.js +104 -0
  49. package/dist/cjs/management/api/resources/resourceServers/client/Client.d.ts +29 -0
  50. package/dist/cjs/management/api/resources/resourceServers/client/Client.js +103 -0
  51. package/dist/cjs/management/api/types/types.d.ts +226 -51
  52. package/dist/cjs/management/api/types/types.js +37 -36
  53. package/dist/cjs/management/version.d.ts +1 -1
  54. package/dist/cjs/management/version.js +1 -1
  55. package/dist/cjs/management/wrapper/ManagementClient.d.ts +9 -2
  56. package/dist/cjs/management/wrapper/ManagementClient.js +0 -1
  57. package/dist/cjs/management/wrapper/token-provider.d.ts +4 -2
  58. package/dist/cjs/management/wrapper/token-provider.js +142 -11
  59. package/dist/cjs/utils.d.ts +0 -18
  60. package/dist/cjs/utils.js +1 -32
  61. package/dist/esm/index.d.mts +0 -2
  62. package/dist/esm/index.mjs +0 -2
  63. package/dist/esm/lib/errors.d.mts +0 -18
  64. package/dist/esm/lib/errors.mjs +0 -22
  65. package/dist/esm/lib/middleware/auth0-client-telemetry.d.mts +3 -7
  66. package/dist/esm/lib/middleware/auth0-client-telemetry.mjs +1 -25
  67. package/dist/esm/lib/models.d.mts +0 -24
  68. package/dist/esm/lib/models.mjs +1 -49
  69. package/dist/esm/management/Client.d.mts +5 -5
  70. package/dist/esm/management/Client.mjs +7 -7
  71. package/dist/esm/management/api/errors/GatewayTimeoutError.d.mts +5 -0
  72. package/dist/esm/management/api/errors/GatewayTimeoutError.mjs +17 -0
  73. package/dist/esm/management/api/errors/index.d.mts +1 -0
  74. package/dist/esm/management/api/errors/index.mjs +1 -0
  75. package/dist/esm/management/api/requests/requests.d.mts +112 -88
  76. package/dist/esm/management/api/resources/experimentation/client/Client.d.mts +12 -0
  77. package/dist/esm/management/api/resources/experimentation/client/Client.mjs +12 -0
  78. package/dist/esm/management/api/resources/experimentation/client/index.d.mts +1 -0
  79. package/dist/esm/management/api/resources/experimentation/client/index.mjs +1 -0
  80. package/dist/esm/management/api/resources/experimentation/exports.d.mts +3 -0
  81. package/dist/esm/management/api/resources/experimentation/exports.mjs +4 -0
  82. package/dist/esm/management/api/resources/experimentation/index.d.mts +2 -0
  83. package/dist/esm/management/api/resources/experimentation/index.mjs +2 -0
  84. package/dist/esm/management/api/resources/experimentation/resources/experiments/client/Client.d.mts +34 -0
  85. package/dist/esm/management/api/resources/experimentation/resources/experiments/client/Client.mjs +94 -0
  86. package/dist/esm/management/api/resources/experimentation/resources/experiments/client/index.d.mts +1 -0
  87. package/dist/esm/management/api/resources/experimentation/resources/experiments/client/index.mjs +1 -0
  88. package/dist/esm/management/api/resources/experimentation/resources/experiments/exports.d.mts +2 -0
  89. package/dist/esm/management/api/resources/{organizationTemplates → experimentation/resources/experiments}/exports.mjs +1 -1
  90. package/dist/esm/management/api/resources/experimentation/resources/index.d.mts +1 -0
  91. package/dist/esm/management/api/resources/experimentation/resources/index.mjs +1 -0
  92. package/dist/esm/management/api/resources/guardian/client/Client.d.mts +40 -1
  93. package/dist/esm/management/api/resources/guardian/client/Client.mjs +139 -0
  94. package/dist/esm/management/api/resources/guardian/resources/factors/client/Client.d.mts +3 -0
  95. package/dist/esm/management/api/resources/guardian/resources/factors/client/Client.mjs +5 -0
  96. package/dist/esm/management/api/resources/guardian/resources/factors/resources/email/client/Client.d.mts +46 -0
  97. package/dist/esm/management/api/resources/guardian/resources/factors/resources/email/client/Client.mjs +144 -0
  98. package/dist/esm/management/api/resources/guardian/resources/factors/resources/email/client/index.d.mts +1 -0
  99. package/dist/esm/management/api/resources/guardian/resources/factors/resources/email/client/index.mjs +1 -0
  100. package/dist/esm/management/api/resources/guardian/resources/factors/resources/email/exports.d.mts +2 -0
  101. package/dist/esm/management/api/resources/guardian/resources/factors/resources/email/exports.mjs +3 -0
  102. package/dist/esm/management/api/resources/guardian/resources/factors/resources/email/index.d.mts +1 -0
  103. package/dist/esm/management/api/resources/guardian/resources/factors/resources/email/index.mjs +1 -0
  104. package/dist/esm/management/api/resources/guardian/resources/factors/resources/index.d.mts +1 -0
  105. package/dist/esm/management/api/resources/guardian/resources/factors/resources/index.mjs +1 -0
  106. package/dist/esm/management/api/resources/guardian/resources/factors/resources/phone/client/Client.d.mts +33 -0
  107. package/dist/esm/management/api/resources/guardian/resources/factors/resources/phone/client/Client.mjs +122 -0
  108. package/dist/esm/management/api/resources/index.d.mts +1 -1
  109. package/dist/esm/management/api/resources/index.mjs +1 -1
  110. package/dist/esm/management/api/resources/organizations/client/Client.d.mts +36 -0
  111. package/dist/esm/management/api/resources/organizations/client/Client.mjs +104 -0
  112. package/dist/esm/management/api/resources/resourceServers/client/Client.d.mts +29 -0
  113. package/dist/esm/management/api/resources/resourceServers/client/Client.mjs +103 -0
  114. package/dist/esm/management/api/types/types.d.mts +226 -51
  115. package/dist/esm/management/api/types/types.mjs +34 -33
  116. package/dist/esm/management/version.d.mts +1 -1
  117. package/dist/esm/management/version.mjs +1 -1
  118. package/dist/esm/management/wrapper/ManagementClient.d.mts +9 -2
  119. package/dist/esm/management/wrapper/ManagementClient.mjs +0 -1
  120. package/dist/esm/management/wrapper/token-provider.d.mts +4 -2
  121. package/dist/esm/management/wrapper/token-provider.mjs +142 -11
  122. package/dist/esm/utils.d.mts +0 -18
  123. package/dist/esm/utils.mjs +0 -30
  124. package/package.json +45 -23
  125. package/reference.md +654 -389
  126. package/dist/cjs/auth/backchannel.d.ts +0 -158
  127. package/dist/cjs/auth/backchannel.js +0 -135
  128. package/dist/cjs/auth/base-auth-api.d.ts +0 -41
  129. package/dist/cjs/auth/base-auth-api.js +0 -109
  130. package/dist/cjs/auth/client-authentication.d.ts +0 -27
  131. package/dist/cjs/auth/client-authentication.js +0 -82
  132. package/dist/cjs/auth/database.d.ts +0 -157
  133. package/dist/cjs/auth/database.js +0 -94
  134. package/dist/cjs/auth/id-token-validator.d.ts +0 -18
  135. package/dist/cjs/auth/id-token-validator.js +0 -158
  136. package/dist/cjs/auth/index.d.ts +0 -65
  137. package/dist/cjs/auth/index.js +0 -80
  138. package/dist/cjs/auth/oauth.d.ts +0 -462
  139. package/dist/cjs/auth/oauth.js +0 -280
  140. package/dist/cjs/auth/passwordless.d.ts +0 -165
  141. package/dist/cjs/auth/passwordless.js +0 -173
  142. package/dist/cjs/auth/tokenExchange.d.ts +0 -166
  143. package/dist/cjs/auth/tokenExchange.js +0 -74
  144. package/dist/cjs/lib/index.d.ts +0 -3
  145. package/dist/cjs/lib/runtime.d.ts +0 -61
  146. package/dist/cjs/lib/runtime.js +0 -222
  147. package/dist/cjs/management/api/resources/organizationTemplates/client/Client.d.ts +0 -106
  148. package/dist/cjs/management/api/resources/organizationTemplates/client/Client.js +0 -411
  149. package/dist/cjs/management/api/resources/organizationTemplates/exports.d.ts +0 -2
  150. package/dist/cjs/userinfo/index.d.ts +0 -87
  151. package/dist/cjs/userinfo/index.js +0 -104
  152. package/dist/esm/auth/backchannel.d.mts +0 -158
  153. package/dist/esm/auth/backchannel.mjs +0 -131
  154. package/dist/esm/auth/base-auth-api.d.mts +0 -41
  155. package/dist/esm/auth/base-auth-api.mjs +0 -103
  156. package/dist/esm/auth/client-authentication.d.mts +0 -27
  157. package/dist/esm/auth/client-authentication.mjs +0 -45
  158. package/dist/esm/auth/database.d.mts +0 -157
  159. package/dist/esm/auth/database.mjs +0 -90
  160. package/dist/esm/auth/id-token-validator.d.mts +0 -18
  161. package/dist/esm/auth/id-token-validator.mjs +0 -120
  162. package/dist/esm/auth/index.d.mts +0 -65
  163. package/dist/esm/auth/index.mjs +0 -60
  164. package/dist/esm/auth/oauth.d.mts +0 -462
  165. package/dist/esm/auth/oauth.mjs +0 -276
  166. package/dist/esm/auth/passwordless.d.mts +0 -165
  167. package/dist/esm/auth/passwordless.mjs +0 -169
  168. package/dist/esm/auth/tokenExchange.d.mts +0 -166
  169. package/dist/esm/auth/tokenExchange.mjs +0 -70
  170. package/dist/esm/lib/index.d.mts +0 -3
  171. package/dist/esm/lib/index.mjs +0 -2
  172. package/dist/esm/lib/runtime.d.mts +0 -61
  173. package/dist/esm/lib/runtime.mjs +0 -201
  174. package/dist/esm/management/api/resources/organizationTemplates/client/Client.d.mts +0 -106
  175. package/dist/esm/management/api/resources/organizationTemplates/client/Client.mjs +0 -374
  176. package/dist/esm/management/api/resources/organizationTemplates/exports.d.mts +0 -2
  177. package/dist/esm/userinfo/index.d.mts +0 -87
  178. package/dist/esm/userinfo/index.mjs +0 -98
  179. /package/dist/cjs/management/api/resources/{organizationTemplates → experimentation}/client/index.d.ts +0 -0
  180. /package/dist/cjs/management/api/resources/{organizationTemplates → experimentation}/client/index.js +0 -0
  181. /package/dist/{esm/management/api/resources/organizationTemplates/client/index.d.mts → cjs/management/api/resources/experimentation/resources/experiments/client/index.d.ts} +0 -0
  182. /package/dist/cjs/management/api/resources/{organizationTemplates → experimentation/resources/experiments}/index.d.ts +0 -0
  183. /package/dist/cjs/management/api/resources/{organizationTemplates → experimentation/resources/experiments}/index.js +0 -0
  184. /package/dist/{esm/management/api/resources/organizationTemplates/client/index.mjs → cjs/management/api/resources/guardian/resources/factors/resources/email/client/index.d.ts} +0 -0
  185. /package/dist/esm/management/api/resources/{organizationTemplates → experimentation/resources/experiments}/index.d.mts +0 -0
  186. /package/dist/esm/management/api/resources/{organizationTemplates → experimentation/resources/experiments}/index.mjs +0 -0
@@ -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
- });
@@ -1,157 +0,0 @@
1
- import { InitOverride, JSONApiResponse, TextApiResponse } from "../lib/models.mjs";
2
- import { BaseAuthAPI } from "./base-auth-api.mjs";
3
- export interface SignUpRequest {
4
- /**
5
- * The client_id of your client.
6
- * Use if you want to override the class's `clientId`
7
- */
8
- client_id?: string;
9
- /**
10
- * The user's email address.
11
- */
12
- email: string;
13
- /**
14
- * The user's desired password.
15
- */
16
- password: string;
17
- /**
18
- * The name of the database configured to your client.
19
- */
20
- connection: string;
21
- /**
22
- * The user's username. Only valid if the connection requires a username.
23
- */
24
- username?: string;
25
- /**
26
- * The user's given name(s).
27
- */
28
- given_name?: string;
29
- /**
30
- * The user's family name(s).
31
- */
32
- family_name?: string;
33
- /**
34
- * The user's full name.
35
- */
36
- name?: string;
37
- /**
38
- *The user's nickname.
39
- */
40
- nickname?: string;
41
- /**
42
- * A URI pointing to the user's picture.
43
- */
44
- picture?: string;
45
- /**
46
- * The user metadata to be associated with the user. If set, the field must be an object containing no more than ten properties. Property names can have a maximum of 100 characters, and property values must be strings of no more than 500 characters.
47
- */
48
- user_metadata?: {
49
- [key: string]: unknown;
50
- };
51
- }
52
- export interface SignUpResponse {
53
- /**
54
- * Email address of the new user.
55
- */
56
- email: string;
57
- /**
58
- * Indicates whether the email has been verified or not.
59
- */
60
- email_verified: boolean;
61
- /**
62
- * The server can return `_id`, `id` or `user_id` depending on various factors.
63
- * For convenience we expose it here as just `id`.
64
- */
65
- id: string;
66
- /**
67
- * Username of this user.
68
- */
69
- username?: string;
70
- /**
71
- * The user's given name(s).
72
- */
73
- given_name?: string;
74
- /**
75
- * The user's family name(s).
76
- */
77
- family_name?: string;
78
- /**
79
- * The user's full name.
80
- */
81
- name?: string;
82
- /**
83
- *The user's nickname.
84
- */
85
- nickname?: string;
86
- /**
87
- * A URI pointing to the user's picture.
88
- */
89
- picture?: string;
90
- /**
91
- * The user metadata to be associated with the user. If set, the field must be an object containing no more than ten properties. Property names can have a maximum of 100 characters, and property values must be strings of no more than 500 characters.
92
- */
93
- user_metadata?: {
94
- [key: string]: unknown;
95
- };
96
- }
97
- export interface ChangePasswordRequest {
98
- /**
99
- * The client_id of your client.
100
- * Use if you want to override the class's `clientId`
101
- */
102
- client_id?: string;
103
- /**
104
- * The user's email address.
105
- */
106
- email: string;
107
- /**
108
- * The name of the database configured to your client.
109
- */
110
- connection: string;
111
- /**
112
- * The organization_id of the Organization associated with the user.
113
- */
114
- organization?: string;
115
- }
116
- /**
117
- * Sign-up and change-password for Database & Active Directory authentication services.
118
- */
119
- export declare class Database extends BaseAuthAPI {
120
- /**
121
- * Given a user's credentials, and a connection, this endpoint will create a new user using active authentication.
122
- *
123
- * This endpoint only works for database connections.
124
- *
125
- * See: https://auth0.com/docs/api/authentication#signup
126
- *
127
- * @example
128
- * ```js
129
- * var data = {
130
- * email: '{EMAIL}',
131
- * password: '{PASSWORD}',
132
- * connection: 'Username-Password-Authentication'
133
- * };
134
- *
135
- * await auth0.database.signUp(data);
136
- * ```
137
- */
138
- signUp(bodyParameters: SignUpRequest, initOverrides?: InitOverride): Promise<JSONApiResponse<SignUpResponse>>;
139
- /**
140
- * Given a user's email address and a connection, Auth0 will send a change password email.
141
- *
142
- * This endpoint only works for database connections.
143
- *
144
- * See: https://auth0.com/docs/api/authentication#change-password
145
- *
146
- * @example
147
- * ```js
148
- * var data = {
149
- * email: '{EMAIL}',
150
- * connection: 'Username-Password-Authentication'
151
- * };
152
- *
153
- * await auth0.database.changePassword(data);
154
- * ```
155
- */
156
- changePassword(bodyParameters: ChangePasswordRequest, initOverrides?: InitOverride): Promise<TextApiResponse>;
157
- }