The End of Life (EOL) date of Rules and Hooks will be November 18, 2026, and they are no longer available to new tenants created as of October 16, 2023. Existing tenants with active Hooks will retain Hooks product access through end of life.We highly recommend that you use Actions to extend Auth0. With Actions, you have access to rich type information, inline documentation, and public
npm
packages, and can connect external integrations that enhance your overall extensibility experience. To learn more about what Actions offer, read Understand How Auth0 Actions Work.To help with your migration, we offer guides that will help you migrate from Rules to Actions and migrate from Hooks to Actions. We also have a dedicated Move to Actions page that highlights feature comparisons, an Actions demo, and other resources to help you on your migration journey.To read more about the Rules and Hooks deprecation, read our blog post: Preparing for Rules and Hooks End of Life.POST /oauth/token
endpoint using the Client Credentials Flow. For example, you may deny the token from being issued, add custom claims to the access token, or modify its scopes. To learn more, read Client Credentials Flow.
Hooks at this extensibility point are blocking (synchronous), which means they execute as part of the trigger’s process and prevent the rest of the Auth0 pipeline from running until the Hook is complete.
The
triggerId
for the Client Credentials Exchange extensibility point is credentials-exchange
. To learn how to create hooks for this extensibility point, read Create Hooks.Starter code and parameters
When creating a Hook executed at the Client Credentials Exchange extensibility point, you may find the following starter code helpful. Parameters that can be passed into and used by the Hook function are listed at the top of the code sample.-
The callback function (
cb
) at the end of the sample code signals completion and must be included. -
The line
access_token.scope = scope
ensures that all granted scopes will be present in the access token. Removing it will reset all scopes, and the token will include only scopes you add with the script.
Default response
When you run a Hook executed at the Client Credentials Exchange extensibility point, the default response object is:Starter code response
Once you’ve customized the starter code with your scopes and additional claims, you can test the Hook using the runner embedded in the Hook Editor. The runner simulates a call to the Hook with the same body and response that you would get with a Client Credentials Exchange.Executing the code using the runner requires a save, which means that the original code will be overwritten.
Sample script: Add an additional scope to the access token
In this example, we use a Hook to add an additional scope to those already existing for the access token.Response
When we run this Hook, the response object is:Sample script: Add a claim to the access token
In this example, we add a namespaced custom claim and its value to the access token. To learn more, read Create Namespaced Custom Claims. You can add the following as claims to the issued token:- The
scope
property of the response object - Any properties with namespaced property names
To access a configured Hook Secret from within a hook, use
context.webtask.secrets.SECRET_NAME
.Response
When we run this Hook, the response object is:Sample script: Raise an error or deny an access token
In this example, we use custom Error objects to generate OAuth2 Error Responses. (To learn more, see OAuth2 RFC - Section 5.2 in the IETF Datatracker.) If a plain JavaScript error is returned in the callback, such as:client_credentials
grant from the /oauth/token
endpoint, Auth0 will respond with:
InvalidScopeError
client_credentials
grant is from the /oauth/token
endpoint, Auth0 responds with:
InvalidRequestError
client_credentials
grant from the /oauth/token
endpoint, Auth0 will respond with:
ServerError
client_credentials
grant from the /oauth/token
endpoint, Auth0 responds with:
Currently, the behavior of the built-in JavaScript
Error
class and ServerError
is identical, but the ServerError
class allows you to be explicit about the OAuth2 error that will be returned.