n8n provides several authentication methods for API requests, from simple to advanced. Here's how to implement each type:
Built-in Authentication Methods
1. API Key Authentication
For Header-based API Keys:
- In HTTP Request node, go to Authentication section
- Select "Header Auth"
- Set header name (e.g.,
X-API-Key, Authorization)
- Set header value to your API key
For Query Parameter API Keys:
- Select "Query Auth"
- Set parameter name (e.g.,
api_key, token)
- Set parameter value
2. Bearer Token
- Select "Bearer Token" in authentication
- Enter your token value
- n8n automatically adds
Authorization: Bearer {token} header
3. Basic Authentication
- Select "Basic Auth"
- Enter username and password
- n8n handles the Base64 encoding automatically
4. OAuth2
For services supporting OAuth2:
- Select "OAuth2 API"
- Configure authorization URL, token URL, client ID, and client secret
- n8n handles the OAuth flow and token refresh
Using Credentials Manager
Best Practice: Store sensitive authentication data in n8n's credential manager:
- Go to Settings > Credentials
- Create new credential with your auth details
- In HTTP Request node, select your saved credential
- Reference it in authentication fields using expressions
Manual Header Authentication
For custom authentication schemes:
- In HTTP Request node, go to Headers
- Add custom headers manually:
Authorization: API_KEY your_key_here
X-Custom-Auth: your_custom_token
Cookie: session_id=abc123
Advanced Authentication Patterns
Token Refresh Workflows
For APIs requiring token refresh:
- Create a workflow that refreshes tokens
- Store new tokens in credentials
- Schedule periodic token refresh
- Use refreshed tokens in main workflows
Multi-step Authentication
Some APIs require multiple authentication steps:
- First HTTP Request: Login and get session token
- Set node: Extract token from response
- Subsequent requests: Use token in headers
Environment Variables
For deployment across environments:
- Use
$env.API_KEY expressions
- Set environment variables in your n8n deployment
- Reference them in credential fields
Security Best Practices
- Never hardcode API keys in workflows
- Use the Credentials Manager for all sensitive data
- Enable credential encryption in n8n settings
- Regularly rotate API keys and update credentials
- Use least privilege principle for API permissions
Common Authentication Examples
REST API with API Key:
Headers: Authorization: Bearer sk-1234567890abcdef
GraphQL with Token:
Headers: Authorization: token ghp_1234567890abcdef
Custom Header:
Headers: X-RapidAPI-Key: your_rapidapi_key_here
The key is matching n8n's authentication method to what your target API expects, and always using the credentials manager for secure storage of sensitive authentication data.