Deploy Blnk
Local install or Blnk Cloud.
Enable authentication
Enable secure mode by settingserver.secure to true and providing a strong server.secret_key:
X-Blnk-Key header. Requests without a key are rejected.
The secret_key value becomes your master key. It has full access to every endpoint on the server, so use it only for administrative tasks and initial setup. For regular service traffic, create scoped API keys.
Pass the master key in the X-Blnk-Key header:
cURL
About the master key
The master key is thesecret_key from your configuration. Unlike scoped API keys, it is not bound to an owner or scopes, and it can call any endpoint on the server. Blnk also uses it to sign outbound webhook and transaction hook deliveries.
We recommend using the master key only for initial setup and administrative tasks listed below. For regular API calls, use the scoped keys you create.
-
Create scoped keys. Create your first scoped keys with
POST /api-keys. After that, services should use scoped keys, not the master key. -
Manage keys across owners. List, create, and revoke keys for any owner by passing
ownerin the request. Scoped keys can manage keys only within their ownowner_id. See Owner context. -
Manage hooks. Register, update, list, and delete transaction hooks. Hook management rejects scoped keys, even with
hooks:*scopes. -
Verify webhooks. Blnk signs outbound deliveries with
X-Blnk-Signatureusingserver.secret_key. Use the same secret on your receiver to verify authenticity. See Webhook security.
Security check list
Enabling secure mode is only the start. Work through this checklist to protect your master key, keep configuration out of version control, and limit API access to what each service needs.Master key management
- Use a strong, randomly generated master key
- Never share or commit it to version control
- Store it in environment variables or a secret management tool
- Rotate it on a regular schedule
Configuration management
- Exclude
blnk.jsonfrom version control (.gitignore) - Store sensitive configuration in environment variables
- Implement secure secret rotation procedures
Access control
- Follow the principle of least privilege: use scoped keys for services, not the master key
- Regularly review API key permissions. See Manage API keys
- Register and manage transaction hooks with the master key only
Monitoring and auditing
- Track failed authentication attempts
- Monitor API key usage patterns
- Set up alerts for suspicious activity
- Regularly review access logs
Error handling
Structured errors are available from Blnk Core 0.15.0 and later.
401 Unauthorized. These errors apply whether you use the master key or a scoped key.
| Code | When it happens |
|---|---|
AUTH_MISSING_API_KEY | No X-Blnk-Key header was sent with the request. |
AUTH_INVALID_API_KEY | The key value is unknown or malformed. |
AUTH_EXPIRED_API_KEY | The key has expired or has been revoked. |
401 Unauthorized
| Code | What to do |
|---|---|
AUTH_MISSING_API_KEY | Add the X-Blnk-Key header to your request. |
AUTH_INVALID_API_KEY | Verify the key value wasn’t truncated or swapped with another environment’s key. |
AUTH_EXPIRED_API_KEY | Create a replacement key before revoking the old one. See Manage API keys. |
Related docs
Scoped API keys
Create and use scoped keys.
Scopes
Pick the right permissions.
Owner context
Owner labels and cross-owner admin.
Manage keys
List, revoke, and delegate keys.