Authentication & Authorization
Comprehensive guide to configuring authentication and authorization for Elsa Workflows, covering OIDC providers, API keys, custom authentication, and security best practices.
This guide provides comprehensive instructions for securing your Elsa Workflows deployment with various authentication and authorization strategies. Whether you're integrating with existing identity providers, implementing API key authentication, or building custom authentication solutions, this guide covers everything you need to get started.
Overview
Elsa Workflows supports multiple authentication mechanisms to secure both the Elsa HTTP API and Elsa Studio:
No Authentication - For development and testing environments
Elsa.Identity - Built-in identity system with user management
OpenID Connect (OIDC) - Integration with external identity providers (Azure AD, Auth0, Keycloak, etc.)
API Keys - Token-based authentication for machine-to-machine communication
Custom Authentication - Implement your own authentication provider
Table of Contents
Prerequisites
Before configuring authentication, ensure you have:
Elsa Server project set up (see Elsa Server Setup)
.NET 8.0 or later SDK installed
Basic understanding of ASP.NET Core authentication
Access to your identity provider (if using OIDC)
No Authentication (Development Only)
⚠️ Warning: This configuration should only be used in development environments. Never deploy to production without proper authentication.
Disabling API Security
In your Elsa Server Program.cs, disable security requirements:
Disabling Studio Authorization
If using Elsa Studio (WASM or standalone), also disable authorization:
This allows all HTTP requests to proceed without authentication checks.
Using Elsa.Identity
Elsa.Identity is the built-in identity system that provides user management, roles, and permissions out of the box.
1. Install NuGet Packages
2. Configure Services
Add Elsa.Identity to your Program.cs:
3. Configure Default Admin User
Add admin user configuration to appsettings.json:
4. Create Additional Users
Use the Identity API endpoints to create additional users:
5. Obtain Authentication Token
Authenticate and get a JWT token:
Response:
Use the accessToken in subsequent requests:
OIDC Configuration
OpenID Connect (OIDC) allows you to integrate with external identity providers like Azure AD, Auth0, Keycloak, and others.
General OIDC Setup
Register your application with the OIDC provider
Obtain client ID and client secret
Configure redirect URIs
Install required NuGet packages
Configure authentication middleware
Azure AD Integration
Azure Active Directory (Azure AD / Microsoft Entra ID) is a popular choice for enterprise applications.
Step 1: Register Application in Azure Portal
Navigate to Azure Portal
Go to Azure Active Directory > App registrations
Click New registration
Configure:
Name: Elsa Workflows Server
Supported account types: Choose based on your requirements
Redirect URI:
Type: Web
URI:
https://your-elsa-server.com/signin-oidc
Click Register
Note the Application (client) ID and Directory (tenant) ID
Step 2: Create Client Secret
In your app registration, go to Certificates & secrets
Click New client secret
Add description and expiration
Click Add
Copy the secret value immediately (it won't be shown again)
Step 3: Configure API Permissions
Go to API permissions
Add permissions:
Microsoft Graph > Delegated >
User.ReadMicrosoft Graph > Delegated >
openidMicrosoft Graph > Delegated >
profileMicrosoft Graph > Delegated >
email
Click Grant admin consent (if you have admin privileges)
Step 4: Install NuGet Packages
Step 5: Configure Services in Program.cs
Step 6: Add Configuration to appsettings.json
Step 7: Configure Studio for Azure AD
In your Elsa Studio Program.cs:
Auth0 Integration
Auth0 is a flexible identity platform with extensive features for authentication and authorization.
Step 1: Create Auth0 Application
Log in to Auth0 Dashboard
Navigate to Applications > Applications
Click Create Application
Configure:
Name: Elsa Workflows Server
Type: Regular Web Application
Click Create
Step 2: Configure Application Settings
Go to Settings tab
Note the Domain, Client ID, and Client Secret
Configure Allowed Callback URLs:
Configure Allowed Logout URLs:
Configure Allowed Web Origins (for CORS):
Click Save Changes
Step 3: Create API in Auth0 (Optional)
For API-based authentication:
Navigate to Applications > APIs
Click Create API
Configure:
Name: Elsa Workflows API
Identifier:
https://your-elsa-api.comSigning Algorithm: RS256
Click Create
Step 4: Install NuGet Packages
Step 5: Configure Services in Program.cs
Step 6: Add Configuration to appsettings.json
Step 7: Obtaining and Using Tokens
To authenticate API calls with Auth0:
Obtain an access token using OAuth 2.0 Client Credentials flow:
Use the access token in API requests:
Generic OIDC Provider
You can integrate with any OIDC-compliant provider (Keycloak, IdentityServer, Okta, etc.).
Step 1: Install NuGet Packages
Step 2: Configure Services in Program.cs
Step 3: Add Configuration to appsettings.json
Example: Keycloak Configuration
For Keycloak specifically:
API Key Authentication
API key authentication is useful for machine-to-machine communication and automated workflows.
Implementation Approach
Elsa doesn't provide built-in API key authentication, but you can implement it using ASP.NET Core authentication handlers.
Step 1: Create API Key Model
Create a model to represent API keys:
Step 2: Create API Key Store
Implement a store to manage API keys:
Step 3: Create Authentication Handler
Implement a custom authentication handler:
Step 4: Register Services
In Program.cs:
Step 5: Create API Management Endpoints
Create endpoints to manage API keys:
Step 6: Using API Keys
Once you have an API key, include it in the request header:
Or in C#:
Persistent API Key Storage
For production use, store API keys in a database:
Custom Authentication Provider
You can implement completely custom authentication logic by creating a custom authentication handler.
Example: Header-Based Authentication
This example shows a custom authentication provider that validates users based on a custom header.
Step 1: Create Custom Authentication Handler
Step 2: Create User Service Interface
Step 3: Register Custom Authentication
In Program.cs:
Step 4: Using Custom Authentication
Multiple Authentication Schemes
You can support multiple authentication schemes simultaneously:
This configuration accepts either JWT Bearer tokens or API keys.
Studio Authentication Configuration
Elsa Studio needs to be configured to authenticate with the Elsa Server API.
Studio with JWT Bearer Tokens
When using JWT-based authentication (OIDC, Elsa.Identity):
Studio with OIDC
When using OpenID Connect:
Studio with API Keys
When using API key authentication:
Add to appsettings.json:
Studio WASM Configuration
For Elsa Studio WASM (WebAssembly), configure in the Program.cs of the WASM project:
With wwwroot/appsettings.json:
Troubleshooting
401 Unauthorized Errors
Symptom: Requests to the API return 401 Unauthorized.
Common Causes:
Missing or invalid authentication token
Verify the token is included in the
AuthorizationheaderCheck token format:
Authorization: Bearer <token>Ensure the token hasn't expired
Token validation issues
Verify the
Authorityconfiguration matches your identity providerCheck the
Audienceclaim in the token matches your API audienceEnsure clock skew between servers isn't causing validation failures
Authentication middleware not configured
Authentication scheme mismatch
Verify the authentication scheme name matches between configuration and handler
Solutions:
404 Not Found Errors
Symptom: Authentication endpoints return 404 Not Found.
Common Causes:
Incorrect callback URLs
Verify redirect URIs match exactly in both your code and identity provider configuration
Check for trailing slashes or protocol mismatches (http vs https)
Missing authentication endpoints
Ensure you've called
app.UseAuthentication()beforeapp.UseWorkflowsApi()
Route configuration issues
Verify the callback path matches your configuration:
Solutions:
CORS Issues with Studio
Symptom: Studio cannot connect to the API due to CORS errors.
Solution:
Token Expiration Issues
Symptom: Users are logged out frequently or get 401 errors intermittently.
Solutions:
Increase token lifetime:
Implement token refresh:
HTTPS/SSL Certificate Issues
Symptom: Authentication fails with SSL/TLS errors in development.
Solution (Development only):
For production, ensure proper SSL certificates are configured.
Debugging Authentication Flow
Enable detailed authentication logging:
Security Best Practices
1. Use HTTPS Everywhere
Always use HTTPS in production to protect authentication tokens in transit:
2. Secure Signing Keys
Store signing keys securely, never in source code:
Use Azure Key Vault, AWS Secrets Manager, or HashiCorp Vault in production:
3. Implement Token Expiration
Set appropriate token lifetimes:
4. Use Role-Based Access Control
Implement role-based authorization:
Apply to endpoints:
5. Implement Rate Limiting
Protect against brute force attacks:
6. Validate Redirect URIs
Always validate redirect URIs to prevent open redirect vulnerabilities:
7. Implement Logging and Monitoring
Log authentication events for security auditing:
8. Rotate API Keys Regularly
Implement API key rotation:
9. Protect Against CSRF
Enable anti-forgery tokens for cookie-based authentication:
10. Security Headers
Add security headers to responses:
Production Considerations
1. Distributed Caching for Tokens
When running multiple instances, use distributed caching:
2. Database-Backed User Store
Use a database for user management:
3. Load Balancer Configuration
Configure sticky sessions or use token-based authentication:
4. Health Checks with Authentication
Exclude health check endpoints from authentication:
5. Environment-Specific Configuration
Use different configurations for different environments:
6. Monitoring and Alerting
Monitor authentication metrics:
7. Backup Authentication Method
Always have a backup authentication method:
8. Regular Security Audits
Schedule regular security reviews:
Review access logs monthly
Audit active API keys quarterly
Test authentication flows after each deployment
Scan for vulnerabilities with tools like OWASP ZAP
Keep dependencies updated
9. Disaster Recovery
Document recovery procedures:
Key rotation procedures
User account recovery process
Emergency access procedures
Backup identity provider configuration
10. Documentation
Maintain documentation for:
Authentication architecture diagrams
Configuration management procedures
Troubleshooting guides
Security incident response plans
Runbooks for common operations
Summary
This guide covered comprehensive authentication and authorization strategies for Elsa Workflows:
No Authentication: Development/testing only
Elsa.Identity: Built-in user management system
OIDC Providers: Azure AD, Auth0, and generic OIDC integration
API Keys: Machine-to-machine authentication
Custom Providers: Implementing custom authentication logic
Studio Configuration: Connecting Studio to authenticated APIs
Troubleshooting: Common issues and solutions
Security: Best practices for production deployments
Choose the authentication strategy that best fits your requirements, considering factors like:
Organization's existing identity infrastructure
Compliance and regulatory requirements
User experience needs
Operational complexity
Scalability requirements
For additional help, refer to:
If you encounter issues not covered in this guide, please open an issue on the Elsa Workflows GitHub repository.
Last updated