Skip to content

Auth0 Actions & Extensibility

Auth0 Actions (the evolution of Rules and Hooks) are the “Sovereign Script” of the Auth0 platform. They are serverless Node.js functions that execute at specific “Trigger Points” during the identity lifecycle—most notably during the login flow. Actions allow you to programmatically modify user profiles, add custom claims to JWT tokens, verify MFA status, and even call external APIs to detect fraud or synchronize data. For the IAM architect, Actions are the tool of Absolute Orchestration, providing the power to tailor every single authentication ceremony to your organization’s unique business and security requirements with code-level precision.

ACTIONS

Developer Sovereign
Core Mission
Identity Lifecycle Orchestration. Establishing a robust, code-driven framework for enriching tokens and automating security responses at machine-speed during the authentication handshake.
Like a Sophisticated Diplomatic Script: Imagine your login flow is a "Diplomatic Meeting." Most IdPs give you a fixed script you have to follow. Auth0 Actions allow you to write your own "Sovereign Script." When the visitor (The User) arrives, the script can stop the meeting to check their background (Call an API), it can give them a special badge based on their rank (Custom Claims), or it can even end the meeting instantly if it detects an imposter (Security Remediation). The meeting only proceeds if your script says "Success."
Token Enrichment / Fraud Detection / Role Mapping / Automated Provisioning / B2B Logic

Designing for extensibility requires choosing the right Action trigger for your functional goal.

TriggerStrategic ResponsibilityIAM Implementation
Login FlowReal-time Enrichment.Modifying the JWT (ID/Access Token) once a user successfully logs in.
Pre-User RegistrationData Guardrails.Validating an email domain or blocking specific sign-up attempts before the user is created.
Post-User RegistrationDownstream Sync.Triggering an API call to your CRM (Salesforce) or DB after a new user joins.
Post-Change PasswordSecurity Alerting.Sending a notification to Slack or an audit log when a password is changed.

An Action executes as a “Sandbox-Intervention” between authentication and token issuance.

graph LR
    Auth[Authenticated] --> Action[Auth0 Action: Node.js]
    Action --> Token[Issue Enriched Token]
1

Identify the Trigger Event

The user successfully enters their credentials. Before Auth0 signs the token, it triggers the **Login Action**. The user's profile and the context of the login (IP, User-Agent, App ID) are passed into your Node.js function. This is your "Sovereign Moment" to intervene.

2

Enrich & Validate (The Code)

You execute your logic. You might call an external API to check the user's subscription status in Stripe. You then use the `api` object to set a custom claim: `api.idToken.setCustomClaim('https://sovereign.corp/plan', 'gold')`. This data is now "Baking" into the identity.

3

Finality & Token Issuance

If the Action completes successfully, Auth0 proceeds to sign the tokens. If your Action calls `api.access.deny()`, the login is aborted instantly, even if the password was correct. This allows for **Real-time Security Enforcement** based on complex business rules that a static policy engine could never handle.


Writing an Action to add a ‘Role’ claim to a token is the most common use case for IAM architects.

/**
* Handler that will be called during the execution of a PostLogin flow.
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostLoginAPI} api - Interface whose methods can be used to alter the behavior of the login.
*/
exports.onExecutePostLogin = async (event, api) => {
const namespace = 'https://sovereign.corp';
// Adding custom roles based on user metadata
if (event.user.app_metadata.is_admin) {
api.idToken.setCustomClaim(`${namespace}/roles`, ['admin']);
api.accessToken.setCustomClaim(`${namespace}/roles`, ['admin']);
}
};

Master the technical ceremonies of identity logic and serverless orchestration.