UNPKG

18.8 kBPlain TextView Raw
1import { ICache } from './cache';
2
3export interface AuthorizationParams {
4 /**
5 * - `'page'`: displays the UI with a full page view
6 * - `'popup'`: displays the UI with a popup window
7 * - `'touch'`: displays the UI in a way that leverages a touch interface
8 * - `'wap'`: displays the UI with a "feature phone" type interface
9 */
10 display?: 'page' | 'popup' | 'touch' | 'wap';
11
12 /**
13 * - `'none'`: do not prompt user for login or consent on reauthentication
14 * - `'login'`: prompt user for reauthentication
15 * - `'consent'`: prompt user for consent before processing request
16 * - `'select_account'`: prompt user to select an account
17 */
18 prompt?: 'none' | 'login' | 'consent' | 'select_account';
19
20 /**
21 * Maximum allowable elapsed time (in seconds) since authentication.
22 * If the last time the user authenticated is greater than this value,
23 * the user must be reauthenticated.
24 */
25 max_age?: string | number;
26
27 /**
28 * The space-separated list of language tags, ordered by preference.
29 * For example: `'fr-CA fr en'`.
30 */
31 ui_locales?: string;
32
33 /**
34 * Previously issued ID Token.
35 */
36 id_token_hint?: string;
37
38 /**
39 * Provides a hint to Auth0 as to what flow should be displayed.
40 * The default behavior is to show a login page but you can override
41 * this by passing 'signup' to show the signup page instead.
42 *
43 * This only affects the New Universal Login Experience.
44 */
45 screen_hint?: 'signup' | 'login' | string;
46
47 /**
48 * The user's email address or other identifier. When your app knows
49 * which user is trying to authenticate, you can provide this parameter
50 * to pre-fill the email box or select the right session for sign-in.
51 *
52 * This currently only affects the classic Lock experience.
53 */
54 login_hint?: string;
55
56 acr_values?: string;
57
58 /**
59 * The default scope to be used on authentication requests.
60 *
61 * This defaults to `profile email` if not set. If you are setting extra scopes and require
62 * `profile` and `email` to be included then you must include them in the provided scope.
63 *
64 * Note: The `openid` scope is **always applied** regardless of this setting.
65 */
66 scope?: string;
67
68 /**
69 * The default audience to be used for requesting API access.
70 */
71 audience?: string;
72
73 /**
74 * The name of the connection configured for your application.
75 * If null, it will redirect to the Auth0 Login Page and show
76 * the Login Widget.
77 */
78 connection?: string;
79
80 /**
81 * The Id of an organization to log in to.
82 *
83 * This will specify an `organization` parameter in your user's login request and will add a step to validate
84 * the `org_id` claim in your user's ID Token.
85 */
86 organization?: string;
87
88 /**
89 * The Id of an invitation to accept. This is available from the user invitation URL that is given when participating in a user invitation flow.
90 */
91 invitation?: string;
92
93 /**
94 * The default URL where Auth0 will redirect your browser to with
95 * the authentication result. It must be whitelisted in
96 * the "Allowed Callback URLs" field in your Auth0 Application's
97 * settings. If not provided here, it should be provided in the other
98 * methods that provide authentication.
99 */
100 redirect_uri?: string;
101
102 /**
103 * If you need to send custom parameters to the Authorization Server,
104 * make sure to use the original parameter name.
105 */
106 [key: string]: any;
107}
108
109interface BaseLoginOptions {
110 /**
111 * URL parameters that will be sent back to the Authorization Server. This can be known parameters
112 * defined by Auth0 or custom parameters that you define.
113 */
114 authorizationParams?: AuthorizationParams;
115}
116
117export interface Auth0ClientOptions extends BaseLoginOptions {
118 /**
119 * Your Auth0 account domain such as `'example.auth0.com'`,
120 * `'example.eu.auth0.com'` or , `'example.mycompany.com'`
121 * (when using [custom domains](https://auth0.com/docs/custom-domains))
122 */
123 domain: string;
124 /**
125 * The issuer to be used for validation of JWTs, optionally defaults to the domain above
126 */
127 issuer?: string;
128 /**
129 * The Client ID found on your Application settings page
130 */
131 clientId: string;
132 /**
133 * The value in seconds used to account for clock skew in JWT expirations.
134 * Typically, this value is no more than a minute or two at maximum.
135 * Defaults to 60s.
136 */
137 leeway?: number;
138
139 /**
140 * The location to use when storing cache data. Valid values are `memory` or `localstorage`.
141 * The default setting is `memory`.
142 *
143 * Read more about [changing storage options in the Auth0 docs](https://auth0.com/docs/libraries/auth0-single-page-app-sdk#change-storage-options)
144 */
145 cacheLocation?: CacheLocation;
146
147 /**
148 * Specify a custom cache implementation to use for token storage and retrieval. This setting takes precedence over `cacheLocation` if they are both specified.
149 */
150 cache?: ICache;
151
152 /**
153 * If true, refresh tokens are used to fetch new access tokens from the Auth0 server. If false, the legacy technique of using a hidden iframe and the `authorization_code` grant with `prompt=none` is used.
154 * The default setting is `false`.
155 *
156 * **Note**: Use of refresh tokens must be enabled by an administrator on your Auth0 client application.
157 */
158 useRefreshTokens?: boolean;
159
160 /**
161 * If true, fallback to the technique of using a hidden iframe and the `authorization_code` grant with `prompt=none` when unable to use refresh tokens. If false, the iframe fallback is not used and
162 * errors relating to a failed `refresh_token` grant should be handled appropriately. The default setting is `false`.
163 *
164 * **Note**: There might be situations where doing silent auth with a Web Message response from an iframe is not possible,
165 * like when you're serving your application from the file system or a custom protocol (like in a Desktop or Native app).
166 * In situations like this you can disable the iframe fallback and handle the failed `refresh_token` grant and prompt the user to login interactively with `loginWithRedirect` or `loginWithPopup`."
167 *
168 * E.g. Using the `file:` protocol in an Electron application does not support that legacy technique.
169 *
170 * @example
171 * let token: string;
172 * try {
173 * token = await auth0.getTokenSilently();
174 * } catch (e) {
175 * if (e.error === 'missing_refresh_token' || e.error === 'invalid_grant') {
176 * auth0.loginWithRedirect();
177 * }
178 * }
179 */
180 useRefreshTokensFallback?: boolean;
181
182 /**
183 * A maximum number of seconds to wait before declaring background calls to /authorize as failed for timeout
184 * Defaults to 60s.
185 */
186 authorizeTimeoutInSeconds?: number;
187
188 /**
189 * Specify the timeout for HTTP calls using `fetch`. The default is 10 seconds.
190 */
191 httpTimeoutInSeconds?: number;
192
193 /**
194 * Internal property to send information about the client to the authorization server.
195 * @internal
196 */
197 auth0Client?: {
198 name: string;
199 version: string;
200 env?: { [key: string]: string };
201 };
202
203 /**
204 * Sets an additional cookie with no SameSite attribute to support legacy browsers
205 * that are not compatible with the latest SameSite changes.
206 * This will log a warning on modern browsers, you can disable the warning by setting
207 * this to false but be aware that some older useragents will not work,
208 * See https://www.chromium.org/updates/same-site/incompatible-clients
209 * Defaults to true
210 */
211 legacySameSiteCookie?: boolean;
212
213 /**
214 * If `true`, the SDK will use a cookie when storing information about the auth transaction while
215 * the user is going through the authentication flow on the authorization server.
216 *
217 * The default is `false`, in which case the SDK will use session storage.
218 *
219 * @notes
220 *
221 * You might want to enable this if you rely on your users being able to authenticate using flows that
222 * may end up spanning across multiple tabs (e.g. magic links) or you cannot otherwise rely on session storage being available.
223 */
224 useCookiesForTransactions?: boolean;
225
226 /**
227 * Number of days until the cookie `auth0.is.authenticated` will expire
228 * Defaults to 1.
229 */
230 sessionCheckExpiryDays?: number;
231
232 /**
233 * The domain the cookie is accessible from. If not set, the cookie is scoped to
234 * the current domain, including the subdomain.
235 *
236 * Note: setting this incorrectly may cause silent authentication to stop working
237 * on page load.
238 *
239 *
240 * To keep a user logged in across multiple subdomains set this to your
241 * top-level domain and prefixed with a `.` (eg: `.example.com`).
242 */
243 cookieDomain?: string;
244
245 /**
246 * If true, data to the token endpoint is transmitted as x-www-form-urlencoded data, if false it will be transmitted as JSON. The default setting is `true`.
247 *
248 * **Note:** Setting this to `false` may affect you if you use Auth0 Rules and are sending custom, non-primitive data. If you disable this,
249 * please verify that your Auth0 Rules continue to work as intended.
250 */
251 useFormData?: boolean;
252
253 /**
254 * Modify the value used as the current time during the token validation.
255 *
256 * **Note**: Using this improperly can potentially compromise the token validation.
257 */
258 nowProvider?: () => Promise<number> | number;
259}
260
261/**
262 * The possible locations where tokens can be stored
263 */
264export type CacheLocation = 'memory' | 'localstorage';
265
266/**
267 * @ignore
268 */
269export interface AuthorizeOptions extends AuthorizationParams {
270 response_type: string;
271 response_mode: string;
272 redirect_uri?: string;
273 nonce: string;
274 state: string;
275 scope: string;
276 code_challenge: string;
277 code_challenge_method: string;
278}
279
280export interface RedirectLoginOptions<TAppState = any>
281 extends BaseLoginOptions {
282 /**
283 * Used to store state before doing the redirect
284 */
285 appState?: TAppState;
286 /**
287 * Used to add to the URL fragment before redirecting
288 */
289 fragment?: string;
290 /**
291 * Used to control the redirect and not rely on the SDK to do the actual redirect.
292 *
293 * @example
294 * const client = new Auth0Client({
295 * async onRedirect(url) {
296 * window.location.replace(url);
297 * }
298 * });
299 * @deprecated since v2.0.1, use `openUrl` instead.
300 */
301 onRedirect?: (url: string) => Promise<void>;
302
303 /**
304 * Used to control the redirect and not rely on the SDK to do the actual redirect.
305 *
306 * @example
307 * const client = new Auth0Client({
308 * openUrl(url) {
309 * window.location.replace(url);
310 * }
311 * });
312 *
313 * @example
314 * import { Browser } from '@capacitor/browser';
315 *
316 * const client = new Auth0Client({
317 * async openUrl(url) {
318 * await Browser.open({ url });
319 * }
320 * });
321 */
322 openUrl?: (url: string) => Promise<void> | void;
323}
324
325export interface RedirectLoginResult<TAppState = any> {
326 /**
327 * State stored when the redirect request was made
328 */
329 appState?: TAppState;
330}
331
332export interface PopupLoginOptions extends BaseLoginOptions {}
333
334export interface PopupConfigOptions {
335 /**
336 * The number of seconds to wait for a popup response before
337 * throwing a timeout error. Defaults to 60s
338 */
339 timeoutInSeconds?: number;
340
341 /**
342 * Accepts an already-created popup window to use. If not specified, the SDK
343 * will create its own. This may be useful for platforms like iOS that have
344 * security restrictions around when popups can be invoked (e.g. from a user click event)
345 */
346 popup?: any;
347}
348
349export interface GetTokenSilentlyOptions {
350 /**
351 * When `off`, ignores the cache and always sends a
352 * request to Auth0.
353 * When `cache-only`, only reads from the cache and never sends a request to Auth0.
354 * Defaults to `on`, where it both reads from the cache and sends a request to Auth0 as needed.
355 */
356 cacheMode?: 'on' | 'off' | 'cache-only';
357
358 /**
359 * Parameters that will be sent back to Auth0 as part of a request.
360 */
361 authorizationParams?: {
362 /**
363 * There's no actual redirect when getting a token silently,
364 * but, according to the spec, a `redirect_uri` param is required.
365 * Auth0 uses this parameter to validate that the current `origin`
366 * matches the `redirect_uri` `origin` when sending the response.
367 * It must be whitelisted in the "Allowed Web Origins" in your
368 * Auth0 Application's settings.
369 */
370 redirect_uri?: string;
371
372 /**
373 * The scope that was used in the authentication request
374 */
375 scope?: string;
376
377 /**
378 * The audience that was used in the authentication request
379 */
380 audience?: string;
381
382 /**
383 * If you need to send custom parameters to the Authorization Server,
384 * make sure to use the original parameter name.
385 */
386 [key: string]: any;
387 };
388
389 /** A maximum number of seconds to wait before declaring the background /authorize call as failed for timeout
390 * Defaults to 60s.
391 */
392 timeoutInSeconds?: number;
393
394 /**
395 * If true, the full response from the /oauth/token endpoint (or the cache, if the cache was used) is returned
396 * (minus `refresh_token` if one was issued). Otherwise, just the access token is returned.
397 *
398 * The default is `false`.
399 */
400 detailedResponse?: boolean;
401}
402
403export interface GetTokenWithPopupOptions extends PopupLoginOptions {
404 /**
405 * When `off`, ignores the cache and always sends a request to Auth0.
406 * When `cache-only`, only reads from the cache and never sends a request to Auth0.
407 * Defaults to `on`, where it both reads from the cache and sends a request to Auth0 as needed.
408 */
409 cacheMode?: 'on' | 'off' | 'cache-only';
410}
411
412export interface LogoutUrlOptions {
413 /**
414 * The `clientId` of your application.
415 *
416 * If this property is not set, then the `clientId` that was used during initialization of the SDK is sent to the logout endpoint.
417 *
418 * If this property is set to `null`, then no client ID value is sent to the logout endpoint.
419 *
420 * [Read more about how redirecting after logout works](https://auth0.com/docs/logout/guides/redirect-users-after-logout)
421 */
422 clientId?: string | null;
423
424 /**
425 * Parameters to pass to the logout endpoint. This can be known parameters defined by Auth0 or custom parameters
426 * you wish to provide.
427 */
428 logoutParams?: {
429 /**
430 * When supported by the upstream identity provider,
431 * forces the user to logout of their identity provider
432 * and from Auth0.
433 * [Read more about how federated logout works at Auth0](https://auth0.com/docs/logout/guides/logout-idps)
434 */
435 federated?: boolean;
436 /**
437 * The URL where Auth0 will redirect your browser to after the logout.
438 *
439 * **Note**: If the `client_id` parameter is included, the
440 * `returnTo` URL that is provided must be listed in the
441 * Application's "Allowed Logout URLs" in the Auth0 dashboard.
442 * However, if the `client_id` parameter is not included, the
443 * `returnTo` URL must be listed in the "Allowed Logout URLs" at
444 * the account level in the Auth0 dashboard.
445 *
446 * [Read more about how redirecting after logout works](https://auth0.com/docs/logout/guides/redirect-users-after-logout)
447 */
448 returnTo?: string;
449
450 /**
451 * If you need to send custom parameters to the logout endpoint, make sure to use the original parameter name.
452 */
453 [key: string]: any;
454 };
455}
456
457export interface LogoutOptions extends LogoutUrlOptions {
458 /**
459 * Used to control the redirect and not rely on the SDK to do the actual redirect.
460 *
461 * @example
462 * await auth0.logout({
463 * async onRedirect(url) {
464 * window.location.replace(url);
465 * }
466 * });
467 * @deprecated since v2.0.1, use `openUrl` instead.
468 */
469 onRedirect?: (url: string) => Promise<void>;
470
471 /**
472 * Used to control the redirect and not rely on the SDK to do the actual redirect.
473 *
474 * Set to `false` to disable the redirect, or provide a function to handle the actual redirect yourself.
475 *
476 * @example
477 * await auth0.logout({
478 * openUrl(url) {
479 * window.location.replace(url);
480 * }
481 * });
482 *
483 * @example
484 * import { Browser } from '@capacitor/browser';
485 *
486 * await auth0.logout({
487 * async openUrl(url) {
488 * await Browser.open({ url });
489 * }
490 * });
491 */
492 openUrl?: false | ((url: string) => Promise<void> | void);
493}
494
495/**
496 * @ignore
497 */
498export interface AuthenticationResult {
499 state: string;
500 code?: string;
501 error?: string;
502 error_description?: string;
503}
504
505/**
506 * @ignore
507 */
508export interface TokenEndpointOptions {
509 baseUrl: string;
510 client_id: string;
511 grant_type: string;
512 timeout?: number;
513 auth0Client: any;
514 useFormData?: boolean;
515 [key: string]: any;
516}
517
518export type TokenEndpointResponse = {
519 id_token: string;
520 access_token: string;
521 refresh_token?: string;
522 expires_in: number;
523 scope?: string;
524};
525
526/**
527 * @ignore
528 */
529export interface OAuthTokenOptions extends TokenEndpointOptions {
530 code_verifier: string;
531 code: string;
532 redirect_uri: string;
533 audience: string;
534 scope: string;
535}
536
537/**
538 * @ignore
539 */
540export interface RefreshTokenOptions extends TokenEndpointOptions {
541 refresh_token: string;
542}
543
544/**
545 * @ignore
546 */
547export interface JWTVerifyOptions {
548 iss: string;
549 aud: string;
550 id_token: string;
551 nonce?: string;
552 leeway?: number;
553 max_age?: number;
554 organizationId?: string;
555 now?: number;
556}
557
558export interface IdToken {
559 __raw: string;
560 name?: string;
561 given_name?: string;
562 family_name?: string;
563 middle_name?: string;
564 nickname?: string;
565 preferred_username?: string;
566 profile?: string;
567 picture?: string;
568 website?: string;
569 email?: string;
570 email_verified?: boolean;
571 gender?: string;
572 birthdate?: string;
573 zoneinfo?: string;
574 locale?: string;
575 phone_number?: string;
576 phone_number_verified?: boolean;
577 address?: string;
578 updated_at?: string;
579 iss?: string;
580 aud?: string;
581 exp?: number;
582 nbf?: number;
583 iat?: number;
584 jti?: string;
585 azp?: string;
586 nonce?: string;
587 auth_time?: string;
588 at_hash?: string;
589 c_hash?: string;
590 acr?: string;
591 amr?: string;
592 sub_jwk?: string;
593 cnf?: string;
594 sid?: string;
595 org_id?: string;
596 [key: string]: any;
597}
598
599export class User {
600 name?: string;
601 given_name?: string;
602 family_name?: string;
603 middle_name?: string;
604 nickname?: string;
605 preferred_username?: string;
606 profile?: string;
607 picture?: string;
608 website?: string;
609 email?: string;
610 email_verified?: boolean;
611 gender?: string;
612 birthdate?: string;
613 zoneinfo?: string;
614 locale?: string;
615 phone_number?: string;
616 phone_number_verified?: boolean;
617 address?: string;
618 updated_at?: string;
619 sub?: string;
620 [key: string]: any;
621}
622
623/**
624 * @ignore
625 */
626export type FetchOptions = {
627 method?: string;
628 headers?: Record<string, string>;
629 credentials?: 'include' | 'omit';
630 body?: string;
631 signal?: AbortSignal;
632};
633
634export type GetTokenSilentlyVerboseResponse = Omit<
635 TokenEndpointResponse,
636 'refresh_token'
637>;
638
\No newline at end of file