state
parameter./continue
endpoint along with the state
parameter.api.redirect.sendUserTo()
function as follows:
https://my-app.exampleco.com
. In other words, any Actions that are bound to the post-login triggers that run after the Action invoking the redirect will not execute until the authentication flow has been resumed. If you are familiar with Redirect Rules, then note that this is a key difference between Redirect Actions and Redirect Rules.
api.redirect.sendUserTo()
function. Auth0 also passes a state
parameter in that URL. For example:
https://my-app.exampleco.com/?state=abc123
Your redirect URL will need to extract the state
parameter and send it back to Auth0 to resume the authentication transaction. State is an opaque value used to prevent Cross-Site Request Forgery (CSRF) attacks.
/continue
endpoint and including the state
parameter you received in the URL. If you do not send the original state back to the /continue
endpoint, Auth0 will lose the context of the login transaction and the user will not be able to log in due to an invalid_request
error.
For example:
https://{yourAuth0Domain}/continue?state=THE_ORIGINAL_STATE
In this example, THE_ORIGINAL_STATE
is the value that Auth0 generated and sent to the redirect URL. For example, if your Action redirects to https://my-app.exampleco.com/
, Auth0 would use a redirect URL similar to https://my-app.exampleco.com/?state=abc123
, making abc123
the THE_ORIGINAL_STATE
. To resume the authentication transaction, you would redirect to:
https://{yourAuth0Domain}/continue?state=abc123
When a user has been redirected to the /continue
endpoint, the Actions pipeline will resume on the same Action that invoked the redirect by calling the onContinuePostLogin
function. For redirects to work properly, you must have a function with the following signature in the same Action that invoked the redirect:
api.redirect.encodeToken
and api.redirect.sendUserTo
functions:
session_token
query string parameter to the URL used in the redirect (in addition to the state
parameter that Auth0 adds automatically). This token will contain the following:
Token Element | Description |
---|---|
sub | Auth0 user_id of the user. |
iss | Hostname of your Auth0 tenant domain (e.g., example.auth0.com ). |
exp | Expiration time (in seconds) specified with the expiresInSeconds parameter. Should be as short as possible to avoid re-use of the token. Defaults to 900 seconds (15 minutes). |
ip | IP Address of the originating authentication request. |
email | Custom claim with a value specified in the payload.email parameter. |
externalUserId | Custom claim with a value specified in the payload.externalUserId parameter. |
signature | Using the secret specified above, the token will be signed with HS256 algorithm. |
sub
claim of the token.
/continue
endpoint. In some situations, you may want to pass data back to Auth0 to impact the authentication or for that user (for example, if you are implementing CAPTCHA checks or custom ).
event.user.app_metadata
object. This approach avoids passing sensitive information to Auth0 on the front channel.
state
claim within the token matches the state
parameter used as part of the redirect.Token Element | Description |
---|---|
sub | Auth0 user_id of the user. |
iss | Application that is targeted for the redirect. |
exp | Should be as short as possible to avoid reuse of the token. |
state | state parameter sent to the remote site as part of the redirect. This must be included in the token to avoid replay attacks. |
other | Any other custom claims will be exposed as the payload in the code above. |
signature | Token should be signed with the HS256 algorithm. |
/continue
endpoint. The tokenParameterName
option in the code allows you to specify the name of the field that contains your token.
event.authentication.methods
array will contain an entry for the custom method for the duration of the user’s browser session. Each entry in this array has a timestamp indicating when the authentication method was recorded.
A custom action can trigger a redirect if the required custom method is not in the event.authentication.methods
array or if the entry is too old.
You can use api.redirect.sendUserTo()
to send the user to a page that implements a custom authentication method. You can use the api.authentication.recordMethod()
in the exports.onContinuePostLogin
handler to store a record of the completed method in the user’s session.
The record stored in the event.authentication.methods
array will have a name
property matching the URL chosen in api.authentication.recordMethod()
. The URL captured here allows you to search through the current transaction’s completed authentication methods to determine if your custom method already completed.
Your workflow may require the custom method to be re-performed periodically during the life of a user’s session. For example, custom MFA scenarios may require user re-verification after a specified timeframe.
The example below compares the timestamp of an existing record to determine when to rerun the custom method:
api.authentication.recordMethod()
API is only available in the exports.onContinuePostLogin
handler. This avoids potential login exploits by recording the custom method after completing the redirect.
prompt=none
is to avoid any scenario where the user will be required to enter input, any redirection will result in an error=interaction_required
.
Since Actions run after an authentication session is created, you cannot use prompt=none
if you have a redirect rule that is attempting to block access to tokens under certain conditions (for example, custom MFA, CAPTCHA with login, and so on).
You cannot create a redirect flow that blocks token access and bypasses the redirect Action if prompt=none
because after a failed attempt, a user can simply call again with prompt=none
and get tokens because their authentication session has been created even though Actions failed the first time.
prompt=none
at all.
Any time api.redirect.sendUserTo()
is called in an Action, if prompt=none
was passed, then the authorization fails with error=interaction_required
, but since the user’s session is created even if Actions fail, we can’t trust that a user passed redirect challenges and therefore can’t use prompt=none
as a way to get tokens.
In this specific case, we recommend that you use refresh tokens exclusively, because you can ensure that a user passed challenges if those challenges are required to generate a refresh token.