@auth0/auth0-spa-js 1.22.5 → 1.22.6

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.
package/README.md CHANGED
@@ -1,56 +1,40 @@
1
- # @auth0/auth0-spa-js
1
+ ![Auth0 SDK for Single Page Applications using Authorization Code Grant Flow with PKCE.](https://cdn.auth0.com/website/sdks/banners/spa-js-banner.png)
2
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
-
5
- [![CircleCI](https://circleci.com/gh/auth0/auth0-spa-js.svg?style=svg)](https://circleci.com/gh/auth0/auth0-spa-js)
6
- ![Release](https://img.shields.io/github/v/release/auth0/auth0-spa-js)
3
+ ![Release](https://img.shields.io/npm/v/@auth0/auth0-spa-js)
7
4
  [![Codecov](https://img.shields.io/codecov/c/github/auth0/auth0-spa-js)](https://codecov.io/gh/auth0/auth0-spa-js)
8
5
  ![Downloads](https://img.shields.io/npm/dw/@auth0/auth0-spa-js)
9
6
  [![License](https://img.shields.io/:license-mit-blue.svg?style=flat)](https://opensource.org/licenses/MIT)
7
+ ![CircleCI](https://img.shields.io/circleci/build/github/auth0/auth0-spa-js)
10
8
 
11
9
  > ℹ️ A new major version of Auth0-SPA-JS is available in **Beta**! Try it out today, any feedback is appreciated. Read all about it on [the `beta` branch](https://github.com/auth0/auth0-spa-js/tree/beta).
12
10
 
13
- ## Table of Contents
14
-
15
- - [Documentation](#documentation)
16
- - [Installation](#installation)
17
- - [Getting Started](#getting-started)
18
- - [Contributing](#contributing)
19
- - [Support + Feedback](#support--feedback)
20
- - [Frequently Asked Questions](#frequently-asked-questions)
21
- - [Vulnerability Reporting](#vulnerability-reporting)
22
- - [What is Auth0](#what-is-auth0)
23
- - [License](#license)
11
+ 📚 [Documentation](#documentation) - 🚀 [Getting Started](#getting-started) - 💻 [API Reference](#api-reference) - 💬 [Feedback](#feedback)
24
12
 
25
13
  ## Documentation
26
14
 
27
- - [Documentation](https://auth0.com/docs/libraries/auth0-spa-js)
28
- - [API reference](https://auth0.github.io/auth0-spa-js/)
29
- - [Migrate from Auth0.js to the Auth0 Single Page App SDK](https://auth0.com/docs/libraries/auth0-spa-js/migrate-from-auth0js)
15
+ - [Quickstart](https://auth0.com/docs/quickstart/spa/vanillajs/interactive) - our interactive guide for quickly adding login, logout and user information to your app using Auth0.
16
+ - [Sample app](https://github.com/auth0-samples/auth0-javascript-samples/tree/master/01-Login) - a full-fledged sample app integrated with Auth0.
17
+ - [FAQs](https://github.com/auth0/auth0-spa-js/blob/master/FAQ.md) - frequently asked questions about auth0-spa-js SDK.
18
+ - [Examples](https://github.com/auth0/auth0-spa-js/blob/master/EXAMPLES.md) - code samples for common scenarios.
19
+ - [Docs Site](https://auth0.com/docs) - explore our Docs site and learn more about Auth0.
30
20
 
31
- ## Installation
32
-
33
- From the CDN:
21
+ ## Getting Started
34
22
 
35
- ```html
36
- <script src="https://cdn.auth0.com/js/auth0-spa-js/1.22/auth0-spa-js.production.js"></script>
37
- ```
23
+ ### Installation
38
24
 
39
- Using [npm](https://npmjs.org):
25
+ Using [npm](https://npmjs.org) in your project directory run the following command:
40
26
 
41
27
  ```sh
42
28
  npm install @auth0/auth0-spa-js
43
29
  ```
44
30
 
45
- Using [yarn](https://yarnpkg.com):
31
+ From the CDN:
46
32
 
47
- ```sh
48
- yarn add @auth0/auth0-spa-js
33
+ ```html
34
+ <script src="https://cdn.auth0.com/js/auth0-spa-js/1.22/auth0-spa-js.production.js"></script>
49
35
  ```
50
36
 
51
- ## Getting Started
52
-
53
- ### Auth0 Configuration
37
+ ### Configure Auth0
54
38
 
55
39
  Create a **Single Page Application** in the [Auth0 Dashboard](https://manage.auth0.com/#/applications).
56
40
 
@@ -72,7 +56,7 @@ Next, configure the following URLs for your application under the "Application U
72
56
 
73
57
  Take note of the **Client ID** and **Domain** values under the "Basic Information" section. You'll need these values in the next step.
74
58
 
75
- ### Creating the client
59
+ ### Configure the SDK
76
60
 
77
61
  Create an `Auth0Client` instance before rendering or initializing your application. You should only have one instance of the client.
78
62
 
@@ -86,15 +70,6 @@ const auth0 = await createAuth0Client({
86
70
  redirect_uri: '<MY_CALLBACK_URL>'
87
71
  });
88
72
 
89
- //with promises
90
- createAuth0Client({
91
- domain: '<AUTH0_DOMAIN>',
92
- client_id: '<AUTH0_CLIENT_ID>',
93
- redirect_uri: '<MY_CALLBACK_URL>'
94
- }).then(auth0 => {
95
- //...
96
- });
97
-
98
73
  //or, you can just instantiate the client on it's own
99
74
  import { Auth0Client } from '@auth0/auth0-spa-js';
100
75
 
@@ -114,15 +89,15 @@ try {
114
89
  }
115
90
  ```
116
91
 
117
- ### 1 - Login
92
+ ### Logging In
93
+
94
+ You can then use login using the `Auth0Client` instance you created:
118
95
 
119
96
  ```html
120
97
  <button id="login">Click to Login</button>
121
98
  ```
122
99
 
123
100
  ```js
124
- //with async/await
125
-
126
101
  //redirect to the Universal Login Page
127
102
  document.getElementById('login').addEventListener('click', async () => {
128
103
  await auth0.loginWithRedirect();
@@ -135,245 +110,22 @@ window.addEventListener('load', async () => {
135
110
  const user = await auth0.getUser();
136
111
  console.log(user);
137
112
  });
138
-
139
- //with promises
140
-
141
- //redirect to the Universal Login Page
142
- document.getElementById('login').addEventListener('click', () => {
143
- auth0.loginWithRedirect().catch(() => {
144
- //error while redirecting the user
145
- });
146
- });
147
-
148
- //in your callback route (<MY_CALLBACK_URL>)
149
- window.addEventListener('load', () => {
150
- auth0.handleRedirectCallback().then(redirectResult => {
151
- //logged in. you can get the user profile like this:
152
- auth0.getUser().then(user => {
153
- console.log(user);
154
- });
155
- });
156
- });
157
- ```
158
-
159
- ### 2 - Calling an API
160
-
161
- ```html
162
- <button id="call-api">Call an API</button>
163
- ```
164
-
165
- ```js
166
- //with async/await
167
- document.getElementById('call-api').addEventListener('click', async () => {
168
- const accessToken = await auth0.getTokenSilently();
169
- const result = await fetch('https://myapi.com', {
170
- method: 'GET',
171
- headers: {
172
- Authorization: `Bearer ${accessToken}`
173
- }
174
- });
175
- const data = await result.json();
176
- console.log(data);
177
- });
178
-
179
- //with promises
180
- document.getElementById('call-api').addEventListener('click', () => {
181
- auth0
182
- .getTokenSilently()
183
- .then(accessToken =>
184
- fetch('https://myapi.com', {
185
- method: 'GET',
186
- headers: {
187
- Authorization: `Bearer ${accessToken}`
188
- }
189
- })
190
- )
191
- .then(result => result.json())
192
- .then(data => {
193
- console.log(data);
194
- });
195
- });
196
- ```
197
-
198
- ### 3 - Logout
199
-
200
- ```html
201
- <button id="logout">Logout</button>
202
- ```
203
-
204
- ```js
205
- import createAuth0Client from '@auth0/auth0-spa-js';
206
-
207
- document.getElementById('logout').addEventListener('click', () => {
208
- auth0.logout();
209
- });
210
- ```
211
-
212
- You can redirect users back to your app after logging out. This URL must appear in the **Allowed Logout URLs** setting for the app in your [Auth0 Dashboard](https://manage.auth0.com):
213
-
214
- ```js
215
- auth0.logout({
216
- returnTo: 'https://your.custom.url.example.com/'
217
- });
218
- ```
219
-
220
- ### Data caching options
221
-
222
- The SDK can be configured to cache ID tokens and access tokens either in memory or in local storage. The default is in memory. This setting can be controlled using the `cacheLocation` option when creating the Auth0 client.
223
-
224
- To use the in-memory mode, no additional options need are required as this is the default setting. To configure the SDK to cache data using local storage, set `cacheLocation` as follows:
225
-
226
- ```js
227
- await createAuth0Client({
228
- domain: '<AUTH0_DOMAIN>',
229
- client_id: '<AUTH0_CLIENT_ID>',
230
- redirect_uri: '<MY_CALLBACK_URL>',
231
- cacheLocation: 'localstorage' // valid values are: 'memory' or 'localstorage'
232
- });
233
113
  ```
234
114
 
235
- **Important:** This feature will allow the caching of data **such as ID and access tokens** to be stored in local storage. Exercising this option changes the security characteristics of your application and **should not be used lightly**. Extra care should be taken to mitigate against XSS attacks and minimize the risk of tokens being stolen from local storage.
115
+ For other comprehensive examples, see the [EXAMPLES.md](https://github.com/auth0/auth0-spa-js/blob/master/EXAMPLES.md) document.
236
116
 
237
- #### Creating a custom cache
117
+ ## API Reference
238
118
 
239
- The SDK can be configured to use a custom cache store that is implemented by your application. This is useful if you are using this SDK in an environment where more secure token storage is available, such as potentially a hybrid mobile app.
119
+ Explore API Methods available in auth0-spa-js.
240
120
 
241
- To do this, provide an object to the `cache` property of the SDK configuration.
121
+ - [Configuration Options](https://auth0.github.io/auth0-spa-js/interfaces/auth0clientoptions.html)
242
122
 
243
- The object should implement the following functions. Note that all of these functions can optionally return a Promise or a static value.
123
+ - [Auth0Client](https://auth0.github.io/auth0-spa-js/classes/auth0client.html)
124
+ - [createAuth0Client](https://auth0.github.io/auth0-spa-js/globals.html#createauth0client)
244
125
 
245
- | Signature | Return type | Description |
246
- | -------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
247
- | `get(key)` | Promise<object> or object | Returns the item from the cache with the specified key, or `undefined` if it was not found |
248
- | `set(key: string, object: any) ` | Promise<void> or void | Sets an item into the cache |
249
- | `remove(key)` | Promise<void> or void | Removes a single item from the cache at the specified key, or no-op if the item was not found |
250
- | `allKeys()` | Promise<string[]> or string [] | (optional) Implement this if your cache has the ability to return a list of all keys. Otherwise, the SDK internally records its own key manifest using your cache. **Note**: if you only want to ensure you only return keys used by this SDK, the keys we use are prefixed with `@@auth0spajs@@` |
126
+ ## Feedback
251
127
 
252
- Here's an example of a custom cache implementation that uses `sessionStorage` to store tokens and apply it to the Auth0 SPA SDK:
253
-
254
- ```js
255
- const sessionStorageCache = {
256
- get: function (key) {
257
- return JSON.parse(sessionStorage.getItem(key));
258
- },
259
-
260
- set: function (key, value) {
261
- sessionStorage.setItem(key, JSON.stringify(value));
262
- },
263
-
264
- remove: function (key) {
265
- sessionStorage.removeItem(key);
266
- },
267
-
268
- // Optional
269
- allKeys: function () {
270
- return Object.keys(sessionStorage);
271
- }
272
- };
273
-
274
- await createAuth0Client({
275
- domain: '<AUTH0_DOMAIN>',
276
- client_id: '<AUTH0_CLIENT_ID>',
277
- redirect_uri: '<MY_CALLBACK_URL>',
278
- cache: sessionStorageCache
279
- });
280
- ```
281
-
282
- **Note:** The `cache` property takes precedence over the `cacheLocation` property if both are set. A warning is displayed in the console if this scenario occurs.
283
-
284
- We also export the internal `InMemoryCache` and `LocalStorageCache` implementations, so you can wrap your custom cache around these implementations if you wish.
285
-
286
- ### Refresh Tokens
287
-
288
- Refresh tokens can be used to request new access tokens. [Read more about how our refresh tokens work for browser-based applications](https://auth0.com/docs/tokens/concepts/refresh-token-rotation) to help you decide whether or not you need to use them.
289
-
290
- To enable the use of refresh tokens, set the `useRefreshTokens` option to `true`:
291
-
292
- ```js
293
- await createAuth0Client({
294
- domain: '<AUTH0_DOMAIN>',
295
- client_id: '<AUTH0_CLIENT_ID>',
296
- redirect_uri: '<MY_CALLBACK_URL>',
297
- useRefreshTokens: true
298
- });
299
- ```
300
-
301
- Using this setting will cause the SDK to automatically send the `offline_access` scope to the authorization server. Refresh tokens will then be used to exchange for new access tokens instead of using a hidden iframe, and calls the `/oauth/token` endpoint directly. This means that in most cases the SDK does not rely on third-party cookies when using refresh tokens.
302
-
303
- **Note** This configuration option requires Rotating Refresh Tokens to be [enabled for your Auth0 Tenant](https://auth0.com/docs/tokens/guides/configure-refresh-token-rotation).
304
-
305
- #### Refresh Token fallback
306
-
307
- In all cases where a refresh token is not available, the SDK falls back to the legacy technique of using a hidden iframe with `prompt=none` to try and get a new access token and refresh token. This scenario would occur for example if you are using the in-memory cache and you have refreshed the page. In this case, any refresh token that was stored previously would be lost.
308
-
309
- If the fallback mechanism fails, a `login_required` error will be thrown and could be handled in order to put the user back through the authentication process.
310
-
311
- **Note**: This fallback mechanism does still require access to the Auth0 session cookie, so if third-party cookies are being blocked then this fallback will not work and the user must re-authenticate in order to get a new refresh token.
312
-
313
- ### Organizations
314
-
315
- [Organizations](https://auth0.com/docs/organizations) is a set of features that provide better support for developers who build and maintain SaaS and Business-to-Business (B2B) applications.
316
-
317
- #### Log in to an organization
318
-
319
- Log in to an organization by specifying the `organization` parameter when setting up the client:
320
-
321
- ```js
322
- createAuth0Client({
323
- domain: '<AUTH0_DOMAIN>',
324
- client_id: '<AUTH0_CLIENT_ID>',
325
- redirect_uri: '<MY_CALLBACK_URL>',
326
- organization: '<MY_ORG_ID>'
327
- });
328
- ```
329
-
330
- You can also specify the organization when logging in:
331
-
332
- ```js
333
- // Using a redirect
334
- client.loginWithRedirect({
335
- organization: '<MY_ORG_ID>'
336
- });
337
-
338
- // Using a popup window
339
- client.loginWithPopup({
340
- organization: '<MY_ORG_ID>'
341
- });
342
- ```
343
-
344
- #### Accept user invitations
345
-
346
- Accept a user invitation through the SDK by creating a route within your application that can handle the user invitation URL, and log the user in by passing the `organization` and `invitation` parameters from this URL. You can either use `loginWithRedirect` or `loginWithPopup` as needed.
347
-
348
- ```js
349
- const url = new URL(invitationUrl);
350
- const params = new URLSearchParams(url.search);
351
- const organization = params.get('organization');
352
- const invitation = params.get('invitation');
353
-
354
- if (organization && invitation) {
355
- client.loginWithRedirect({
356
- organization,
357
- invitation
358
- });
359
- }
360
- ```
361
-
362
- ### Advanced options
363
-
364
- Advanced options can be set by specifying the `advancedOptions` property when configuring `Auth0Client`. Learn about the complete set of advanced options in the [API documentation](https://auth0.github.io/auth0-spa-js/interfaces/advancedoptions.html)
365
-
366
- ```js
367
- createAuth0Client({
368
- domain: '<AUTH0_DOMAIN>',
369
- client_id: '<AUTH0_CLIENT_ID>',
370
- advancedOptions: {
371
- defaultScope: 'email' // change the scopes that are applied to every authz request. **Note**: `openid` is always specified regardless of this setting
372
- }
373
- });
374
- ```
375
-
376
- ## Contributing
128
+ ### Contributing
377
129
 
378
130
  We appreciate feedback and contribution to this repo! Before you get started, please see the following:
379
131
 
@@ -381,31 +133,26 @@ We appreciate feedback and contribution to this repo! Before you get started, pl
381
133
  - [Auth0's code of conduct guidelines](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md)
382
134
  - [This repo's contribution guide](https://github.com/auth0/auth0-spa-js/blob/master/CONTRIBUTING.md)
383
135
 
384
- ## Support + Feedback
385
-
386
- For support or to provide feedback, please [raise an issue on our issue tracker](https://github.com/auth0/auth0-spa-js/issues).
387
-
388
- ## Frequently Asked Questions
136
+ ### Raise an issue
389
137
 
390
- For a rundown of common issues you might encounter when using the SDK, please check out [the FAQ](https://github.com/auth0/auth0-spa-js/blob/master/FAQ.md).
138
+ To provide feedback or report a bug, please [raise an issue on our issue tracker](https://github.com/auth0/auth0-spa-js/issues).
391
139
 
392
- ## Vulnerability Reporting
140
+ ### Vulnerability Reporting
393
141
 
394
142
  Please do not report security vulnerabilities on the public GitHub issue tracker. The [Responsible Disclosure Program](https://auth0.com/whitehat) details the procedure for disclosing security issues.
395
143
 
396
144
  ## What is Auth0?
397
145
 
398
- Auth0 helps you to easily:
399
-
400
- - implement authentication with multiple identity providers, including social (e.g., Google, Facebook, Microsoft, LinkedIn, GitHub, Twitter, etc), or enterprise (e.g., Windows Azure AD, Google Apps, Active Directory, ADFS, SAML, etc.)
401
- - log in users with username/password databases, passwordless, or multi-factor authentication
402
- - link multiple user accounts together
403
- - generate signed JSON Web Tokens to authorize your API calls and flow the user identity securely
404
- - access demographics and analytics detailing how, when, and where users are logging in
405
- - enrich user profiles from other data sources using customizable JavaScript rules
406
-
407
- [Why Auth0?](https://auth0.com/why-auth0)
408
-
409
- ## License
410
-
411
- This project is licensed under the MIT license. See the [LICENSE](https://github.com/auth0/auth0-spa-js/blob/master/LICENSE) file for more info.
146
+ <p align="center">
147
+ <picture>
148
+ <source media="(prefers-color-scheme: dark)" srcset="https://cdn.auth0.com/website/sdks/logos/auth0_dark_mode.png" width="150">
149
+ <source media="(prefers-color-scheme: light)" srcset="https://cdn.auth0.com/website/sdks/logos/auth0_light_mode.png" width="150">
150
+ <img alt="Auth0 Logo" src="https://cdn.auth0.com/website/sdks/logos/auth0_light_mode.png" width="150">
151
+ </picture>
152
+ </p>
153
+ <p align="center">
154
+ Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout <a href="https://auth0.com/why-auth0">Why Auth0?</a>
155
+ </p>
156
+ <p align="center">
157
+ This project is licensed under the MIT license. See the <a href="https://github.com/auth0/auth0-spa-js/blob/master/LICENSE"> LICENSE</a> file for more info.
158
+ </p>
@@ -240,16 +240,15 @@
240
240
  value: value
241
241
  };
242
242
  };
243
- var FunctionPrototype$2 = Function.prototype;
243
+ var $Function = Function;
244
+ var FunctionPrototype$2 = $Function.prototype;
244
245
  var bind$2 = FunctionPrototype$2.bind;
245
246
  var call$1 = FunctionPrototype$2.call;
246
247
  var uncurryThis = functionBindNative && bind$2.bind(call$1, call$1);
247
- var functionUncurryThis = functionBindNative ? function(fn) {
248
- return fn && uncurryThis(fn);
249
- } : function(fn) {
250
- return fn && function() {
248
+ var functionUncurryThis = function(fn) {
249
+ return fn instanceof $Function ? functionBindNative ? uncurryThis(fn) : function() {
251
250
  return call$1.apply(fn, arguments);
252
- };
251
+ } : undefined;
253
252
  };
254
253
  var toString$1 = functionUncurryThis({}.toString);
255
254
  var stringSlice$3 = functionUncurryThis("".slice);
@@ -274,12 +273,20 @@
274
273
  var toIndexedObject = function(it) {
275
274
  return indexedObject(requireObjectCoercible(it));
276
275
  };
277
- var isCallable = function(argument) {
276
+ var documentAll$2 = typeof document == "object" && document.all;
277
+ var IS_HTMLDDA = typeof documentAll$2 == "undefined" && documentAll$2 !== undefined;
278
+ var documentAll_1 = {
279
+ all: documentAll$2,
280
+ IS_HTMLDDA: IS_HTMLDDA
281
+ };
282
+ var documentAll$1 = documentAll_1.all;
283
+ var isCallable = documentAll_1.IS_HTMLDDA ? function(argument) {
284
+ return typeof argument == "function" || argument === documentAll$1;
285
+ } : function(argument) {
278
286
  return typeof argument == "function";
279
287
  };
280
- var documentAll = typeof document == "object" && document.all;
281
- var SPECIAL_DOCUMENT_ALL = typeof documentAll == "undefined" && documentAll !== undefined;
282
- var isObject = SPECIAL_DOCUMENT_ALL ? function(it) {
288
+ var documentAll = documentAll_1.all;
289
+ var isObject = documentAll_1.IS_HTMLDDA ? function(it) {
283
290
  return typeof it == "object" ? it !== null : isCallable(it) || it === documentAll;
284
291
  } : function(it) {
285
292
  return typeof it == "object" ? it !== null : isCallable(it);
@@ -366,10 +373,10 @@
366
373
  (module.exports = function(key, value) {
367
374
  return sharedStore[key] || (sharedStore[key] = value !== undefined ? value : {});
368
375
  })("versions", []).push({
369
- version: "3.25.1",
376
+ version: "3.25.4",
370
377
  mode: "global",
371
378
  copyright: "© 2014-2022 Denis Pushkarev (zloirock.ru)",
372
- license: "https://github.com/zloirock/core-js/blob/v3.25.1/LICENSE",
379
+ license: "https://github.com/zloirock/core-js/blob/v3.25.4/LICENSE",
373
380
  source: "https://github.com/zloirock/core-js"
374
381
  });
375
382
  }));
@@ -3591,7 +3598,7 @@
3591
3598
  exports.default = SuperTokensLock;
3592
3599
  }));
3593
3600
  var Lock = unwrapExports(browserTabsLock);
3594
- var version = "1.22.5";
3601
+ var version = "1.22.6";
3595
3602
  var DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS = 60;
3596
3603
  var DEFAULT_POPUP_CONFIG_OPTIONS = {
3597
3604
  timeoutInSeconds: DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS
@@ -3925,6 +3932,7 @@
3925
3932
  } else {
3926
3933
  resolve(event.data);
3927
3934
  }
3935
+ messageChannel.port1.close();
3928
3936
  };
3929
3937
  to.postMessage(message, [ messageChannel.port2 ]);
3930
3938
  }));