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,280 +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.OAuth = exports.TOKEN_URL = exports.TOKEN_FOR_CONNECTION_REQUESTED_TOKEN_TYPE = exports.TOKEN_FOR_CONNECTION_TOKEN_TYPE = exports.TOKEN_FOR_CONNECTION_GRANT_TYPE = exports.SUBJECT_TOKEN_TYPES = void 0;
13
- const runtime_js_1 = require("../lib/runtime.js");
14
- const base_auth_api_js_1 = require("./base-auth-api.js");
15
- const id_token_validator_js_1 = require("./id-token-validator.js");
16
- const utils_js_1 = require("../utils.js");
17
- var SUBJECT_TOKEN_TYPES;
18
- (function (SUBJECT_TOKEN_TYPES) {
19
- /**
20
- * Constant representing the subject type for a refresh token.
21
- * This is used in OAuth 2.0 token exchange to specify that the token being exchanged is a refresh token.
22
- *
23
- * @see {@link https://tools.ietf.org/html/rfc8693#section-3.1 RFC 8693 Section 3.1}
24
- */
25
- SUBJECT_TOKEN_TYPES["REFRESH_TOKEN"] = "urn:ietf:params:oauth:token-type:refresh_token";
26
- /**
27
- * Constant representing the subject type for a access token.
28
- * This is used in OAuth 2.0 token exchange to specify that the token being exchanged is an access token.
29
- *
30
- * @see {@link https://tools.ietf.org/html/rfc8693#section-3.1 RFC 8693 Section 3.1}
31
- */
32
- SUBJECT_TOKEN_TYPES["ACCESS_TOKEN"] = "urn:ietf:params:oauth:token-type:access_token";
33
- })(SUBJECT_TOKEN_TYPES || (exports.SUBJECT_TOKEN_TYPES = SUBJECT_TOKEN_TYPES = {}));
34
- exports.TOKEN_FOR_CONNECTION_GRANT_TYPE = "urn:auth0:params:oauth:grant-type:token-exchange:federated-connection-access-token";
35
- /**
36
- * @deprecated Use {@link SUBJECT_TOKEN_TYPES.REFRESH_TOKEN} instead.
37
- */
38
- exports.TOKEN_FOR_CONNECTION_TOKEN_TYPE = "urn:ietf:params:oauth:token-type:refresh_token";
39
- exports.TOKEN_FOR_CONNECTION_REQUESTED_TOKEN_TYPE = "http://auth0.com/oauth/token-type/federated-connection-access-token";
40
- exports.TOKEN_URL = "/oauth/token";
41
- /**
42
- * OAuth 2.0 flows.
43
- */
44
- class OAuth extends base_auth_api_js_1.BaseAuthAPI {
45
- constructor(options) {
46
- super(Object.assign(Object.assign({}, options), { domain: options.useMTLS ? `${utils_js_1.mtlsPrefix}.${options.domain}` : options.domain }));
47
- this.idTokenValidator = new id_token_validator_js_1.IDTokenValidator(options);
48
- }
49
- /**
50
- * This is the flow that regular web apps use to access an API.
51
- *
52
- * Use this endpoint to exchange an Authorization Code for a Token.
53
- *
54
- * See: https://auth0.com/docs/api/authentication#authorization-code-flow44
55
- *
56
- * @example
57
- * ```js
58
- * const auth0 = new AuthenticationApi({
59
- * domain: 'my-domain.auth0.com',
60
- * clientId: 'myClientId',
61
- * clientSecret: 'myClientSecret'
62
- * });
63
- *
64
- * await auth0.oauth.authorizationCodeGrant({ code: 'mycode' });
65
- * ```
66
- */
67
- authorizationCodeGrant(bodyParameters_1) {
68
- return __awaiter(this, arguments, void 0, function* (bodyParameters, options = {}) {
69
- (0, runtime_js_1.validateRequiredRequestParams)(bodyParameters, ["code"]);
70
- return (0, base_auth_api_js_1.grant)("authorization_code", yield this.addClientAuthentication(bodyParameters), options, this.clientId, this.idTokenValidator, this.request.bind(this));
71
- });
72
- }
73
- /**
74
- * PKCE was originally designed to protect the authorization code flow in mobile apps,
75
- * but its ability to prevent authorization code injection makes it useful for every type of OAuth client,
76
- * even web apps that use client authentication.
77
- *
78
- * See: https://auth0.com/docs/api/authentication#authorization-code-flow-with-pkce45
79
- *
80
- * @example
81
- * ```js
82
- * const auth0 = new AuthenticationApi({
83
- * domain: 'my-domain.auth0.com',
84
- * clientId: 'myClientId',
85
- * clientSecret: 'myClientSecret'
86
- * });
87
- *
88
- * await auth0.oauth.authorizationCodeGrantWithPKCE({
89
- * code: 'mycode',
90
- * code_verifier: 'mycodeverifier'
91
- * });
92
- * ```
93
- */
94
- authorizationCodeGrantWithPKCE(bodyParameters_1) {
95
- return __awaiter(this, arguments, void 0, function* (bodyParameters, options = {}) {
96
- (0, runtime_js_1.validateRequiredRequestParams)(bodyParameters, ["code", "code_verifier"]);
97
- return (0, base_auth_api_js_1.grant)("authorization_code", yield this.addClientAuthentication(bodyParameters), options, this.clientId, this.idTokenValidator, this.request.bind(this));
98
- });
99
- }
100
- /**
101
- * This is the OAuth 2.0 grant that server processes use to access an API.
102
- *
103
- * Use this endpoint to directly request an Access Token by using the Client's credentials
104
- * (a Client ID and a Client Secret or a Client Assertion).
105
- *
106
- * See: https://auth0.com/docs/api/authentication#client-credentials-flow
107
- *
108
- * @example
109
- * ```js
110
- * const auth0 = new AuthenticationApi({
111
- * domain: 'my-domain.auth0.com',
112
- * clientId: 'myClientId',
113
- * clientSecret: 'myClientSecret'
114
- * });
115
- *
116
- * await auth0.oauth.clientCredentialsGrant({ audience: 'myaudience' });
117
- * ```
118
- */
119
- clientCredentialsGrant(bodyParameters_1) {
120
- return __awaiter(this, arguments, void 0, function* (bodyParameters, options = {}) {
121
- (0, runtime_js_1.validateRequiredRequestParams)(bodyParameters, ["audience"]);
122
- return (0, base_auth_api_js_1.grant)("client_credentials", yield this.addClientAuthentication(bodyParameters), options, this.clientId, this.idTokenValidator, this.request.bind(this));
123
- });
124
- }
125
- /**
126
- * This is the OAuth 2.0 extension that allows to initiate an OAuth flow from the backchannel instead of by building a URL.
127
- *
128
- *
129
- * See: https://www.rfc-editor.org/rfc/rfc9126.html
130
- *
131
- * @example
132
- * ```js
133
- * const auth0 = new AuthenticationApi({
134
- * domain: 'my-domain.auth0.com',
135
- * clientId: 'myClientId',
136
- * clientSecret: 'myClientSecret'
137
- * });
138
- *
139
- * await auth0.oauth.pushedAuthorization({ response_type: 'id_token', redirect_uri: 'http://localhost' });
140
- * ```
141
- */
142
- pushedAuthorization(bodyParameters_1) {
143
- return __awaiter(this, arguments, void 0, function* (bodyParameters, options = {}) {
144
- (0, runtime_js_1.validateRequiredRequestParams)(bodyParameters, ["client_id", "response_type", "redirect_uri"]);
145
- const bodyParametersWithClientAuthentication = yield this.addClientAuthentication(bodyParameters);
146
- const response = yield this.request({
147
- path: "/oauth/par",
148
- method: "POST",
149
- headers: {
150
- "Content-Type": "application/x-www-form-urlencoded",
151
- },
152
- body: new URLSearchParams(Object.assign({ client_id: this.clientId }, bodyParametersWithClientAuthentication)),
153
- }, options.initOverrides);
154
- return runtime_js_1.JSONApiResponse.fromResponse(response);
155
- });
156
- }
157
- /**
158
- * This information is typically received from a highly trusted public client like a SPA*.
159
- * (<strong>*Note:</string> For single-page applications and native/mobile apps, we recommend using web flows instead.)
160
- *
161
- * See: https://auth0.com/docs/api/authentication#resource-owner-password
162
- *
163
- * @example
164
- * ```js
165
- * const auth0 = new AuthenticationApi({
166
- * domain: 'my-domain.auth0.com',
167
- * clientId: 'myClientId'
168
- * clientSecret: 'myClientSecret'
169
- * });
170
- *
171
- * await auth0.oauth.passwordGrant({
172
- * username: 'myusername@example.com',
173
- * password: 'mypassword'
174
- * },
175
- * { initOverrides: { headers: { 'auth0-forwarded-for': 'END.USER.IP.123' } } }
176
- * );
177
- * ```
178
- *
179
- * Set the'auth0-forwarded-for' header to the end-user IP as a string value if you want
180
- * brute-force protection to work in server-side scenarios.
181
- *
182
- * See https://auth0.com/docs/get-started/authentication-and-authorization-flow/avoid-common-issues-with-resource-owner-password-flow-and-attack-protection
183
- *
184
- */
185
- passwordGrant(bodyParameters_1) {
186
- return __awaiter(this, arguments, void 0, function* (bodyParameters, options = {}) {
187
- (0, runtime_js_1.validateRequiredRequestParams)(bodyParameters, ["username", "password"]);
188
- return (0, base_auth_api_js_1.grant)(bodyParameters.realm ? "http://auth0.com/oauth/grant-type/password-realm" : "password", yield this.addClientAuthentication(bodyParameters), options, this.clientId, this.idTokenValidator, this.request.bind(this));
189
- });
190
- }
191
- /**
192
- * Use this endpoint to refresh an Access Token using the Refresh Token you got during authorization.
193
- *
194
- * See: https://auth0.com/docs/api/authentication#refresh-token
195
- *
196
- * @example
197
- * ```js
198
- * const auth0 = new AuthenticationApi({
199
- * domain: 'my-domain.auth0.com',
200
- * clientId: 'myClientId'
201
- * clientSecret: 'myClientSecret'
202
- * });
203
- *
204
- * await auth0.oauth.refreshTokenGrant({ refresh_token: 'myrefreshtoken' })
205
- * ```
206
- */
207
- refreshTokenGrant(bodyParameters_1) {
208
- return __awaiter(this, arguments, void 0, function* (bodyParameters, options = {}) {
209
- (0, runtime_js_1.validateRequiredRequestParams)(bodyParameters, ["refresh_token"]);
210
- return (0, base_auth_api_js_1.grant)("refresh_token", yield this.addClientAuthentication(bodyParameters), options, this.clientId, this.idTokenValidator, this.request.bind(this));
211
- });
212
- }
213
- /**
214
- * Use this endpoint to invalidate a Refresh Token if it has been compromised.
215
- *
216
- * The behaviour of this endpoint depends on the state of the <a href="https://auth0.com/docs/secure/tokens/refresh-tokens/revoke-refresh-tokens#refresh-tokens-and-grants">Refresh Token Revocation Deletes Grant</a> toggle.
217
- * If this toggle is enabled, then each revocation request invalidates not only the specific token, but all other tokens based on the same authorization grant.
218
- * This means that all Refresh Tokens that have been issued for the same user, application, and audience will be revoked.
219
- * If this toggle is disabled, then only the refresh token is revoked, while the grant is left intact.
220
- *
221
- * See: https://auth0.com/docs/api/authentication#revoke-refresh-token
222
- *
223
- * @example
224
- * ```js
225
- * const auth0 = new AuthenticationApi({
226
- * domain: 'my-domain.auth0.com',
227
- * clientId: 'myClientId'
228
- * clientSecret: 'myClientSecret'
229
- * });
230
- *
231
- * await auth0.oauth.revokeRefreshToken({ token: 'myrefreshtoken' })
232
- * ```
233
- */
234
- revokeRefreshToken(bodyParameters_1) {
235
- return __awaiter(this, arguments, void 0, function* (bodyParameters, options = {}) {
236
- (0, runtime_js_1.validateRequiredRequestParams)(bodyParameters, ["token"]);
237
- const response = yield this.request({
238
- path: "/oauth/revoke",
239
- method: "POST",
240
- headers: {
241
- "Content-Type": "application/json",
242
- },
243
- body: yield this.addClientAuthentication(Object.assign({ client_id: this.clientId }, bodyParameters)),
244
- }, options.initOverrides);
245
- return runtime_js_1.VoidApiResponse.fromResponse(response);
246
- });
247
- }
248
- /**
249
- * Exchanges a subject token for an access token for the connection.
250
- *
251
- * The request body includes:
252
- * - client_id (and client_secret/client_assertion via addClientAuthentication)
253
- * - grant_type set to `urn:auth0:params:oauth:grant-type:token-exchange:federated-connection-access-token`
254
- * - subject_token: the token to exchange
255
- * - subject_token_type: the type of token being exchanged. Defaults to refresh tokens (`urn:ietf:params:oauth:token-type:refresh_token`).
256
- * - requested_token_type (`http://auth0.com/oauth/token-type/federated-connection-access-token`) indicating that a federated connection access token is desired
257
- * - connection name and an optional `login_hint` if provided
258
- *
259
- * @param bodyParameters - The options to retrieve a token for a connection.
260
- * @returns A promise with the token response data.
261
- * @throws An error if the exchange fails.
262
- */
263
- tokenForConnection(bodyParameters_1) {
264
- return __awaiter(this, arguments, void 0, function* (bodyParameters, options = {}) {
265
- (0, runtime_js_1.validateRequiredRequestParams)(bodyParameters, ["connection", "subject_token"]);
266
- const body = Object.assign(Object.assign({ subject_token_type: SUBJECT_TOKEN_TYPES.REFRESH_TOKEN }, bodyParameters), { grant_type: exports.TOKEN_FOR_CONNECTION_GRANT_TYPE, requested_token_type: exports.TOKEN_FOR_CONNECTION_REQUESTED_TOKEN_TYPE });
267
- yield this.addClientAuthentication(body);
268
- const response = yield this.request({
269
- path: exports.TOKEN_URL,
270
- method: "POST",
271
- headers: {
272
- "Content-Type": "application/x-www-form-urlencoded",
273
- },
274
- body: new URLSearchParams(body),
275
- }, options.initOverrides);
276
- return runtime_js_1.JSONApiResponse.fromResponse(response);
277
- });
278
- }
279
- }
280
- exports.OAuth = OAuth;
@@ -1,165 +0,0 @@
1
- import { InitOverride, JSONApiResponse, VoidApiResponse } from "../lib/runtime.js";
2
- import { BaseAuthAPI, AuthenticationClientOptions } from "./base-auth-api.js";
3
- import { ClientCredentials, GrantOptions, TokenSet } from "./oauth.js";
4
- export interface SendEmailLinkRequest {
5
- /**
6
- * The user's email address
7
- */
8
- email: string;
9
- /**
10
- * Use `link` to send a link or `code` to send a verification code.
11
- * If omitted, a `link` will be sent.
12
- */
13
- send?: "link";
14
- /**
15
- * Append or override the link parameters (like `scope`, `redirect_uri`, `protocol`, `response_type`),
16
- * when you send a link using email.
17
- */
18
- authParams?: Record<string, unknown>;
19
- }
20
- export interface SendEmailCodeRequest {
21
- /**
22
- * The user's email address
23
- */
24
- email: string;
25
- /**
26
- * Use `link` to send a link or `code` to send a verification code.
27
- * If omitted, a `link` will be sent.
28
- */
29
- send?: "code";
30
- }
31
- export type SendEmailRequest = SendEmailLinkRequest | SendEmailCodeRequest;
32
- export interface SendSmsRequest {
33
- /**
34
- * The users phone number.
35
- */
36
- phone_number: string;
37
- }
38
- export interface LoginWithEmailRequest extends ClientCredentials {
39
- /**
40
- * The user's email address.
41
- */
42
- email: string;
43
- /**
44
- * The user's verification code.
45
- */
46
- code: string;
47
- /**
48
- * API Identifier of the API for which you want to get an Access Token.
49
- */
50
- audience?: string;
51
- /**
52
- * Use openid to get an ID Token, or openid profile email to also include user profile information in the ID Token.
53
- */
54
- scope?: string;
55
- }
56
- export interface LoginWithSMSRequest extends Omit<LoginWithEmailRequest, "email"> {
57
- /**
58
- * The user's phone number.
59
- */
60
- phone_number: string;
61
- }
62
- /**
63
- * Handles passwordless flows using Email and SMS.
64
- */
65
- export declare class Passwordless extends BaseAuthAPI {
66
- private idTokenValidator;
67
- constructor(configuration: AuthenticationClientOptions);
68
- /**
69
- * Start passwordless flow sending an email.
70
- *
71
- * Given the user `email` address, it will send an email with:
72
- *
73
- * <ul>
74
- * <li>A link (default, `send:"link"`). You can then authenticate with this
75
- * user opening the link and he will be automatically logged in to the
76
- * application. Optionally, you can append/override parameters to the link
77
- * (like `scope`, `redirect_uri`, `protocol`, `response_type`, etc.) using
78
- * `authParams` object.
79
- * </li>
80
- * <li>
81
- * A verification code (`send:"code"`). You can then authenticate with
82
- * this user using the `/oauth/token` endpoint specifying `email` as
83
- * `username` and `code` as `password`.
84
- * </li>
85
- * </ul>
86
- *
87
- * See: https://auth0.com/docs/api/authentication#get-code-or-link
88
- *
89
- * @example
90
- * ```js
91
- * const auth0 = new AuthenticationApi({
92
- * domain: 'my-domain.auth0.com',
93
- * clientId: 'myClientId',
94
- * clientSecret: 'myClientSecret'
95
- * });
96
- *
97
- * await auth0.passwordless.sendEmail({
98
- * email: '{EMAIL}',
99
- * send: 'link',
100
- * authParams: {} // Optional auth params.
101
- * });
102
- * ```
103
- */
104
- sendEmail(bodyParameters: SendEmailRequest, initOverrides?: InitOverride): Promise<VoidApiResponse>;
105
- /**
106
- * Start passwordless flow sending an SMS.
107
- *
108
- * Given the user `phone_number`, it will send a SMS message with a
109
- * verification code. You can then authenticate with this user using the
110
- * `/oauth/token` endpoint specifying `phone_number` as `username` and `code` as
111
- * `password`:
112
- *
113
- * See: https://auth0.com/docs/api/authentication#get-code-or-link
114
- *
115
- * @example
116
- * ```js
117
- * const auth0 = new AuthenticationApi({
118
- * domain: 'my-domain.auth0.com',
119
- * clientId: 'myClientId',
120
- * clientSecret: 'myClientSecret'
121
- * });
122
- *
123
- * await auth0.passwordless.sendSMS({
124
- * phone_number: '{PHONE}'
125
- * });
126
- * ```
127
- */
128
- sendSMS(bodyParameters: SendSmsRequest, initOverrides?: InitOverride): Promise<VoidApiResponse>;
129
- /**
130
- * Once you have a verification code, use this endpoint to login the user with their email and verification code.
131
- *
132
- * @example
133
- * ```js
134
- * const auth0 = new AuthenticationApi({
135
- * domain: 'my-domain.auth0.com',
136
- * clientId: 'myClientId',
137
- * clientSecret: 'myClientSecret'
138
- * });
139
- *
140
- * await auth0.passwordless.loginWithEmail({
141
- * email: 'foo@example.com',
142
- * code: 'ABC123'
143
- * });
144
- * ```
145
- */
146
- loginWithEmail(bodyParameters: LoginWithEmailRequest, options?: GrantOptions): Promise<JSONApiResponse<TokenSet>>;
147
- /**
148
- * Once you have a verification code, use this endpoint to login the user with their phone number and verification code.
149
- *
150
- * @example
151
- * ```js
152
- * const auth0 = new AuthenticationApi({
153
- * domain: 'my-domain.auth0.com',
154
- * clientId: 'myClientId',
155
- * clientSecret: 'myClientSecret'
156
- * });
157
- *
158
- * await auth0.passwordless.loginWithSMS({
159
- * phone_number: '0777777777',
160
- * code: 'ABC123'
161
- * });
162
- * ```
163
- */
164
- loginWithSMS(bodyParameters: LoginWithSMSRequest, options?: GrantOptions): Promise<JSONApiResponse<TokenSet>>;
165
- }
@@ -1,173 +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
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.Passwordless = void 0;
24
- const runtime_js_1 = require("../lib/runtime.js");
25
- const base_auth_api_js_1 = require("./base-auth-api.js");
26
- const id_token_validator_js_1 = require("./id-token-validator.js");
27
- /**
28
- * Handles passwordless flows using Email and SMS.
29
- */
30
- class Passwordless extends base_auth_api_js_1.BaseAuthAPI {
31
- constructor(configuration) {
32
- super(configuration);
33
- this.idTokenValidator = new id_token_validator_js_1.IDTokenValidator(configuration);
34
- }
35
- /**
36
- * Start passwordless flow sending an email.
37
- *
38
- * Given the user `email` address, it will send an email with:
39
- *
40
- * <ul>
41
- * <li>A link (default, `send:"link"`). You can then authenticate with this
42
- * user opening the link and he will be automatically logged in to the
43
- * application. Optionally, you can append/override parameters to the link
44
- * (like `scope`, `redirect_uri`, `protocol`, `response_type`, etc.) using
45
- * `authParams` object.
46
- * </li>
47
- * <li>
48
- * A verification code (`send:"code"`). You can then authenticate with
49
- * this user using the `/oauth/token` endpoint specifying `email` as
50
- * `username` and `code` as `password`.
51
- * </li>
52
- * </ul>
53
- *
54
- * See: https://auth0.com/docs/api/authentication#get-code-or-link
55
- *
56
- * @example
57
- * ```js
58
- * const auth0 = new AuthenticationApi({
59
- * domain: 'my-domain.auth0.com',
60
- * clientId: 'myClientId',
61
- * clientSecret: 'myClientSecret'
62
- * });
63
- *
64
- * await auth0.passwordless.sendEmail({
65
- * email: '{EMAIL}',
66
- * send: 'link',
67
- * authParams: {} // Optional auth params.
68
- * });
69
- * ```
70
- */
71
- sendEmail(bodyParameters, initOverrides) {
72
- return __awaiter(this, void 0, void 0, function* () {
73
- (0, runtime_js_1.validateRequiredRequestParams)(bodyParameters, ["email"]);
74
- const response = yield this.request({
75
- path: "/passwordless/start",
76
- method: "POST",
77
- headers: {
78
- "Content-Type": "application/json",
79
- },
80
- body: yield this.addClientAuthentication(Object.assign({ client_id: this.clientId, connection: "email" }, bodyParameters)),
81
- }, initOverrides);
82
- return runtime_js_1.VoidApiResponse.fromResponse(response);
83
- });
84
- }
85
- /**
86
- * Start passwordless flow sending an SMS.
87
- *
88
- * Given the user `phone_number`, it will send a SMS message with a
89
- * verification code. You can then authenticate with this user using the
90
- * `/oauth/token` endpoint specifying `phone_number` as `username` and `code` as
91
- * `password`:
92
- *
93
- * See: https://auth0.com/docs/api/authentication#get-code-or-link
94
- *
95
- * @example
96
- * ```js
97
- * const auth0 = new AuthenticationApi({
98
- * domain: 'my-domain.auth0.com',
99
- * clientId: 'myClientId',
100
- * clientSecret: 'myClientSecret'
101
- * });
102
- *
103
- * await auth0.passwordless.sendSMS({
104
- * phone_number: '{PHONE}'
105
- * });
106
- * ```
107
- */
108
- sendSMS(bodyParameters, initOverrides) {
109
- return __awaiter(this, void 0, void 0, function* () {
110
- (0, runtime_js_1.validateRequiredRequestParams)(bodyParameters, ["phone_number"]);
111
- const response = yield this.request({
112
- path: "/passwordless/start",
113
- method: "POST",
114
- headers: {
115
- "Content-Type": "application/json",
116
- },
117
- body: yield this.addClientAuthentication(Object.assign({ client_id: this.clientId, connection: "sms" }, bodyParameters)),
118
- }, initOverrides);
119
- return runtime_js_1.VoidApiResponse.fromResponse(response);
120
- });
121
- }
122
- /**
123
- * Once you have a verification code, use this endpoint to login the user with their email and verification code.
124
- *
125
- * @example
126
- * ```js
127
- * const auth0 = new AuthenticationApi({
128
- * domain: 'my-domain.auth0.com',
129
- * clientId: 'myClientId',
130
- * clientSecret: 'myClientSecret'
131
- * });
132
- *
133
- * await auth0.passwordless.loginWithEmail({
134
- * email: 'foo@example.com',
135
- * code: 'ABC123'
136
- * });
137
- * ```
138
- */
139
- loginWithEmail(bodyParameters_1) {
140
- return __awaiter(this, arguments, void 0, function* (bodyParameters, options = {}) {
141
- (0, runtime_js_1.validateRequiredRequestParams)(bodyParameters, ["email", "code"]);
142
- const { email: username, code: otp } = bodyParameters, otherParams = __rest(bodyParameters, ["email", "code"]);
143
- return (0, base_auth_api_js_1.grant)("http://auth0.com/oauth/grant-type/passwordless/otp", yield this.addClientAuthentication(Object.assign({ username,
144
- otp, realm: "email" }, otherParams)), options, this.clientId, this.idTokenValidator, this.request.bind(this));
145
- });
146
- }
147
- /**
148
- * Once you have a verification code, use this endpoint to login the user with their phone number and verification code.
149
- *
150
- * @example
151
- * ```js
152
- * const auth0 = new AuthenticationApi({
153
- * domain: 'my-domain.auth0.com',
154
- * clientId: 'myClientId',
155
- * clientSecret: 'myClientSecret'
156
- * });
157
- *
158
- * await auth0.passwordless.loginWithSMS({
159
- * phone_number: '0777777777',
160
- * code: 'ABC123'
161
- * });
162
- * ```
163
- */
164
- loginWithSMS(bodyParameters_1) {
165
- return __awaiter(this, arguments, void 0, function* (bodyParameters, options = {}) {
166
- (0, runtime_js_1.validateRequiredRequestParams)(bodyParameters, ["phone_number", "code"]);
167
- const { phone_number: username, code: otp } = bodyParameters, otherParams = __rest(bodyParameters, ["phone_number", "code"]);
168
- return (0, base_auth_api_js_1.grant)("http://auth0.com/oauth/grant-type/passwordless/otp", yield this.addClientAuthentication(Object.assign({ username,
169
- otp, realm: "sms" }, otherParams)), options, this.clientId, this.idTokenValidator, this.request.bind(this));
170
- });
171
- }
172
- }
173
- exports.Passwordless = Passwordless;