Available on Blnk Core 0.10.1 and later.
transactions:write and balances:read, while your reporting service might only need *:read.
This keeps each service limited to the access it needs. If a key is exposed, you can revoke that key without rotating your master key or affecting the rest of your system.
Before you start
Scoped API keys require secure mode. When secure mode is enabled, Blnk requires every request to include a valid key in theX-Blnk-Key header.
Start by enabling secure mode and setting a strong secret_key in your configuration:
secret_key becomes your master key. Use it once to create your first scoped API key with POST /api-keys.
After that, use scoped keys for normal API traffic.
Create and use a scoped key
1
Create a scoped key
Use the master key to create your first scoped key. In this example, we create a key for a payments service:
A successful request returns
201 Created.2
Save the key
On success, the response includes the plaintext key in the Copy the
key field:201 Created
key value immediately and store it in your secrets manager or as an environment variable. Wire that value into the service that will call Blnk.3
Use the scoped key
Pass the scoped key in the Blnk checks that the key is valid, not expired or revoked, and that its scopes cover the endpoint you’re calling. This key has
X-Blnk-Key header on every request.transactions:write, so it can create transactions but cannot create ledgers without ledgers:write.API key tracking
When you create a record with a scoped API key, Blnk adds the key’sapi_key_id to the resource meta_data under BLNK_GENERATED_BY.
This lets you trace which key created a ledger, balance, transaction, or identity.
The master key does not add this field. Only scoped API keys authenticated through X-Blnk-Key do.
API key tracking
BLNK_GENERATED_BY automatically on POST requests. You do not need to include it in your request body. If you send your own meta_data, Blnk merges this field into it.
Error handling
Structured errors are available from Blnk Core 0.15.0 and later.
401 Unauthorized response.
401 Unauthorized
Other authentication errors, such as a missing
X-Blnk-Key header, are covered in Secure your Blnk server.