UNPKG

38 kBTypeScriptView Raw
1// Type definitions for Auth0.js 9.14
2// Project: https://github.com/auth0/auth0.js
3// Definitions by: Adrian Chia <https://github.com/adrianchia>
4// Matt Durrant <https://github.com/mdurrant>
5// Peter Blazejewicz <https://github.com/peterblazejewicz>
6// Bartosz Kotrys <https://github.com/bkotrys>
7// Mark Nelissen <https://github.com/marknelissen>
8// Tyler Lindell <https://github.com/tylerlindell>
9// Henri Kinnunen <https://github.com/hequ>
10// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
11/// <reference lib="dom" />
12export as namespace auth0;
13
14export class Authentication {
15 constructor(options: AuthOptions);
16
17 passwordless: PasswordlessAuthentication;
18 dbConnection: DBConnection;
19
20 /**
21 * Builds and returns the `/authorize` url in order to initialize a new authN/authZ transaction
22 *
23 * @param options: https://auth0.github.io/auth0.js/global.html#buildAuthorizeUrl
24 * @see {@link https://auth0.com/docs/api/authentication#authorize-client}
25 * @see {@link https://auth0.com/docs/api/authentication#social}
26 */
27 buildAuthorizeUrl(options: AuthorizeUrlOptions): string;
28
29 /**
30 * Builds and returns the Logout url in order to initialize a new authN/authZ transaction
31 *
32 * @param options: https://auth0.com/docs/api/authentication#!#get--v2-logout
33 */
34 buildLogoutUrl(options?: LogoutOptions): string;
35
36 /**
37 * Makes a call to the `oauth/token` endpoint with `password` grant type
38 *
39 * @param options: https://auth0.com/docs/api-auth/grant/password
40 */
41 loginWithDefaultDirectory(options: DefaultDirectoryLoginOptions, callback: Auth0Callback<any>): void;
42
43 /**
44 * Makes a call to the `/ro` endpoint
45 * @deprecated `loginWithResourceOwner` will be soon deprecated, user `login` instead.
46 */
47 loginWithResourceOwner(options: ResourceOwnerLoginOptions, callback: Auth0Callback<any>): void;
48
49 /**
50 * Makes a call to the `oauth/token` endpoint with `password-realm` grant type
51 */
52 login(options: DefaultLoginOptions, callback: Auth0Callback<any>): void;
53
54 /**
55 * Makes a call to the `oauth/token` endpoint
56 */
57 oauthToken(options: any, callback: Auth0Callback<any>): void;
58
59 /**
60 * Makes a call to the `/ssodata` endpoint
61 *
62 */
63 getSSOData(callback?: Auth0Callback<SsoDataResult | undefined>): void;
64
65 /**
66 * Makes a call to the `/ssodata` endpoint
67 *
68 */
69 getSSOData(withActiveDirectories: boolean, callback?: Auth0Callback<SsoDataResult | undefined>): void;
70
71 /**
72 * Makes a call to the `/userinfo` endpoint and returns the user profile
73 *
74 */
75 userInfo(accessToken: string, callback: Auth0Callback<Auth0UserProfile>): void;
76
77 /**
78 * Makes a call to the `/delegation` endpoint
79 *
80 * @param options: https://auth0.com/docs/api/authentication#!#post--delegation
81 */
82 delegation(options: DelegationOptions, callback: Auth0Callback<Auth0DelegationToken>): any;
83
84 /**
85 * Fetches the user country based on the ip.
86 *
87 */
88 getUserCountry(callback: Auth0Callback<{ countryCode: string }>): void;
89}
90
91export class PasswordlessAuthentication {
92 constructor(request: any, option: any);
93
94 /**
95 * Builds and returns the passwordless TOTP verify url in order to initialize a new authN/authZ transaction
96 *
97 */
98 buildVerifyUrl(options: PasswordlessVerifyOptions): string;
99
100 /**
101 * Initializes a new passwordless authN/authZ transaction
102 *
103 * @param options: https://auth0.com/docs/api/authentication#passwordless
104 */
105 start(options: PasswordlessStartOptions, callback: Auth0Callback<any>): void;
106
107 /**
108 * Verifies the passwordless TOTP and returns an error if any.
109 *
110 */
111 verify(options: PasswordlessVerifyOptions, callback: Auth0Callback<any>): void;
112}
113
114export class DBConnection {
115 constructor(request: any, option: any);
116
117 /**
118 * Creates a new user in a Auth0 Database connection
119 * @param options https://auth0.com/docs/api/authentication#signup
120 */
121 signup(options: DbSignUpOptions, callback: Auth0Callback<DbSignUpResults>): void;
122
123 /**
124 * Initializes the change password flow
125 *
126 * @param options: https://auth0.com/docs/api/authentication#!#post--dbconnections-change_password
127 */
128 changePassword(options: ChangePasswordOptions, callback: Auth0Callback<any>): void;
129}
130
131export class Management {
132 /**
133 * Initialize your client class, by using a Non Interactive Client to fetch an access_token via the Client Credentials Grant.
134 */
135 constructor(options: ManagementOptions);
136
137 /**
138 * Returns the user profile. https://auth0.com/docs/api/management/v2#!/Users/get_users_by_id
139 *
140 */
141 getUser(userId: string, callback: Auth0Callback<Auth0UserProfile>): void;
142
143 /**
144 * Updates the user metadata. It will patch the user metadata with the attributes sent.
145 * https://auth0.com/docs/api/management/v2#!/Users/patch_users_by_id
146 *
147 */
148 patchUserMetadata(userId: string, userMetadata: any, callback: Auth0Callback<Auth0UserProfile>): void;
149 /**
150 * Updates the user attributes.
151 * It will patch the root attributes that the server allows it.
152 * {@link https://auth0.com/docs/api/management/v2#!/Users/patch_users_by_id}
153 */
154 patchUserAttributes(userId: string, user: Auth0UserProfile, callback: Auth0Callback<Auth0UserProfile>): void;
155 /**
156 * Link two users. https://auth0.com/docs/api/management/v2#!/Users/post_identities
157 *
158 */
159 linkUser(userId: string, secondaryUserToken: string, callback: Auth0Callback<any>): void;
160}
161
162export class WebAuth {
163 constructor(options: AuthOptions);
164 client: Authentication;
165 popup: Popup;
166 redirect: Redirect;
167 crossOriginAuthentication: CrossOriginAuthentication;
168
169 /**
170 * Redirects to the hosted login page (`/authorize`) in order to initialize a new authN/authZ transaction
171 *
172 * @param options: https://auth0.com/docs/api/authentication#!#get--authorize_db
173 */
174 authorize(options?: AuthorizeOptions): void;
175
176 /**
177 * Parse the url hash and extract the returned tokens depending on the transaction.
178 *
179 * Only validates id_tokens signed by Auth0 using the RS256 algorithm using the public key exposed
180 * by the `/.well-known/jwks.json` endpoint. Id tokens signed with other algorithms will not be
181 * accepted.
182 *
183 * @param callback: any(err, token_payload)
184 */
185 parseHash(callback: Auth0Callback<Auth0DecodedHash | null, Auth0ParseHashError>): void;
186
187 /**
188 * Parse the url hash and extract the returned tokens depending on the transaction.
189 *
190 * Only validates id_tokens signed by Auth0 using the RS256 algorithm using the public key exposed
191 * by the `/.well-known/jwks.json` endpoint. Id tokens signed with other algorithms will not be
192 * accepted.
193 *
194 * @param callback: any(err, token_payload)
195 */
196 parseHash(options: ParseHashOptions, callback: Auth0Callback<Auth0DecodedHash | null, Auth0ParseHashError>): void;
197
198 /**
199 * Decodes the id_token and verifies the nonce.
200 *
201 * @param callback: function(err, {payload, transaction})
202 */
203 validateToken(token: string, nonce: string, callback: Auth0Callback<any>): void;
204
205 /**
206 * Executes a silent authentication transaction under the hood in order to fetch a new tokens for the current session.
207 * This method requires that all Auth is performed with {@link authorize}
208 * Watch out! If you're not using the hosted login page to do social logins, you have to use your own [social connection keys](https://manage.auth0.com/#/connections/social).
209 * If you use Auth0's dev keys, you'll always get `login_required` as an error when calling this method.
210 *
211 * @param options: any valid oauth2 parameter to be sent to the `/authorize` endpoint
212 */
213 renewAuth(options: RenewAuthOptions, callback: Auth0Callback<any>): void;
214
215 /**
216 * Initialices a change password transaction
217 *
218 * @param options: https://auth0.com/docs/api/authentication#!#post--dbconnections-change_password
219 */
220 changePassword(options: ChangePasswordOptions, callback: Auth0Callback<any>): void;
221
222 /**
223 * Signs up a new user
224 *
225 * @param options: https://auth0.com/docs/api/authentication#!#post--dbconnections-signup
226 */
227 signup(options: DbSignUpOptions, callback: Auth0Callback<any>): void;
228
229 /**
230 * Signs up a new user, automatically logs the user in after the signup and returns the user token.
231 * The login will be done using /oauth/token with password-realm grant type.
232 *
233 * @param options: https://auth0.com/docs/api/authentication#!#post--dbconnections-signup
234 */
235 signupAndAuthorize(options: DbSignUpOptions, callback: Auth0Callback<any>): void;
236
237 /**
238 * Logs in the user with username and password using the cross origin authentication (/co/authenticate) flow.
239 * You can use either `username` or `email` to identify the user, but `username` will take precedence over `email`.
240 *
241 * This only works when 3rd party cookies are enabled in the browser.
242 * After the /co/authenticate call, you'll have to use the {@link parseHash} function at the `redirectUri` specified in the constructor.
243 *
244 * @param options options used in the {@link authorize} call after the login_ticket is acquired
245 * @param cb Callback function called only when an authentication error, like invalid username or password, occurs.
246 * For other types of errors, there will be a redirect to the `redirectUri`.
247 */
248 login(options: CrossOriginLoginOptions, callback: Auth0Callback<any>): void;
249
250 /**
251 * Runs the callback code for the cross origin authentication call.
252 * This method is meant to be called by the cross origin authentication callback url.
253 * @deprecated Use {@link crossOriginVerification} instead.
254 */
255 crossOriginAuthenticationCallback(): void;
256
257 /**
258 * Runs the callback code for the cross origin authentication call.
259 * This method is meant to be called by the cross origin authentication callback url.
260 */
261 crossOriginVerification(): void;
262
263 /**
264 * Redirects to the auth0 logout endpoint
265 *
266 * If you want to navigate the user to a specific URL after the logout, set that URL at the returnTo parameter. The URL should be included in any the appropriate Allowed Logout URLs list:
267 *
268 * - If the client_id parameter is included, the returnTo URL must be listed in the Allowed Logout URLs set at the client level (see Setting Allowed Logout URLs at the App Level).
269 * - If the client_id parameter is NOT included, the returnTo URL must be listed in the Allowed Logout URLs set at the account level (see Setting Allowed Logout URLs at the Account Level).
270 *
271 * @see {@link https://auth0.com/docs/api/authentication#logout}
272 */
273 logout(options: LogoutOptions): void;
274
275 /**
276 * Initialices a passwordless authentication transaction
277 *
278 * @param options: https://auth0.com/docs/api/authentication#passwordless
279 */
280 passwordlessStart(options: PasswordlessStartOptions, callback: Auth0Callback<any>): void;
281
282 /**
283 * Verifies the passwordless TOTP and redirects to finish the passwordless transaction
284 *
285 * @param options:
286 */
287 passwordlessVerify(options: PasswordlessVerifyOptions, callback: Auth0Callback<any>): void;
288
289 /**
290 * Logs in a user with the verification code sent to the user
291 * @param options
292 * @param callback
293 */
294 passwordlessLogin(options: PasswordlessLoginOptions, callback: Auth0Callback<any>): void;
295
296 /**
297 * Renews an existing session on Auth0's servers using `response_mode=web_message` (i.e. Auth0's hosted login page)
298 *
299 * @param options options used in {@link authorize} call
300 * @param cb
301 * @see {@link https://auth0.com/docs/libraries/auth0js/v9#using-checksession-to-acquire-new-tokens}
302 */
303 checkSession(options: CheckSessionOptions, cb: Auth0Callback<any>): void;
304
305 /**
306 * Renders the captcha challenge in the provided element.
307 * This function can only be used in the context of a Classic Universal Login Page.
308 * @param element The element where the captcha needs to be rendered
309 * @param [options] The configuration options for the captcha
310 * @param [callback] An optional completion callback
311 *
312 * @see {@link https://auth0.github.io/auth0.js/WebAuth.html#renderCaptcha}
313 */
314 renderCaptcha(element: HTMLElement, options?: CatpchaConfiguration, callback?: Auth0Callback<any>): Captcha;
315}
316
317export class Redirect {
318 constructor(client: any, options: any);
319
320 /**
321 * Performs authentication with username/email and password with a database connection
322 *
323 * This method is not compatible with API Auth so if you need to fetch API tokens with audience
324 * you should use {@link authorize} or {@link login}.
325 */
326 loginWithCredentials(
327 options: {
328 /** url that the Auth0 will redirect after Auth with the Authorization Response */
329 redirectUri?: string | undefined;
330 /** type of the response used. It can be any of the values `code` and `token` */
331 responseType?: string | undefined;
332 /** how the AuthN response is encoded and redirected back to the client. */
333 responseMode?: "query" | "fragment" | undefined;
334 /** scopes to be requested during AuthN. e.g. `openid email` */
335 scope: string;
336 },
337 callback: Auth0Callback<any>,
338 ): void;
339
340 /**
341 * Signs up a new user and automatically logs the user in after the signup.
342 */
343 signupAndLogin(
344 options: {
345 /** user email address */
346 email: string;
347 /** user password */
348 password: string;
349 /** name of the connection where the user will be created */
350 connection: string;
351 /** allow userMetadata to be passed to signUp */
352 userMetadata?: unknown | undefined;
353 } & CrossOriginLoginOptions,
354 callback: Auth0Callback<any>,
355 ): void;
356}
357
358export class Popup {
359 constructor(client: any, options: any);
360
361 /**
362 * Returns a new instance of the popup handler
363 */
364 private buildPopupHandler(): any;
365
366 /**
367 * Initializes the popup window and returns the instance to be used later in order to avoid being blocked by the browser.
368 *
369 * @param options: receives the window height and width and any other window feature to be sent to window.open
370 */
371 preload(options: any): any;
372
373 /**
374 * Handles the popup logic for the callback page.
375 * @see {@link parseHash}
376 */
377 callback(options: {
378 /**
379 * the url hash.
380 * @default window.location.hash
381 */
382 hash: string;
383 /** value originally sent in `state` parameter to {@link authorize} to mitigate XSRF */
384 state?: string | undefined;
385 /** value originally sent in `nonce` parameter to {@link authorize} to prevent replay attacks */
386 nonce?: string | undefined;
387 /**
388 * makes parseHash perform or skip `id_token` verification.
389 * We **strongly** recommend validating the `id_token` yourself if you disable the verification.
390 */
391 _idTokenVerification?: string | undefined;
392 }): void;
393
394 /**
395 * Shows inside a new window the hosted login page (`/authorize`) in order to start a new authN/authZ transaction and post its result using `postMessage`.
396 * @see {@link https://auth0.com/docs/api/authentication#authorize-client}
397 */
398 authorize(
399 options: {
400 /** your Auth0 domain */
401 domain: string;
402 /** your Auth0 client identifier obtained when creating the client in the Auth0 Dashboard */
403 clientId?: string | undefined;
404 /**
405 * identity provider whose login page will be displayed in the popup.
406 * If omitted the hosted login page is used.
407 * {@link https://auth0.com/docs/identityproviders}
408 */
409 connection?: string | undefined;
410 /** url that the Auth0 will redirect after Auth with the Authorization Response */
411 redirectUri: string;
412 /**
413 * type of the response used by OAuth 2.0 flow.
414 * It can be any space separated list of the values `code`, `token`, `id_token`.
415 * {@link https://openid.net/specs/oauth-v2-multiple-response-types-1_0}
416 */
417 responseType: string;
418 /**
419 * how the Auth response is encoded and redirected back to the client.
420 * {@link https://openid.net/specs/oauth-v2-multiple-response-types-1_0.html#ResponseModes}
421 */
422 responseMode?: "query" | "fragment" | "form_post" | undefined;
423 /**
424 * value used to mitigate XSRF attacks.
425 * {@link https://auth0.com/docs/protocols/oauth2/oauth-state}
426 */
427 state?: string | undefined;
428 /**
429 * value used to mitigate replay attacks when using Implicit Grant.
430 * {@link https://auth0.com/docs/api-auth/tutorials/nonce}
431 */
432 nonce?: string | undefined;
433 /** scopes to be requested during Auth. e.g. `openid email` */
434 scope?: string | undefined;
435 /** identifier of the resource server who will consume the access token issued after Auth */
436 audience?: string | undefined;
437 /** determines if Auth0 should render the relay page or not and the caller is responsible of handling the response. */
438 owp?: boolean | undefined;
439 },
440 callback: Auth0Callback<Auth0Result>,
441 ): void;
442
443 /**
444 * Performs authentication with username/email and password with a database connection inside a new window
445 *
446 * This method is not compatible with API Auth so if you need to fetch API tokens with audience
447 * you should use {@link authorize} or {@link login}.
448 */
449 loginWithCredentials(
450 options: {
451 /** url that the Auth0 will redirect after Auth with the Authorization Response */
452 redirectUri?: string | undefined;
453 /** type of the response used. */
454 responseType?: "code" | "token" | undefined;
455 /** how the AuthN response is encoded and redirected back to the client. */
456 responseMode?: "query" | "fragment" | undefined;
457 /** scopes to be requested during AuthN. e.g. `openid email` */
458 scope?: string | undefined;
459 },
460 callback: Auth0Callback<any>,
461 ): void;
462
463 /**
464 * Verifies the passwordless TOTP and returns the requested token
465 */
466 passwordlessVerify(
467 options: {
468 type: "sms" | "email";
469 /** only if type = sms */
470 phoneNumber?: string | undefined;
471 /** only if type = email */
472 email?: string | undefined;
473 /** the connection name */
474 connection: string;
475 /** the TOTP code */
476 verificationCode: string;
477 },
478 callback: Auth0Callback<any>,
479 ): void;
480
481 /**
482 * Signs up a new user and automatically logs the user in after the signup.
483 *
484 * This method is not compatible with API Auth so if you need to fetch API tokens with audience
485 * you should use {@link authorize} or {@link signupAndAuthorize}.
486 */
487 signupAndLogin(
488 options: {
489 /** user email address */
490 email: string;
491 /** user password */
492 password: string;
493 /** name of the connection where the user will be created */
494 connection: string;
495 /** allow userMetadata to be passed to signUp */
496 userMetadata?: unknown | undefined;
497 },
498 callback: Auth0Callback<any>,
499 ): void;
500}
501
502export class CrossOriginAuthentication {
503 constructor(webAuth: any, options: any);
504
505 /**
506 * Logs in the user with username and password using the cross origin authentication (/co/authenticate) flow.
507 * You can use either `username` or `email` to identify the user, but `username` will take precedence over `email`.
508 * This only works when 3rd party cookies are enabled in the browser.
509 * After the /co/authenticate call, you'll have to use the {@link parseHash} function at the `redirectUri` specified in the constructor.
510 *
511 * @param options options used in the {@link authorize} call after the login_ticket is acquired
512 * @param cb Callback function called only when an authentication error, like invalid username or password, occurs.
513 * For other types of errors, there will be a redirect to the `redirectUri`.
514 */
515 login(options: CrossOriginLoginOptions, callback: Auth0Callback<any>): void;
516
517 /**
518 * Runs the callback code for the cross origin authentication call. This method is meant to be called by the cross origin authentication callback url.
519 *
520 */
521 callback(): void;
522}
523
524export type Auth0Callback<T, E = Auth0Error> = (error: null | E, result: T) => void;
525
526export interface TokenProvider {
527 enableCache?: boolean | undefined;
528 cacheTTLInSeconds?: number | undefined;
529}
530
531export interface ManagementOptions {
532 domain: string;
533 token?: string | undefined;
534 clientId?: string | undefined;
535 clientSecret?: string | undefined;
536 audience?: string | undefined;
537 scope?: string | undefined;
538 tokenProvider?: TokenProvider | undefined;
539 telemetry?: boolean | undefined;
540}
541
542export interface AuthOptions {
543 domain: string;
544 clientID: string;
545 responseType?: string | undefined;
546 responseMode?: string | undefined;
547 redirectUri?: string | undefined;
548 scope?: string | undefined;
549 audience?: string | undefined;
550 /**
551 * maximum elapsed time in seconds since the last time the user
552 * was actively authenticated by the authorization server.
553 */
554 maxAge?: number | undefined;
555 leeway?: number | undefined;
556 jwksURI?: string | undefined;
557 overrides?: {
558 __tenant?: string | undefined;
559 __token_issuer?: string | undefined;
560 __jwks_uri?: string | undefined;
561 } | undefined;
562 plugins?: any;
563 popupOrigin?: string | undefined;
564 protocol?: string | undefined;
565 response_type?: string | undefined;
566 state?: string | undefined;
567 tenant?: string | undefined;
568 universalLoginPage?: boolean | undefined;
569 _csrf?: string | undefined;
570 _intstate?: string | undefined;
571 _timesToRetryFailedRequests?: number | undefined;
572 _disableDeprecationWarnings?: boolean | undefined;
573 _sendTelemetry?: boolean | undefined;
574 _telemetryInfo?: any;
575 __tryLocalStorageFirst?: boolean | undefined;
576}
577
578export type DoneCallback = (err?: Auth0Error) => void;
579
580export interface Captcha {
581 reload: (done: DoneCallback) => void;
582 getValue: () => string;
583}
584
585export interface CatpchaConfiguration {
586 /**
587 * An object containaing templates for each captcha provider
588 */
589 templates?: CaptchaTemplates | undefined;
590
591 /**
592 * The ISO code of the language for recaptcha
593 * @default 'en'
594 */
595 lang?: string | undefined;
596}
597
598/**
599 * An object containing templates for a captcha provider
600 */
601export interface CaptchaTemplates {
602 /**
603 * Template function receiving the challenge and returning an string
604 */
605 auth0?: ((challenge: Auth0Challenge) => string) | undefined;
606
607 /**
608 * Template function receiving the challenge and returning an string
609 */
610 recaptcha_v2?: ((challenge: Auth0Challenge) => string) | undefined;
611
612 error: (error: Error) => string;
613}
614
615export interface Auth0Challenge {
616 type: "code";
617 image: string;
618 required: boolean;
619 provider: "auth0" | "recaptcha_v2";
620 [other: string]: unknown;
621}
622
623export interface PasswordlessAuthOptions {
624 connection: string;
625 verificationCode: string;
626 phoneNumber: string;
627 email: string;
628}
629
630/**
631 * These are error codes defined by the auth0-js lib.
632 */
633export type LibErrorCodes = "timeout" | "request_error" | "invalid_token";
634
635/**
636 * The user was not logged in at Auth0, so silent authentication is not possible.
637 */
638export type LoginRequiredErrorCode = "login_required";
639
640/**
641 * The user was logged in at Auth0 and has authorized the application, but needs to
642 * be redirected elsewhere before authentication can be completed; for example, when
643 * using a redirect rule.
644 */
645export type InteractionRequiredErrorCode = "interaction_required";
646
647/**
648 * The user was logged in at Auth0, but needs to give consent to authorize the application.
649 */
650export type ConsentRequiredErrorCode = "consent_required";
651
652/**
653 * These are error codes defined by the OpenID Connect specification.
654 */
655export type SpecErrorCodes =
656 | LoginRequiredErrorCode
657 | InteractionRequiredErrorCode
658 | ConsentRequiredErrorCode
659 | "account_selection_required"
660 | "invalid_request_uri"
661 | "invalid_request_object"
662 | "request_not_supported"
663 | "request_uri_not_supported"
664 | "registration_not_supported";
665
666export interface Auth0Error {
667 error: LibErrorCodes | SpecErrorCodes | string;
668 errorDescription?: string | undefined;
669 // Auth0 is not consistent in the naming of the error description field
670 error_description?: string | undefined;
671 // Need to include non-intuitive error fields that Auth0 uses
672 code?: string | undefined;
673 description?: string | undefined;
674 name?: string | undefined;
675 policy?: string | undefined;
676 original?: any;
677 statusCode?: number | undefined;
678 statusText?: string | undefined;
679}
680
681/**
682 * result of the Auth request.
683 * If there is no token available, this value will be null.
684 */
685export interface Auth0Result {
686 /**
687 * token that allows access to the specified resource server (identified by the audience parameter
688 * or by default Auth0's /userinfo endpoint)
689 */
690 accessToken?: string | undefined;
691 /** number of seconds until the access token expires */
692 expiresIn?: number | undefined;
693 /** token that identifies the user */
694 idToken?: string | undefined;
695 /**
696 * token that can be used to get new access tokens from Auth0.
697 * Note that not all Auth0 Applications can request them
698 * or the resource server might not allow them.
699 */
700 refreshToken?: string | undefined;
701 /** values that you receive back on the authentication response */
702 appState?: any;
703}
704
705export type Auth0ParseHashError = Auth0Error & {
706 state?: string | undefined;
707};
708
709/**
710 * The contents of the authResult object returned by {@link WebAuth#parseHash }
711 */
712export interface Auth0DecodedHash {
713 accessToken?: string | undefined;
714 idToken?: string | undefined;
715 idTokenPayload?: any;
716 appState?: any;
717 refreshToken?: string | undefined;
718 state?: string | undefined;
719 expiresIn?: number | undefined;
720 tokenType?: string | undefined;
721 scope?: string | undefined;
722}
723
724/** Represents the response from an API Token Delegation request. */
725export interface Auth0DelegationToken {
726 /** The length of time in seconds the token is valid for. */
727 expiresIn: number;
728 /** The JWT for delegated access. */
729 idToken: string;
730 /** The type of token being returned. Possible values: "Bearer" */
731 tokenType: string;
732}
733
734export interface ChangePasswordOptions {
735 connection: string;
736 email: string;
737}
738
739export interface BaseAuthOptions {
740 clientID?: string | undefined;
741 responseType?: string | undefined;
742 redirectUri?: string | undefined;
743 scope?: string | undefined;
744 audience?: string | undefined;
745 state?: string | undefined;
746 nonce?: string | undefined;
747 _csrf?: string | undefined;
748 __instate?: string | undefined;
749}
750
751export interface PasswordlessStartAuthParams extends BaseAuthOptions {
752 responseMode?: string | undefined;
753}
754
755export interface PasswordlessStartOptions {
756 connection: string;
757 send: string;
758 phoneNumber?: string | undefined;
759 email?: string | undefined;
760 authParams?: PasswordlessStartAuthParams | undefined;
761}
762
763export interface PasswordlessVerifyOptions extends BaseAuthOptions {
764 connection: string;
765 verificationCode: string;
766 phoneNumber?: string | undefined;
767 email?: string | undefined;
768 send?: string | undefined;
769 responseMode?: string | undefined;
770}
771
772export interface PasswordlessLoginOptions extends BaseAuthOptions {
773 connection: string;
774 verificationCode: string;
775 phoneNumber?: string | undefined;
776 email?: string | undefined;
777}
778
779export interface Auth0UserProfile {
780 name: string;
781 nickname: string;
782 picture: string;
783 user_id: string;
784 username?: string | undefined;
785 given_name?: string | undefined;
786 family_name?: string | undefined;
787 email?: string | undefined;
788 email_verified?: boolean | undefined;
789 clientID: string;
790 gender?: string | undefined;
791 locale?: string | undefined;
792 identities: Auth0Identity[];
793 created_at: string;
794 updated_at: string;
795 sub: string;
796 user_metadata?: any;
797 app_metadata?: any;
798}
799
800export interface MicrosoftUserProfile extends Auth0UserProfile {
801 emails?: string[] | undefined; // optional depending on whether email addresses permission is granted
802}
803
804export interface Office365UserProfile extends Auth0UserProfile {
805 tenantid: string;
806 upn: string;
807}
808
809export interface AdfsUserProfile extends Auth0UserProfile {
810 issuer?: string | undefined;
811}
812
813export interface AuthorizeUrlOptions {
814 /**
815 * your Auth0 client identifier obtained when creating the client in the Auth0 Dashboard
816 */
817 clientID?: string | undefined;
818 /**
819 * url that the Auth0 will redirect after Auth with the Authorization Response
820 */
821 redirectUri: string;
822 /**
823 * type of the response used by OAuth 2.0 flow. It can be any space separated
824 * list of the values `code`, `token`, `id_token`.
825 * {@link https://openid.net/specs/oauth-v2-multiple-response-types-1_0}
826 */
827 responseType: string;
828 /**
829 * how the Auth response is encoded and redirected back to the client.
830 * Supported values are `query`, `fragment` and `form_post`
831 * {@link https://openid.net/specs/oauth-v2-multiple-response-types-1_0.html#ResponseModes}
832 */
833 responseMode?: "query" | "fragment" | "form_post" | undefined;
834 /**
835 * value used to mitigate XSRF attacks.
836 * {@link https://auth0.com/docs/protocols/oauth2/oauth-state}
837 */
838 state?: string | undefined;
839 /**
840 * value used to mitigate replay attacks when using Implicit Grant.
841 * {@link https://auth0.com/docs/api-auth/tutorials/nonce}
842 */
843 nonce?: string | undefined;
844 /**
845 * scopes to be requested during Auth. e.g. `openid email`
846 */
847 scope?: string | undefined;
848 /**
849 * identifier of the resource server who will consume the access token issued after Auth
850 */
851 audience?: string | undefined;
852}
853
854export interface Auth0Identity {
855 connection: string;
856 isSocial: boolean;
857 provider: string;
858 user_id: string;
859}
860
861export interface LoginOptions {
862 username: string;
863 password: string;
864 scope?: string | undefined;
865}
866
867export interface DefaultLoginOptions extends LoginOptions {
868 audience?: string | undefined;
869 realm: string;
870}
871
872export interface DefaultDirectoryLoginOptions extends LoginOptions {
873 audience?: string | undefined;
874}
875
876export interface ResourceOwnerLoginOptions extends LoginOptions {
877 connection: string;
878 device?: string | undefined;
879}
880
881export interface CrossOriginLoginOptions {
882 username?: string | undefined;
883 email?: string | undefined;
884 password: string;
885 realm?: string | undefined;
886 domain?: string | undefined;
887 clientID?: string | undefined;
888 redirectUri?: string | undefined;
889 responseType?: string | undefined;
890 responseMode?: string | undefined;
891 state?: string | undefined;
892 nonce?: string | undefined;
893 scope?: string | undefined;
894 audience?: string | undefined;
895 onRedirecting?: (done: () => void) => void | undefined;
896}
897
898export interface LogoutOptions {
899 clientID?: string | undefined;
900 returnTo?: string | undefined;
901 federated?: boolean | undefined;
902}
903
904export interface DelegationOptions {
905 client_id?: string | undefined;
906 grant_type: string;
907 id_token?: string | undefined;
908 refresh_token?: string | undefined;
909 target?: string | undefined;
910 scope?: string | undefined;
911 api_type?: string | undefined;
912}
913
914export interface DbSignUpOptions {
915 /** user email address */
916 email: string;
917 /** user password */
918 password: string;
919 /** name of the connection where the user will be created */
920 connection: string;
921 /** User desired username. Required if you use a database connection and you have enabled `Requires Username` */
922 username?: string | undefined;
923 scope?: string | undefined;
924 /** additional signup attributes used for creating the user. Will be stored in `user_metadata` */
925 userMetadata?: unknown | undefined;
926}
927
928/** result of the signup request */
929export interface DbSignUpResults {
930 /** user's email */
931 email: string;
932 /** if the user's email was verified */
933 emailVerified: boolean;
934}
935
936export interface ParseHashOptions {
937 hash?: string | undefined;
938 state?: string | undefined;
939 nonce?: string | undefined;
940 _idTokenVerification?: boolean | undefined;
941 /** indicates that you want to allow IdP-Initiated flows. See {@link https://auth0.com/docs/protocols/saml/idp-initiated-sso#lock-auth0-js} */
942 __enableIdPInitiatedLogin?: boolean | undefined;
943}
944
945export interface RenewAuthOptions {
946 /**
947 * your Auth0 domain
948 */
949 domain?: string | undefined;
950 /**
951 * your Auth0 client identifier obtained when creating the client in the Auth0 Dashboard
952 */
953 clientID?: string | undefined;
954 /**
955 * url that the Auth0 will redirect after Auth with the Authorization Response
956 */
957 redirectUri?: string | undefined;
958 /**
959 * type of the response used by OAuth 2.0 flow. It can be any space separated
960 * list of the values `code`, `token`, `id_token`.
961 * {@link https://openid.net/specs/oauth-v2-multiple-response-types-1_0.html}
962 */
963 responseType?: string | undefined;
964 /**
965 * how the Auth response is encoded and redirected back to the client.
966 * Supported values are `query`, `fragment` and `form_post`.
967 * The `query` value is only supported when `responseType` is `code`.
968 * {@link https://openid.net/specs/oauth-v2-multiple-response-types-1_0.html#ResponseModes}
969 */
970 responseMode?: string | undefined;
971 /**
972 * value used to mitigate XSRF attacks.
973 * {@link https://auth0.com/docs/protocols/oauth2/oauth-state}
974 */
975 state?: string | undefined;
976 /**
977 * value used to mitigate replay attacks when using Implicit Grant.
978 * {@link https://auth0.com/docs/api-auth/tutorials/nonce}
979 */
980 nonce?: string | undefined;
981 /**
982 * scopes to be requested during Auth. e.g. `openid email`
983 */
984 scope?: string | undefined;
985 /**
986 * identifier of the resource server who will consume the access token issued after Auth
987 */
988 audience?: string | undefined;
989 /**
990 * identifier data type to look for in postMessage event data, where events are initiated
991 * from silent callback urls, before accepting a message event is the event expected.
992 * A value of false means any postMessage event will trigger a callback.
993 */
994 postMessageDataType?: string | undefined;
995 /**
996 * origin of redirectUri to expect postMessage response from.
997 * Defaults to the origin of the receiving window. Only used if usePostMessage is truthy.
998 */
999 postMessageOrigin?: string | undefined;
1000 /**
1001 * value in milliseconds used to timeout when the `/authorize` call is failing
1002 * as part of the silent authentication with postmessage enabled due to a configuration.
1003 */
1004 timeout?: number | undefined;
1005 /**
1006 * use postMessage to communicate between the silent callback and the SPA.
1007 * When false the SDK will attempt to parse the url hash should ignore the url hash
1008 * and no extra behaviour is needed
1009 * @default false
1010 */
1011 usePostMessage?: boolean | undefined;
1012}
1013
1014export interface AuthorizeOptions {
1015 domain?: string | undefined;
1016 clientID?: string | undefined;
1017 connection?: string | undefined;
1018 redirectUri?: string | undefined;
1019 responseType?: string | undefined;
1020 responseMode?: string | undefined;
1021 state?: string | undefined;
1022 nonce?: string | undefined;
1023 scope?: string | undefined;
1024 audience?: string | undefined;
1025 language?: string | undefined;
1026 login_hint?: string | undefined;
1027 prompt?: string | undefined;
1028 mode?: "login" | "signUp" | undefined;
1029 screen_hint?: "signup" | undefined;
1030 accessType?: string | undefined;
1031 approvalPrompt?: string | undefined;
1032 appState?: any;
1033 connection_scope?: string | string[] | undefined;
1034}
1035
1036export type SsoDataResult = SsoSessionFoundResult | SsoSessionNotFoundResult;
1037
1038export interface SsoSessionFoundResult {
1039 lastUsedClientID: string;
1040 lastUsedConnection: {
1041 name: string;
1042 strategy?: string | undefined;
1043 };
1044 lastUsedUserID: string;
1045 lastUsedUsername: string;
1046 sessionClients: string[];
1047 sso: true;
1048}
1049
1050export interface SsoSessionNotFoundResult {
1051 sso: false;
1052}
1053
1054export interface CheckSessionOptions extends AuthorizeOptions {
1055 /**
1056 * optional parameter for auth0 to use postMessage to communicate between the silent callback and the SPA.
1057 */
1058 usePostMessage?: boolean | undefined;
1059}
1060
1061export const version: {
1062 raw: string;
1063};