<script src="https://cdn.auth0.com/js/auth0-spa-js/2.0/auth0-spa-js.production.js"></script>
. For more information, read the FAQ.npm install @auth0/auth0-spa-js
yarn add @auth0/auth0-spa-js
Auth0Client
client object. Create the Auth0Client
instance before rendering or initializing your application. You can do this using either the async/await method, or with promises. You should only create one instance of the client.
Using createAuth0Client
does a couple of things automatically:
Auth0Client
.getTokenSilently
to refresh the user session.getTokenSilently
, except login_required
.Auth0Client
constructor. This can be useful if you want to:
getTokenSilently
on initialization.<button id="login">Click to Login</button>
Listen for click events on the button you created. When the event occurs, use the desired login method to authenticate the user (loginWithRedirect()
in this example). After the user is authenticated, you can retrieve the user profile with the getUser()
method.
getTokenSilently
method is used to retrieve the Access Token:
<button id="callApi">Call an API</button>
<button id="logout">Logout</button>
cacheLocation
property to localstorage
when initializing the SDK. This can help to mitigate some of the effects of browser privacy technology that prevents access to the Auth0 by storing Access Tokens for longer.
useRefreshTokens
to true
on initialization:
offline_access
scope during the authorization step. Furthermore, getTokenSilently
will then call the /oauth/token
endpoint directly to exchange refresh tokens for access tokens.
The SDK will obey the storage configuration when storing refresh tokens. If the SDK has been configured using the default in-memory storage mechanism, refresh tokens will be lost when refreshing the page.
/authorize
endpoint at Auth0, starting the Universal Login flow:
error.popup.close
:
popup
option in the options
object:
handleRedirectCallback
must be called in order to complete the login flow:
prompt=none
, or by using a rotating Refresh Token. Refresh Tokens are used when useRefreshTokens
is set to true
when configuring the SDK.
getTokenSilently()
method requires you to have Allow Skipping User Consent enabled in your API Settings in the Dashboard. Additionally, user consent cannot be skipped on ‘localhost’.
getTokenSilently
, this method of retrieving an Access Token will work in browsers where third-party cookies are blocked by default:
getTokenSilently
that get an Access Token with a different and scope of that which was requested at user authentication time.
useRefreshTokens: false
), as a Refresh Token is bound to the particular audience and scope that was requested at user authentication time.getUser
method:
getIdTokenClaims
method:
logout
method:
logout
method and including clientId: null
: