You can use Auth0 Rules to redirect users before an authentication transaction is complete. This lets you implement custom authentication flows that require additional user interaction beyond the standard login form. Redirect rules are commonly used to do custom (MFA) in Auth0, but they can also be used for:Documentation Index
Fetch the complete documentation index at: https://auth0.generaltranslation.app/llms.txt
Use this file to discover all available pages before exploring further.
- Custom privacy policy acceptance, terms of service, and data disclosure forms.
- Securely performing a one-time collection of additional required profile data.
- Allowing remote Active Directory users to change their password.
- Requiring users to provide additional verification when logging in from unknown locations.
- Gathering more information about your users than they provided at initial signup.
Start redirect and resume authentication
context.redirect property as follows:
context.redirect.url property. Auth0 also passes a state parameter in that URL. For example:
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.
After the redirect, resume authentication by redirecting the user to the /continue endpoint and include 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:
If you’re using a :
THE_ORIGINAL_STATE is the value that Auth0 generated and sent to the redirect URL. For example, if your rule redirected to https://example.com/foo, Auth0 would use a redirect URL similar to https://example.com/foo?state=abc123. So abc123 would be the THE_ORIGINAL_STATE. To resume the authentication transaction, you would redirect to:
When a user has been redirected to the /continue endpoint:
- all rules will be run again, however, the
context.redirectwill be ignored to allow authentication to continue. - any changes to the user object are made during the redirect, prior to calling the
/continueendpoint. For example, updates through the Auth0 are available after continuing the transaction.
Validate resumed login
context.protocol property:
Force password change example
- The user attempts to log in and needs to change their password.
- The user is redirected to an application-specific page with a JWT in the query string. This JWT ensures that only this user’s password can be changed and must be validated by the application.
- The user changes their password in the application-specific page by having the application call the Auth0 Management API
- Once the user has successfully changed their password, the application extracts the
authorize_againclaim from the verified and decoded JWT, then proceeds to redirect the user to that URL allowing them to sign in with their new password.
Where to store data
Security considerations
UnauthorizedError).
If, however, you need to communicate directly back to Auth0 and give it instructions for restricting access (you are implementing CAPTCHA checks or custom MFA), then you must have a way to securely tell Auth0 that the requirements of that operation were performed. Likewise, if you need to hand information to the application that you are redirecting to, then you must have a secure way to ensure that the information transferred has not been tampered with.
Ensure app is logging into the same user
| Élément de jeton | Description |
|---|---|
sub | Le user_id d’Auth0 de l’utilisateur. |
iss | Un identifiant qui identifie la règle elle-même. |
aud | L’application ciblée par la redirection. |
jti | Une chaîne générée aléatoirement qui est stockée pour confirmation dans l’objet utilisateur (dans le code de règle, définissez user.jti = uuid.v4(); puis ajoutez-la en tant que jti au jeton que vous créez). user.jti sera toujours défini lorsque les règles s’exécuteront à nouveau lorsque /continue sera appelé. Ceci est conforme aux spécifications. |
exp | Doit être aussi court que possible pour éviter la réutilisation du jeton. |
other | Toute autre information de demande personnalisée que vous devez transmettre. |
signature | Si l’application dispose d’un emplacement sécurisé pour stocker un secret, vous pouvez opter pour des signatures HS256. Cela simplifie grandement la solution, et puisque le jeton retourné doit également être signé, cette approche satisfait cette exigence. RS256 est également une option, mais cela implique de générer un certificat et de le renouveler lorsqu’il expire. Si aucune information n’est directement transmise aux règles, vous pouvez envisager l’utilisation d’une application monopage (SPA) pour cet intermédiaire, en privilégiant RS256 afin d’éviter de stocker des informations au sein de l’application. Cela impliquerait que vous disposiez d’un mécanisme pour valider le jeton, soit en utilisant un point de terminaison d’introspection, soit en passant par un point de terminaison JWKS public. |
Pass information back to the rule
/continue endpoint. Only if the rule itself must get information and that information is only relevant to this particular sign in session should you pass information back to the rule.
When passing information back to the /continue endpoint, the token passed should have the following requirements:
| Élément jeton | Description |
|---|---|
sub | L’identifiant user_ID Auth0 de l’utilisateur. |
iss | L’application qui est ciblée pour la redirection. |
aud | Un identifiant qui identifie la règle elle-même. |
jti | Le même identifiant JTI qui a été stocké dans le jeton passé à l’application (NOTE : il doit correspondre à l’identifiant user.jti ou échouer). |
exp | Doit être aussi court que possible pour éviter la réutilisation du jeton. |
other | Toute autre information de demande personnalisée que vous devez transmettre. |
signature | En supposant que l’application dispose d’un emplacement sécurisé pour stocker un secret, vous pouvez utiliser des signatures signées par l’algorithme HS256. Cela réduit considérablement la complexité de la solution et comme le jeton renvoyé devra également être signé, c’est une exigence de cette solution. Vous pouvez utiliser l’algorithme RS256, mais il nécessite la création d’un certificat et la mise à jour de ce certificat lorsqu’il expire. |
context.request.body.token (or something similar) rather than passing it as a query parameter. This is similar to the form-post method for authentication.
If you are not passing information back to the /continue endpoint, you may want to denylist the JTI unless your expiration times are short enough that replay attacks will be almost impossible.
Restrictions and limitations
context.protocol:
- For Password exchange:
context.protocol === 'oauth2-password' - For exchange:
context.protocol === 'oauth2-refresh-token' - For logins:
context.protocol === 'oauth2-resource-owner'
Session timeout
Resource Owner endpoint
/oauth/token directly for the Resource Owner Password Grant. Since the user is not in a redirect flow to begin with, you can not redirect the user in a rule. If you attempt to set context.redirect you will get a failed login attempt with the error interaction_required.
Flows where prompt=none
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 rules 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 (custom MFA, CAPTCHA with login, etc.).
You cannot create a redirect flow that blocks token access and bypasses the redirect rule 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 rules failed the first time.
Refresh tokens
/oauth/token, this will also fail if you set context.redirect.
It is difficult to securely verify that any restrictions on login were carried out. There is not a consistent session ID in the context that could be used to collect information associated with the session such as this user passed MFA challenges. Therefore, you cannot use prompt=none at all.
Anytime context.redirect is set in a rule, if prompt=none was passed, then the authorization fails with error=interaction_required, but since the user’s session is created even if rules fail, we can’t trust that a user passed all context.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.