await connectAccountWithRedirect({
connection: 'google-oauth2',
scopes: ['openid', 'profile', 'email', 'https://www.googleapis.com/auth/drive.readonly'],
authorization_params: {
// additional authorization params to forward to the authorization server
}
});
Redirects to the /connect URL using the parameters
provided as arguments. This then redirects to the connection's login page
where the user can authenticate and authorize the account to be connected.
If connecting the account is successful onRedirectCallback will be called
with the details of the connected account.
Returns a new Fetcher class that will contain a fetchWithAuth() method.
This is a drop-in replacement for the Fetch API's fetch() method, but will
handle certain authentication logic for you, like building the proper auth
headers or managing DPoP nonces and retries automatically.
Check the EXAMPLES.md file for a deeper look into this method.
Returns a new Fetcher class that will contain a fetchWithAuth() method.
This is a drop-in replacement for the Fetch API's fetch() method, but will
handle certain authentication logic for you, like building the proper auth
headers or managing DPoP nonces and retries automatically.
Check the EXAMPLES.md file for a deeper look into this method.
Optionalconfig: FetcherConfig<TOutput>The options required to perform the token exchange
A promise that resolves to the token endpoint response containing Auth0 tokens
Use loginWithCustomTokenExchange() instead. This method will be removed in the next major version.
const tokenResponse = await exchangeToken({
subject_token: 'external_token_value',
subject_token_type: 'urn:acme:legacy-system-token',
scope: 'openid profile email'
});
Exchanges an external subject token for Auth0 tokens and logs the user in.
This method implements the token exchange grant as specified in RFC 8693.
It performs a token exchange by sending a request to the /oauth/token endpoint
with the external token and returns Auth0 tokens (access token, ID token, etc.).
Example:
// Instead of:
const tokens = await exchangeToken(options);
// Use:
const tokens = await loginWithCustomTokenExchange(options);
Returns a string to be used to demonstrate possession of the private key used to cryptographically bind access tokens with DPoP.
It requires enabling the Auth0ClientOptions.useDpop option.
Returns a string to be used to demonstrate possession of the private key used to cryptographically bind access tokens with DPoP.
It requires enabling the Auth0ClientOptions.useDpop option.
const token = await getAccessTokenSilently(options);
If there's a valid token stored, return it. Otherwise, opens an
iframe with the /authorize URL using the parameters provided
as arguments. Random and secure state and nonce parameters
will be auto-generated. If the response is successful, results
will be valid according to their expiration times.
If refresh tokens are used, the token endpoint is called directly with the
'refresh_token' grant. If no refresh token is available to make this call,
the SDK will only fall back to using an iframe to the '/authorize' URL if
the useRefreshTokensFallback setting has been set to true. By default this
setting is false.
This method may use a web worker to perform the token call if the in-memory cache is used.
If an audience value is given to this function, the SDK always falls
back to using an iframe to make the token exchange.
Note that in all cases, falling back to an iframe requires access to
the auth0 cookie.
const token = await getTokenWithPopup(options, config);
Get an access token interactively.
Opens a popup with the /authorize URL using the parameters
provided as arguments. Random and secure state and nonce
parameters will be auto-generated. If the response is successful,
results will be valid according to their expiration times.
const config = getConfiguration();
// { domain: 'tenant.auth0.com', clientId: 'abc123' }
Returns a readonly copy of the initialization configuration containing the domain and clientId.
Returns a readonly copy of the initialization configuration.
An object containing domain and clientId
Returns the current DPoP nonce used for making requests to Auth0.
It can return undefined because when starting fresh it will not
be populated until after the first response from the server.
It requires enabling the Auth0ClientOptions.useDpop option.
Returns the current DPoP nonce used for making requests to Auth0.
It can return undefined because when starting fresh it will not
be populated until after the first response from the server.
It requires enabling the Auth0ClientOptions.useDpop option.
Optionalid: stringThe identifier of a nonce: if absent, it will get the nonce used for requests to Auth0. Otherwise, it will be used to select a specific non-Auth0 nonce.
const claims = await getIdTokenClaims();
Returns all claims from the id_token if available.
After the browser redirects back to the callback page,
call handleRedirectCallback to handle success and error
responses from Auth0. If the response is successful, results
will be valid according to their expiration times.
Optionalurl: stringThe URL to that should be used to retrieve the state and code values. Defaults to window.location.href if not given.
await loginWithCustomTokenExchange(options);
Exchanges an external subject token for Auth0 tokens and logs the user in. This method implements the Custom Token Exchange grant as specified in RFC 8693.
The exchanged tokens are automatically cached, establishing an authenticated session.
After calling this method, you can use getUser(), getIdTokenClaims(), and
getTokenSilently() to access the user's information and tokens.
The options required to perform the token exchange.
A promise that resolves to the token endpoint response, which contains the issued Auth0 tokens (access_token, id_token, etc.).
The request includes the following parameters:
grant_type: "urn:ietf:params:oauth:grant-type:token-exchange"subject_token: The external token to exchangesubject_token_type: The type identifier of the external tokenscope: Merged scopes from the request and SDK defaultsaudience: Target audience (defaults to SDK configuration)organization: Optional organization ID/name for org-scoped authenticationExample Usage:
const options = {
subject_token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp...',
subject_token_type: 'urn:acme:legacy-system-token',
scope: 'openid profile email',
audience: 'https://api.example.com',
organization: 'org_12345'
};
try {
const tokenResponse = await loginWithCustomTokenExchange(options);
console.log('Access token:', tokenResponse.access_token);
// User is now logged in - access user info
const user = await getUser();
console.log('Logged in user:', user);
} catch (error) {
console.error('Token exchange failed:', error);
}
await loginWithPopup(options, config);
Opens a popup with the /authorize URL using the parameters
provided as arguments. Random and secure state and nonce
parameters will be auto-generated. If the response is successful,
results will be valid according to their expiration times.
IMPORTANT: This method has to be called from an event handler that was started by the user like a button click, for example, otherwise the popup will be blocked in most browsers.
await loginWithRedirect(options);
Performs a redirect to /authorize using the parameters
provided as arguments. Random and secure state and nonce
parameters will be auto-generated.
auth0.logout({ logoutParams: { returnTo: window.location.origin } });
Clears the application session and performs a redirect to /v2/logout, using
the parameters provided as arguments, to clear the Auth0 session.
If the logoutParams.federated option is specified, it also clears the Identity Provider session.
Read more about how Logout works at Auth0.
Sets the current DPoP nonce used for making requests to Auth0.
It requires enabling the Auth0ClientOptions.useDpop option.
Sets the current DPoP nonce used for making requests to Auth0.
It requires enabling the Auth0ClientOptions.useDpop option.
The nonce value.
Optionalid: stringThe identifier of a nonce: if absent, it will set the nonce used for requests to Auth0. Otherwise, it will be used to select a specific non-Auth0 nonce.
Contains the authenticated state and authentication methods provided by the
useAuth0hook.