{"_id":"@aquicore/auth0-spa-js","_rev":"1-9b50a361d5fe4c4b688a2d4d83112a1a","name":"@aquicore/auth0-spa-js","dist-tags":{"latest":"1.7.0"},"versions":{"1.7.0":{"author":{"name":"Auth0"},"name":"@aquicore/auth0-spa-js","description":"Auth0 SDK for Single Page Applications using Authorization Code Grant Flow with PKCE","license":"MIT","version":"1.7.0","main":"dist/lib/auth0-spa-js.cjs.js","types":"dist/typings/index.d.ts","module":"dist/auth0-spa-js.production.esm.js","scripts":{"dev":"rimraf dist && rollup -c --watch","start":"npm run dev","docs":"typedoc --options ./typedoc.js --module commonjs","build":"rimraf dist && rollup -m -c --environment NODE_ENV:production","build:stats":"npm run build -- --environment WITH_STATS:true && open stats.html","lint:security":"eslint ./src --ext ts --no-eslintrc --config ./.eslintrc.security","test":"jest --coverage","test:watch":"jest --coverage --watch","test:watch:integration":"concurrently --raw npm:dev 'cypress open'","test:es-check":"npm run test:es-check:es5 && npm run test:es-check:es2015:module","test:es-check:es5":"es-check es5 'dist/auth0-spa-js.production.js'","test:es-check:es2015:module":"es-check es2015 --module 'dist/auth0-spa-js.production.esm.js'","test:integration:server":"cp static/index.html dist/index.html && serve ./dist/ -p 3000 -n","test:integration:tests":"wait-on http://localhost:3000/ && cypress run","test:integration":"concurrently --raw --kill-others --success first npm:test:integration:server npm:test:integration:tests","print-bundle-size":"node ./scripts/print-bundle-size","prepack":"npm run build && npm run test:es-check && npm run test && node ./scripts/prepack","release":"node ./scripts/release","release:clean":"node ./scripts/cleanup","publish:cdn":"ccu --trace"},"devDependencies":{"@auth0/component-cdn-uploader":"github:auth0/component-cdn-uploader#v2.2.2","@rollup/plugin-replace":"^2.3.1","@types/cypress":"^1.1.3","@types/jest":"^24.9.1","@typescript-eslint/eslint-plugin-tslint":"^2.27.0","@typescript-eslint/parser":"^2.27.0","cli-table":"^0.3.1","concurrently":"^5.1.0","cypress":"^4.3.0","es-check":"^5.1.0","eslint":"^6.8.0","gzip-size":"^5.1.1","husky":"^4.2.3","idtoken-verifier":"^2.0.2","jest":"^24.9.0","jest-localstorage-mock":"^2.4.0","jsonwebtoken":"^8.5.1","pem":"^1.14.4","prettier":"^2.0.4","pretty-quick":"^2.0.1","qss":"^2.0.3","rimraf":"^3.0.2","rollup":"^2.3.3","rollup-plugin-commonjs":"^10.1.0","rollup-plugin-livereload":"^1.1.0","rollup-plugin-node-resolve":"^5.2.0","rollup-plugin-serve":"^1.0.1","rollup-plugin-sourcemaps":"^0.5.0","rollup-plugin-terser":"^5.3.0","rollup-plugin-typescript2":"^0.27.0","rollup-plugin-visualizer":"^4.0.3","rollup-plugin-web-worker-loader":"0.9.1","serve":"^11.3.0","ts-jest":"^24.3.0","tslint":"^6.1.1","tslint-config-security":"^1.16.0","typedoc":"^0.17.4","typescript":"^3.8.3","wait-on":"^4.0.1"},"dependencies":{"abortcontroller-polyfill":"^1.4.0","browser-tabs-lock":"^1.2.8","core-js":"^3.6.4","es-cookie":"^1.3.2","fast-text-encoding":"^1.0.1","promise-polyfill":"^8.1.3","unfetch":"^4.1.0"},"repository":{"type":"git","url":"git://github.com/auth0/auth0-spa-js.git"},"bugs":{"url":"https://github.com/auth0/auth0-spa-js/issues"},"homepage":"https://github.com/auth0/auth0-spa-js#readme","keywords":["auth0","login","Authorization Code Grant Flow","PKCE","Single Page Application authentication","SPA authentication"],"ccu":{"name":"auth0-spa-js","cdn":"https://cdn.auth0.com","mainBundleFile":"auth0-spa-js.production.js","bucket":"assets.us.auth0.com","localPath":"dist","digest":{"hashes":["sha384"],"extensions":[".js"]}},"husky":{"hooks":{"pre-commit":"pretty-quick --staged"}},"gitHead":"4c54ee19fc4d4ae4c8a234271aa62be0c37e1239","_id":"@aquicore/auth0-spa-js@1.7.0","_nodeVersion":"12.16.0","_npmVersion":"6.13.4","dist":{"integrity":"sha512-3LVSJ9tSCYlNwU9HB5mz8sYhliJHG+oZAKHKhhSBWDmO2h63RM7j/3Yv9HKalux682F37rNCPBzm7OoVA3v1bQ==","shasum":"ab64697758f65595073399447e7909fbfd06400e","tarball":"https://registry.npmjs.org/@aquicore/auth0-spa-js/-/auth0-spa-js-1.7.0.tgz","fileCount":41,"unpackedSize":1762083,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJemc4zCRA9TVsSAnZWagAAnosQAIGkC08F40zSt+jTNzTN\nmhJC9wAsi6GQxlt2oqpP+gwmp5pFbDlhLpVDhYe6RVkclVjNBgfh9+LuIWL2\nzuBHmJlLrSAFkQWx5RljHSc/e2+1VbFn2gvqIq48324+o0SrPmYmQz0+8wLT\nsLLQ5Mvvi3q1LDAMAKWpgt/iDHkVhELsSPEL5g6QiveksQqb3GMTaofwIH1I\nyEiUvCP9XV532BwikKrR1pd16uHZGqHMu9q7+5jfCXOSGlegtWGSq0iu4mNN\ny59BBIQtX9NZ/0zKFaIE8I4DJdEAkxPx2BsT5Q/Z0HzYqvUScReKwtuFU7wx\nPu/yzeEncI1IFwkTbGzKvvo5PXdniG2RqzRQkwigrxAiDU0gSxcKLL7zheXg\nM7koOR6wX81JjAmHbxDy/0JPsdbjPZarDmmz+Fcok8QUOzxQa17N2ioZOoje\nouvNM9W3q1YMJgtolvnyDs8BYrk2kDP0fBf7ayqa7JtwYJH8U/MG6u+aA/N7\nP5At86SjX11Q/LNGyZR6B4wZYjN1Ee14xTMuAW/ZR8aqI1+bTgXIrH2VRhca\n63OvmZaeHnJYD5TdcgdKLpcvHWkATR6bSX5ezFeGjgN4avDaXzCjV6eUTmcw\nLyuxcan1CDXWxEkli9KaNPLyH/vM8DImtmx5SjC1uc6dk1my0qRbLXcNlllr\nnEdf\r\n=ObBN\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGPSkOrE4wzWbu8iBLmpm8I5rmQDO/GVfZATsf1W3hpwAiBlkP9EOCT15XC3ISNRE+xuwHTRTO5OxjwySnF7sanLYA=="}]},"maintainers":[{"name":"aq-system","email":"maintenance@aquicore.com"}],"_npmUser":{"name":"aq-system","email":"maintenance@aquicore.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/auth0-spa-js_1.7.0_1587138099372_0.17969412900716675"},"_hasShrinkwrap":false}},"time":{"created":"2020-04-17T15:41:39.371Z","1.7.0":"2020-04-17T15:41:39.579Z","modified":"2022-04-04T15:14:06.381Z"},"maintainers":[{"name":"aq-system","email":"maintenance@aquicore.com"}],"description":"Auth0 SDK for Single Page Applications using Authorization Code Grant Flow with PKCE","homepage":"https://github.com/auth0/auth0-spa-js#readme","keywords":["auth0","login","Authorization Code Grant Flow","PKCE","Single Page Application authentication","SPA authentication"],"repository":{"type":"git","url":"git://github.com/auth0/auth0-spa-js.git"},"author":{"name":"Auth0"},"bugs":{"url":"https://github.com/auth0/auth0-spa-js/issues"},"license":"MIT","readme":"# @auth0/auth0-spa-js\n\nAuth0 SDK for Single Page Applications using [Authorization Code Grant Flow with PKCE](https://auth0.com/docs/api-auth/tutorials/authorization-code-grant-pkce).\n\n[![CircleCI](https://circleci.com/gh/auth0/auth0-spa-js.svg?style=svg)](https://circleci.com/gh/auth0/auth0-spa-js)\n[![License](https://img.shields.io/:license-mit-blue.svg?style=flat)](https://opensource.org/licenses/MIT)\n\n## Table of Contents\n\n- [Documentation](#documentation)\n- [Installation](#installation)\n- [Getting Started](#getting-started)\n- [Contributing](#contributing)\n- [Support + Feedback](#support--feedback)\n- [Frequently Asked Questions](#frequently-asked-questions)\n- [Vulnerability Reporting](#vulnerability-reporting)\n- [What is Auth0](#what-is-auth0)\n- [License](#license)\n\n## Documentation\n\n- [Documentation](https://auth0.com/docs/libraries/auth0-spa-js)\n- [API reference](https://auth0.github.io/auth0-spa-js/)\n- [Migrate from Auth0.js to the Auth0 Single Page App SDK](https://auth0.com/docs/libraries/auth0-spa-js/migrate-from-auth0js)\n\n## Installation\n\nFrom the CDN:\n\n```html\n<script src=\"https://cdn.auth0.com/js/auth0-spa-js/1.7/auth0-spa-js.production.js\"></script>\n```\n\nUsing [npm](https://npmjs.org):\n\n```sh\nnpm install @auth0/auth0-spa-js\n```\n\nUsing [yarn](https://yarnpkg.com):\n\n```sh\nyarn add @auth0/auth0-spa-js\n```\n\n## Getting Started\n\n### Creating the client\n\nCreate an `Auth0Client` instance before rendering or initializing your application. You should only have one instance of the client.\n\n```js\nimport createAuth0Client from '@auth0/auth0-spa-js';\n\n//with async/await\nconst auth0 = await createAuth0Client({\n  domain: '<AUTH0_DOMAIN>',\n  client_id: '<AUTH0_CLIENT_ID>',\n  redirect_uri: '<MY_CALLBACK_URL>',\n});\n\n//with promises\ncreateAuth0Client({\n  domain: '<AUTH0_DOMAIN>',\n  client_id: '<AUTH0_CLIENT_ID>',\n  redirect_uri: '<MY_CALLBACK_URL>',\n}).then((auth0) => {\n  //...\n});\n\n//or, you can just instantiate the client on it's own\nimport { Auth0Client } from '@auth0/auth0-spa-js';\n\nconst auth0 = new Auth0Client({\n  domain: '<AUTH0_DOMAIN>',\n  client_id: '<AUTH0_CLIENT_ID>',\n  redirect_uri: '<MY_CALLBACK_URL>',\n});\n\n//if you do this, you'll need to check the session yourself\ntry {\n  await getTokenSilently();\n} catch (error) {\n  if (error.error !== 'login_required') {\n    throw error;\n  }\n}\n```\n\n### 1 - Login\n\n```html\n<button id=\"login\">Click to Login</button>\n```\n\n```js\n//with async/await\n\n//redirect to the Universal Login Page\ndocument.getElementById('login').addEventListener('click', async () => {\n  await auth0.loginWithRedirect();\n});\n\n//in your callback route (<MY_CALLBACK_URL>)\nwindow.addEventListener('load', async () => {\n  const redirectResult = await auth0.handleRedirectCallback();\n  //logged in. you can get the user profile like this:\n  const user = await auth0.getUser();\n  console.log(user);\n});\n\n//with promises\n\n//redirect to the Universal Login Page\ndocument.getElementById('login').addEventListener('click', () => {\n  auth0.loginWithRedirect().catch(() => {\n    //error while redirecting the user\n  });\n});\n\n//in your callback route (<MY_CALLBACK_URL>)\nwindow.addEventListener('load', () => {\n  auth0.handleRedirectCallback().then((redirectResult) => {\n    //logged in. you can get the user profile like this:\n    auth0.getUser().then((user) => {\n      console.log(user);\n    });\n  });\n});\n```\n\n### 2 - Calling an API\n\n```html\n<button id=\"call-api\">Call an API</button>\n```\n\n```js\n//with async/await\ndocument.getElementById('call-api').addEventListener('click', async () => {\n  const accessToken = await auth0.getTokenSilently();\n  const result = await fetch('https://myapi.com', {\n    method: 'GET',\n    headers: {\n      Authorization: `Bearer ${accessToken}`,\n    },\n  });\n  const data = await result.json();\n  console.log(data);\n});\n\n//with promises\ndocument.getElementById('call-api').addEventListener('click', () => {\n  auth0\n    .getTokenSilently()\n    .then((accessToken) =>\n      fetch('https://myapi.com', {\n        method: 'GET',\n        headers: {\n          Authorization: `Bearer ${accessToken}`,\n        },\n      })\n    )\n    .then((result) => result.json())\n    .then((data) => {\n      console.log(data);\n    });\n});\n```\n\n### 3 - Logout\n\n```html\n<button id=\"logout\">Logout</button>\n```\n\n```js\nimport createAuth0Client from '@auth0/auth0-spa-js';\n\ndocument.getElementById('logout').addEventListener('click', () => {\n  auth0.logout();\n});\n```\n\n### Data caching options\n\nThe 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.\n\nTo 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:\n\n```js\nawait createAuth0Client({\n  domain: '<AUTH0_DOMAIN>',\n  client_id: '<AUTH0_CLIENT_ID>',\n  redirect_uri: '<MY_CALLBACK_URL>',\n  cacheLocation: 'localstorage', // valid values are: 'memory' or 'localstorage'\n});\n```\n\n**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.\n\n### Refresh Tokens\n\nRefresh 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.\n\nTo enable the use of refresh tokens, set the `useRefreshTokens` option to `true`:\n\n```js\nawait createAuth0Client({\n  domain: '<AUTH0_DOMAIN>',\n  client_id: '<AUTH0_CLIENT_ID>',\n  redirect_uri: '<MY_CALLBACK_URL>',\n  useRefreshTokens: true,\n});\n```\n\nUsing 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.\n\n**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).\n\n#### Refresh Token fallback\n\nIn 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.\n\nIf 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.\n\n**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.\n\n## Contributing\n\nWe appreciate feedback and contribution to this repo! Before you get started, please see the following:\n\n- [Auth0's general contribution guidelines](https://github.com/auth0/open-source-template/blob/master/GENERAL-CONTRIBUTING.md)\n- [Auth0's code of conduct guidelines](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md)\n- [This repo's contribution guide](https://github.com/auth0/auth0-spa-js/blob/master/CONTRIBUTING.md)\n\n## Support + Feedback\n\nFor support or to provide feedback, please [raise an issue on our issue tracker](https://github.com/auth0/auth0-spa-js/issues).\n\n## Frequently Asked Questions\n\nFor 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).\n\n## Vulnerability Reporting\n\nPlease 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.\n\n## What is Auth0?\n\nAuth0 helps you to easily:\n\n- 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.)\n- log in users with username/password databases, passwordless, or multi-factor authentication\n- link multiple user accounts together\n- generate signed JSON Web Tokens to authorize your API calls and flow the user identity securely\n- access demographics and analytics detailing how, when, and where users are logging in\n- enrich user profiles from other data sources using customizable JavaScript rules\n\n[Why Auth0?](https://auth0.com/why-auth0)\n\n## License\n\nThis project is licensed under the MIT license. See the [LICENSE](https://github.com/auth0/auth0-spa-js/blob/master/LICENSE) file for more info.\n","readmeFilename":"README.md"}