Scoped API keys, and machine access for your customers
Two different keys are easy to mix up: the one your backend uses to call the platform, and the one your customer’s server uses to call you. Each should carry the least power that does the job.
6 min read · Last checked
In short
Key points
- An organization API key carries a list of scopes, and every call checks for the scope it needs.
- Scopes are exact. Scopes that spend money or return credentials are not part of any composite.
- The scope catalog is public, so you can read it before creating a key.
- Customer machine credentials are bound to one tenant, one environment and the permissions you define.
Your backend: least-privilege API keys
Send the key in the X-TenancyEngine-Api-Key header. A call without the needed scope returns 403 naming the missing scope, and creating a key with a scope that does not exist returns 400. Give each key only what its backend needs.
- A scope satisfies only its own check. The overlaps are two legacy scopes, listed in each scope’s grantedBy field.
- Scopes that spend money or return credentials, such as sms.send, ai.extract and secrets.read, need that exact scope.
- Some scopes are limited to organization-wide keys; the catalog shows each restriction.
curl https://api.saasruntime.com/api/v1/public/api-key-scopesYour customer’s server: machine credentials
Customers often want to call your product API from their own servers: a nightly sync, a worker, an ERP connector. TenancyEngine issues them machine credentials, and your API verifies the resulting tokens locally with the .NET SDK. You do not build a key store.
- Define API permissions for your application, namespaced with your application slug.
- Issue a credential to one customer tenant, choosing one environment, an expiry of at most two years and the permissions. The secret is shown once.
- The binding to organization, application, tenant, environment and permissions is fixed at creation; nothing in a token request can change it.
- Platform and sign-in scopes such as openid or anything starting with platform can never be used, so a customer credential cannot carry platform powers.
Which key does what
- Organization API key: your backend calling TenancyEngine, for example to create workspaces or read entitlements.
- Machine credential: your customer’s server calling your product API, verified by your API.
- Neither replaces the other, and a machine credential can never carry platform or sign-in scopes.
Controls around it
- Changing credentials needs both applications.configure and tenants.write, so read-only and billing roles cannot change them.
- Every change is audited with the tenant.
- Credentials cannot be created, rotated or renewed during a support (impersonation) session.
Honest limits
What to know before you rely on this
- Local token verification is documented for the .NET SDK (TenancyEngine.Sdk).
- Two scopes listed as reserved have no route that accepts them yet; the catalog marks them.
Questions people ask
Is a machine credential the same as my organization API key?
No. The API key is how your backend calls TenancyEngine. A machine credential is how your customer’s server calls your API.
Can a customer credential reach another customer’s data?
The credential is bound to one tenant, one application and one environment when it is created, and the binding cannot be changed by a token request.
Sources
Keep reading
Try it on the free plan
One app and five customers, no credit card required.