What is @auth0/auth0-spa-js?
@auth0/auth0-spa-js is a JavaScript library designed to handle authentication in single-page applications (SPAs) using Auth0. It provides a simple and secure way to integrate Auth0's authentication and authorization services into your SPA.
What are @auth0/auth0-spa-js's main functionalities?
Login
This feature allows users to log in to your application using Auth0. The code sample demonstrates how to create an Auth0 client and initiate a login redirect.
const auth0 = await createAuth0Client({
domain: 'YOUR_DOMAIN',
client_id: 'YOUR_CLIENT_ID'
});
await auth0.loginWithRedirect({
redirect_uri: window.location.origin
});
Logout
This feature allows users to log out of your application. The code sample shows how to log out and redirect the user to the home page.
await auth0.logout({
returnTo: window.location.origin
});
Get User Information
This feature retrieves the authenticated user's information. The code sample demonstrates how to get the user profile after authentication.
const user = await auth0.getUser();
console.log(user);
Token Handling
This feature handles token retrieval for authenticated requests. The code sample shows how to get an access token silently without redirecting the user.
const token = await auth0.getTokenSilently();
console.log(token);
Other packages similar to @auth0/auth0-spa-js
oidc-client
oidc-client is a JavaScript library for OpenID Connect (OIDC) and OAuth2. It provides similar functionalities for handling authentication and authorization in SPAs. Compared to @auth0/auth0-spa-js, oidc-client is more generic and can be used with any OIDC-compliant identity provider.
firebase
Firebase Authentication provides backend services to help authenticate users in your application. It supports various authentication methods, including email/password, phone, and social providers. Unlike @auth0/auth0-spa-js, Firebase offers a broader range of services beyond authentication, such as database and hosting.
@auth0/auth0-spa-js
Auth0 SDK for Single Page Applications using Authorization Code Grant Flow with PKCE.
Table of Contents
Make sure this is updated based on the sections included:
Documentation
Installation
From the CDN:
<script src="https://cdn.auth0.com/js/auth0-spa-js/1.0.0/auth0-spa-js.production.js"></script>
Using npm:
npm install @auth0/auth0-spa-js
Using yarn:
yarn add @auth0/auth0-spa-js
Getting Started
import Auth0 from '@auth0/auth0-spa-js';
const auth0 = new Auth0({
domain: 'YOUR_AUTH0_DOMAIN',
client_id: 'YOUR_AUTH0_CLIENT_ID'
});
await auth0.init();
await auth0.loginWithPopup();
const user = await auth0.getUser();
const accessToken = await auth0.getTokenSilently();
Contributing
We appreciate feedback and contribution to this repo! Before you get started, please see the following:
Support + Feedback
- Use Issues for code-level support
- Use Community for usage, questions, specific cases
Vulnerability Reporting
Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.
What is Auth0?
Auth0 helps you to easily:
- 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.)
- log in users with username/password databases, passwordless, or multi-factor authentication
- link multiple user accounts together
- generate signed JSON Web Tokens to authorize your API calls and flow the user identity securely
- access demographics and analytics detailing how, when, and where users are logging in
- enrich user profiles from other data sources using customizable JavaScript rules
Why Auth0?
License
This project is licensed under the MIT license. See the LICENSE file for more info.