ZITADEL Actions allow you to execute custom JavaScript code at specific points in authentication and authorization flows. This enables you to implement custom business logic, integrate with external systems, validate data, and manipulate user information beyond ZITADEL’s out-of-the-box capabilities.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/zitadel/zitadel/llms.txt
Use this file to discover all available pages before exploring further.
Why use Actions?
Actions solve problems that can’t be anticipated by ZITADEL’s standard features: Custom validation Implement domain-specific validation rules before users are created or authenticated, such as checking email domains against an allowlist or validating employee IDs. Automated workflows Automatically assign roles based on user attributes, sync data with external systems, or trigger notifications when specific events occur. Data enrichment Add custom metadata to users, modify claims in tokens, or integrate profile data from external sources during authentication. Integration requirements Connect ZITADEL to your existing business systems, trigger webhooks, call external APIs, or synchronize data across platforms.Actions Architecture
Actions consist of three main components:1. Action Script
A JavaScript function that contains your custom logic:2. Flow Type
The stage in the authentication/authorization process where the action runs:- External Authentication: After authentication with external identity provider
- Pre Userinfo Creation: Before userinfo endpoint returns claims
- Pre Access Token Creation: Before access token is created
- Complement Token: Add custom claims to tokens
- Customize SAML Response: Modify SAML response attributes
3. Trigger
The specific event within a flow type that executes the action.Action Configuration
Each action has the following configuration:| Property | Description |
|---|---|
| Name | Unique identifier for the action |
| Script | JavaScript code to execute |
| Timeout | Maximum execution time (in seconds) |
| Allowed to Fail | Whether the flow continues if action fails |
Creating Actions
Actions are created and managed through the ZITADEL Console or Management API.Assigning Actions to Flows
After creating an action, assign it to a flow:Context Object (ctx)
Thectx object provides information about the current flow:
User Context
Request Context
Authentication Request Context
API Object (api)
Theapi object provides methods to interact with ZITADEL and external systems:
User Management
Claims Manipulation
External HTTP Calls
Actions have access to thezitadel/http module for making HTTP requests:
Logging
UUID Generation
Common Use Cases
Assign Roles Based on Email Domain
Validate Email Domain
Enrich Token with External Data
Notify External System on User Registration
Add User to External System
Map External Identity Provider Groups to Roles
Actions v2 (New)
ZITADEL Actions v2 is the next generation of the Actions feature, providing more flexibility and capabilities:Key Differences
Actions v1:- JavaScript code executed within ZITADEL
- Limited to specific flow types
- Synchronous execution
- External HTTP endpoints (webhooks)
- Supports request, response, function, and event triggers
- Can be synchronous or asynchronous
- More flexible integration options
Actions v2 Components
- Target: External endpoint configuration
- Execution: When and which targets to call
- Endpoint: Your actual service implementation
Migrating to Actions v2
Actions v2 provides a migration path from v1 with external HTTP endpoints instead of JavaScript execution within ZITADEL.Action Execution Flow
- User triggers an authentication or API operation
- ZITADEL reaches the configured trigger point in the flow
- ZITADEL executes assigned actions in order
- Each action runs with the configured timeout
- If an action fails:
- Allowed to Fail = false: Flow stops, error returned to user
- Allowed to Fail = true: Flow continues to next action
- Flow completes or returns error
Timeouts and Performance
Actions have configurable timeouts to prevent blocking flows:- Default timeout: 10 seconds
- Maximum timeout: 60 seconds
- Recommendation: Keep actions fast (< 3 seconds)
- Cache external API responses when possible
- Use asynchronous operations for non-critical tasks
- Implement proper error handling and fallbacks
- Monitor action execution times
- Set realistic timeouts based on external dependencies
Error Handling
Actions should handle errors gracefully:Security Considerations
- Validate all inputs: Never trust data from context without validation
- Secure external calls: Use HTTPS and authenticate API requests
- Protect sensitive data: Don’t log passwords, tokens, or PII
- Limit permissions: Actions run with organization-level permissions
- Review action code: Audit actions before deploying to production
- Use secrets management: Don’t hardcode API keys in action scripts
- Implement rate limiting: Protect external APIs from abuse
- Handle errors safely: Don’t expose sensitive error details to users
Testing Actions
Test actions before deploying to production:- Use test users: Create dedicated test accounts
- Test error scenarios: Verify behavior when external systems are down
- Check timeouts: Ensure actions complete within timeout limits
- Validate outputs: Verify claims and metadata are set correctly
- Monitor logs: Review action execution logs for errors
- Test rollback: Verify “allowed to fail” behavior works as expected
Debugging Actions
Use logging to debug action execution:Best Practices
- Keep actions focused: Each action should do one thing well
- Use descriptive names: Name actions clearly to indicate their purpose
- Document your code: Add comments explaining complex logic
- Handle failures gracefully: Use try-catch and set “allowed to fail” appropriately
- Optimize performance: Minimize external API calls and execution time
- Version your actions: Keep track of changes to action scripts
- Test thoroughly: Validate actions in development before production
- Monitor execution: Track action performance and error rates
- Use actions sparingly: Don’t add unnecessary complexity to flows
- Consider Actions v2: Evaluate whether webhook-based actions are better for your use case
Limitations
- Actions are executed synchronously during the authentication flow
- JavaScript runtime is sandboxed (limited access to Node.js APIs)
- Maximum script size: 100 KB
- No access to filesystem or database
- HTTP calls are subject to configured deny lists
- Actions run within quota limits (execution time and requests)