API Key Authentication Plugin
Features
Section titled “Features”- API key-based authentication
- Role-based access control
- Custom permissions per API key
- IP whitelisting support
- System role support
Configuration
Section titled “Configuration”To use the API Key Authentication plugin, you need to configure it in your application. Here’s how to set it up:
... plugin: [ new GDapiKeyAuthentication({ enable: true, apiKeys: { myApiKeyName: { token: API_KEY_TOKEN, permissions: { // put here any permission that you want to give to the apiKey isEmailVerified: true, isCustomerWithApiKey: true, } } } }) ],...
Configuration Options
Section titled “Configuration Options”enable
: (boolean) Enable or disable the pluginapiKeys
: (object) Configuration for your API keys[apiKeyName]
: (object) Configuration for a specific API keytoken
: (string) The API key tokenpermissions
: (object) Custom permissions for this API keyrole
: (string) Optional role assignment_id
: (string) Optional user ID to associate with this API keyipWhitelist
: (string | string[]) Optional list of allowed IP addresses
To authenticate using an API key, include it in your request headers. When using the SDK, use:
$.setHeaders({ apiKey: 'myApiKey' })
Authentication Flow
Section titled “Authentication Flow”- When a request is made with an API key:
- The plugin checks if the API key exists and is valid
- If valid, it assigns the configured role and permissions to the request
- If the API key has an associated user ID, it will be used for the request
- The authentication method is marked as ‘apiKey’
Security Best Practices
Section titled “Security Best Practices”- Always use IP whitelisting when possible to restrict API key usage to specific IP addresses
- Use strong, randomly generated API key tokens
- Regularly rotate API keys
- Assign minimal required permissions to each API key
- Monitor API key usage for suspicious activity
Error Handling
Section titled “Error Handling”The plugin will reject requests that:
- Use an invalid or expired API key
- Come from non-whitelisted IPs (if IP whitelisting is enabled)
- Attempt to use an API key with insufficient permissions
Example Use Cases
Section titled “Example Use Cases”- Server-to-server communication
- Third-party API integration
- Automated testing
- Backend service authentication
- Microservice communication