Gathering detailed insights and metrics for @auth0/auth0-spa-js
Gathering detailed insights and metrics for @auth0/auth0-spa-js
Gathering detailed insights and metrics for @auth0/auth0-spa-js
Gathering detailed insights and metrics for @auth0/auth0-spa-js
Auth0 authentication for Single Page Applications (SPA) with PKCE
npm install @auth0/auth0-spa-js
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
925 Stars
751 Commits
363 Forks
31 Watching
28 Branches
85 Contributors
Updated on 26 Nov 2024
Minified
Minified + Gzipped
TypeScript (59.27%)
JavaScript (32.2%)
HTML (8.53%)
Cumulative downloads
Total Downloads
Last day
-9.7%
143,599
Compared to previous day
Last week
0.6%
805,128
Compared to previous week
Last month
5.5%
3,460,175
Compared to previous month
Last year
22.3%
37,296,958
Compared to previous year
45
📚 Documentation - 🚀 Getting Started - 💻 API Reference - 💬 Feedback
Using npm in your project directory run the following command:
1npm install @auth0/auth0-spa-js
From the CDN:
1<script src="https://cdn.auth0.com/js/auth0-spa-js/2.1/auth0-spa-js.production.js"></script>
Create a Single Page Application in the Auth0 Dashboard.
If you're using an existing application, verify that you have configured the following settings in your Single Page Application:
- Click on the "Settings" tab of your application's page.
- Scroll down and click on the "Show Advanced Settings" link.
- Under "Advanced Settings", click on the "OAuth" tab.
- Ensure that "JsonWebToken Signature Algorithm" is set to
RS256
and that "OIDC Conformant" is enabled.
Next, configure the following URLs for your application under the "Application URIs" section of the "Settings" page:
http://localhost:3000
http://localhost:3000
http://localhost:3000
These URLs should reflect the origins that your application is running on. Allowed Callback URLs may also include a path, depending on where you're handling the callback (see below).
Take note of the Client ID and Domain values under the "Basic Information" section. You'll need these values in the next step.
Create an Auth0Client
instance before rendering or initializing your application. You should only have one instance of the client.
1import { createAuth0Client } from '@auth0/auth0-spa-js'; 2 3//with async/await 4const auth0 = await createAuth0Client({ 5 domain: '<AUTH0_DOMAIN>', 6 clientId: '<AUTH0_CLIENT_ID>', 7 authorizationParams: { 8 redirect_uri: '<MY_CALLBACK_URL>' 9 } 10}); 11 12//or, you can just instantiate the client on its own 13import { Auth0Client } from '@auth0/auth0-spa-js'; 14 15const auth0 = new Auth0Client({ 16 domain: '<AUTH0_DOMAIN>', 17 clientId: '<AUTH0_CLIENT_ID>', 18 authorizationParams: { 19 redirect_uri: '<MY_CALLBACK_URL>' 20 } 21}); 22 23//if you do this, you'll need to check the session yourself 24try { 25 await auth0.getTokenSilently(); 26} catch (error) { 27 if (error.error !== 'login_required') { 28 throw error; 29 } 30}
You can then use login using the Auth0Client
instance you created:
1<button id="login">Click to Login</button>
1//redirect to the Universal Login Page 2document.getElementById('login').addEventListener('click', async () => { 3 await auth0.loginWithRedirect(); 4}); 5 6//in your callback route (<MY_CALLBACK_URL>) 7window.addEventListener('load', async () => { 8 const redirectResult = await auth0.handleRedirectCallback(); 9 //logged in. you can get the user profile like this: 10 const user = await auth0.getUser(); 11 console.log(user); 12});
For other comprehensive examples, see the EXAMPLES.md document.
Explore API Methods available in auth0-spa-js.
We appreciate feedback and contribution to this repo! Before you get started, please see the following:
To provide feedback or report a bug, please raise an issue on our issue tracker.
Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.
Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout Why Auth0?
This project is licensed under the MIT license. See the LICENSE file for more info.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
SAST tool detected
Details
Reason
Found 13/15 approved changesets -- score normalized to 8
Reason
branch protection is not maximal on development and all release branches
Details
Reason
6 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 5
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
12 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More