UNPKG

8.64 kBTypeScriptView Raw
1import { Auth0ClientOptions, RedirectLoginOptions, PopupLoginOptions, PopupConfigOptions, GetUserOptions, GetIdTokenClaimsOptions, RedirectLoginResult, GetTokenSilentlyOptions, GetTokenWithPopupOptions, LogoutOptions, CacheLocation, LogoutUrlOptions, User, IdToken, GetTokenSilentlyVerboseResponse } from './global';
2/**
3 * Auth0 SDK for Single Page Applications using [Authorization Code Grant Flow with PKCE](https://auth0.com/docs/api-auth/tutorials/authorization-code-grant-pkce).
4 */
5export default class Auth0Client {
6 private options;
7 private readonly transactionManager;
8 private readonly cacheManager;
9 private readonly customOptions;
10 private readonly domainUrl;
11 private readonly tokenIssuer;
12 private readonly defaultScope;
13 private readonly scope;
14 private readonly cookieStorage;
15 private readonly sessionCheckExpiryDays;
16 private readonly orgHintCookieName;
17 private readonly isAuthenticatedCookieName;
18 private readonly nowProvider;
19 private readonly httpTimeoutMs;
20 cacheLocation: CacheLocation;
21 private worker;
22 constructor(options: Auth0ClientOptions);
23 private _url;
24 private _getParams;
25 private _authorizeUrl;
26 private _verifyIdToken;
27 private _parseNumber;
28 private _processOrgIdHint;
29 /**
30 * ```js
31 * await auth0.buildAuthorizeUrl(options);
32 * ```
33 *
34 * Builds an `/authorize` URL for loginWithRedirect using the parameters
35 * provided as arguments. Random and secure `state` and `nonce`
36 * parameters will be auto-generated.
37 *
38 * @param options
39 */
40 buildAuthorizeUrl(options?: RedirectLoginOptions): Promise<string>;
41 /**
42 * ```js
43 * try {
44 * await auth0.loginWithPopup(options);
45 * } catch(e) {
46 * if (e instanceof PopupCancelledError) {
47 * // Popup was closed before login completed
48 * }
49 * }
50 * ```
51 *
52 * Opens a popup with the `/authorize` URL using the parameters
53 * provided as arguments. Random and secure `state` and `nonce`
54 * parameters will be auto-generated. If the response is successful,
55 * results will be valid according to their expiration times.
56 *
57 * IMPORTANT: This method has to be called from an event handler
58 * that was started by the user like a button click, for example,
59 * otherwise the popup will be blocked in most browsers.
60 *
61 * @param options
62 * @param config
63 */
64 loginWithPopup(options?: PopupLoginOptions, config?: PopupConfigOptions): Promise<void>;
65 /**
66 * ```js
67 * const user = await auth0.getUser();
68 * ```
69 *
70 * Returns the user information if available (decoded
71 * from the `id_token`).
72 *
73 * If you provide an audience or scope, they should match an existing Access Token
74 * (the SDK stores a corresponding ID Token with every Access Token, and uses the
75 * scope and audience to look up the ID Token)
76 *
77 * @typeparam TUser The type to return, has to extend {@link User}.
78 * @param options
79 */
80 getUser<TUser extends User>(options?: GetUserOptions): Promise<TUser | undefined>;
81 /**
82 * ```js
83 * const claims = await auth0.getIdTokenClaims();
84 * ```
85 *
86 * Returns all claims from the id_token if available.
87 *
88 * If you provide an audience or scope, they should match an existing Access Token
89 * (the SDK stores a corresponding ID Token with every Access Token, and uses the
90 * scope and audience to look up the ID Token)
91 *
92 * @param options
93 */
94 getIdTokenClaims(options?: GetIdTokenClaimsOptions): Promise<IdToken | undefined>;
95 /**
96 * ```js
97 * await auth0.loginWithRedirect(options);
98 * ```
99 *
100 * Performs a redirect to `/authorize` using the parameters
101 * provided as arguments. Random and secure `state` and `nonce`
102 * parameters will be auto-generated.
103 *
104 * @param options
105 */
106 loginWithRedirect<TAppState = any>(options?: RedirectLoginOptions<TAppState>): Promise<void>;
107 /**
108 * After the browser redirects back to the callback page,
109 * call `handleRedirectCallback` to handle success and error
110 * responses from Auth0. If the response is successful, results
111 * will be valid according to their expiration times.
112 */
113 handleRedirectCallback<TAppState = any>(url?: string): Promise<RedirectLoginResult<TAppState>>;
114 /**
115 * ```js
116 * await auth0.checkSession();
117 * ```
118 *
119 * Check if the user is logged in using `getTokenSilently`. The difference
120 * with `getTokenSilently` is that this doesn't return a token, but it will
121 * pre-fill the token cache.
122 *
123 * This method also heeds the `auth0.{clientId}.is.authenticated` cookie, as an optimization
124 * to prevent calling Auth0 unnecessarily. If the cookie is not present because
125 * there was no previous login (or it has expired) then tokens will not be refreshed.
126 *
127 * It should be used for silently logging in the user when you instantiate the
128 * `Auth0Client` constructor. You should not need this if you are using the
129 * `createAuth0Client` factory.
130 *
131 * **Note:** the cookie **may not** be present if running an app using a private tab, as some
132 * browsers clear JS cookie data and local storage when the tab or page is closed, or on page reload. This effectively
133 * means that `checkSession` could silently return without authenticating the user on page refresh when
134 * using a private tab, despite having previously logged in. As a workaround, use `getTokenSilently` instead
135 * and handle the possible `login_required` error [as shown in the readme](https://github.com/auth0/auth0-spa-js#creating-the-client).
136 *
137 * @param options
138 */
139 checkSession(options?: GetTokenSilentlyOptions): Promise<void>;
140 /**
141 * Fetches a new access token and returns the response from the /oauth/token endpoint, omitting the refresh token.
142 *
143 * @param options
144 */
145 getTokenSilently(options: GetTokenSilentlyOptions & {
146 detailedResponse: true;
147 }): Promise<GetTokenSilentlyVerboseResponse>;
148 /**
149 * Fetches a new access token and returns it.
150 *
151 * @param options
152 */
153 getTokenSilently(options?: GetTokenSilentlyOptions): Promise<string>;
154 private _getTokenSilently;
155 /**
156 * ```js
157 * const token = await auth0.getTokenWithPopup(options);
158 * ```
159 * Opens a popup with the `/authorize` URL using the parameters
160 * provided as arguments. Random and secure `state` and `nonce`
161 * parameters will be auto-generated. If the response is successful,
162 * results will be valid according to their expiration times.
163 *
164 * @param options
165 * @param config
166 */
167 getTokenWithPopup(options?: GetTokenWithPopupOptions, config?: PopupConfigOptions): Promise<string>;
168 /**
169 * ```js
170 * const isAuthenticated = await auth0.isAuthenticated();
171 * ```
172 *
173 * Returns `true` if there's valid information stored,
174 * otherwise returns `false`.
175 *
176 */
177 isAuthenticated(): Promise<boolean>;
178 /**
179 * ```js
180 * await auth0.buildLogoutUrl(options);
181 * ```
182 *
183 * Builds a URL to the logout endpoint using the parameters provided as arguments.
184 * @param options
185 */
186 buildLogoutUrl(options?: LogoutUrlOptions): string;
187 /**
188 * ```js
189 * auth0.logout();
190 * ```
191 *
192 * Clears the application session and performs a redirect to `/v2/logout`, using
193 * the parameters provided as arguments, to clear the Auth0 session.
194 *
195 * **Note:** If you are using a custom cache, and specifying `localOnly: true`, and you want to perform actions or read state from the SDK immediately after logout, you should `await` the result of calling `logout`.
196 *
197 * If the `federated` option is specified it also clears the Identity Provider session.
198 * If the `localOnly` option is specified, it only clears the application session.
199 * It is invalid to set both the `federated` and `localOnly` options to `true`,
200 * and an error will be thrown if you do.
201 * [Read more about how Logout works at Auth0](https://auth0.com/docs/logout).
202 *
203 * @param options
204 */
205 logout(options?: LogoutOptions): Promise<void> | void;
206 private _getTokenFromIFrame;
207 private _getTokenUsingRefreshToken;
208 private _getEntryFromCache;
209}
210
\No newline at end of file