Skip to content

Customer machine access to your API ​

Your customers often want to call your product API from their own servers: a nightly sync job, a Linux worker, an ERP connector. TenancyEngine issues those customers machine credentials and your API verifies the resulting tokens locally with TenancyEngine.Sdk. You never build a key store, and one customer's credential can never reach another customer, another product or another environment.

The .NET pieces on this page (AddTenancyEngineMachineAccess, RequireTenancyEngineMachineScope, TenancyEngineMachineTokenClient) need TenancyEngine.Sdk 2.1.0 or later; use 2.3.0.

This page is for the ISV (you). Your customers only ever see a client ID, a client secret shown once, and the permissions you defined.

How it fits together ​

WhoHasDoes
You (the ISV)Your application in TenancyEngine, its environments, and a list of API permissionsDefine permissions, issue credentials to customer tenants, verify tokens in your API
Your customerOne tenant of your application, and one or more machine credentialsRuns a server or worker that exchanges its credential for a short-lived token, then calls your API
TenancyEngineThe token issuer (https://auth.saasruntime.com)Issues tokens bound to exactly one tenant, one environment and the granted permissions

The binding is fixed when the credential is created: organization (yours), application, tenant (the customer), environment (for example Staging as a sandbox, Production for live traffic) and permissions. Nothing in a token request can change it.

Machine credentials are separate from your organization API key: the API key is how your backend calls TenancyEngine; a machine credential is how your customer's server calls your API.

1. Define your API permissions ​

Console: Applications → your app → Environments → API permissions → Add permission.

Each permission is a key your API checks, namespaced with your application slug, for example bankweave.accounts.read or bankweave.payments.initiate. Keys are lowercase letters, digits, ., _, : and -. Platform and sign-in scopes (openid, offline_access, api, email, profile, roles, anything starting with platform: or platform.) can never be used, so a customer credential can never carry platform powers.

Deactivating a permission stops new tokens that include it; a credential that holds it is refused at its next token request until the permission is reactivated or the credential is replaced.

API: GET|POST /api/v1/admin/applications/{applicationId}/resource-scopes, PUT /api/v1/admin/applications/{applicationId}/resource-scopes/{scopeId} (needs applications.configure to change, applications.read to list).

2. Issue a credential to a customer ​

Console: Tenants → the customer → Environment access → Machine access → Create credential. Choose a name, one environment the tenant has access to, an expiry (at most two years) and the permissions. The secret is shown once; give it to the customer through your normal secure channel. The list then shows environment, permissions, expiry, last used and status, never the secret.

Creating, rotating, renewing and revoking a credential needs both applications.configure and tenants.write on the application. Read-only and billing roles cannot change credentials. Every change is written to the audit log with the tenant.

Credentials cannot be created, rotated or renewed during an impersonation (support) session: the request is refused with 403 and code machine_credential_impersonation_forbidden, and the attempt is audited against the staff member, not the customer. Revoking still works, so support can contain a leaked secret. The client ID is generated ({environment client ID}-m-{16 hex}); the credential name you choose is a label only.

API: POST /api/v1/admin/applications/{applicationId}/oauth-clients with boundTenantId, applicationEnvironmentId, scopes, expiresAtUtc and clientType: "Confidential"; then .../oauth-clients/{id}/rotate-secret, .../renew, .../revoke. A customer's own tenant administrator can do the same through /api/v1/portal/oauth-clients with a tenant session (no TenancyEngine console access needed).

3. Your customer's worker gets a token ​

The customer calls the standard OAuth 2.0 client credentials grant:

http
POST https://auth.saasruntime.com/connect/token
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials&client_id=bankweave-m-3f9c2a7d41b0e6c8&client_secret=...&scope=bankweave.accounts.read

scope is optional (all granted permissions when omitted) and can only narrow the grant. Passing tenant_id, application_id, organization_id, environment, environment_id, audience or resource is rejected. There is no refresh token; request a new token when it expires.

Token requests are rate limited: 30 a minute per credential and 60 a minute per source IP. Past that the endpoint answers 429 with a Retry-After header. A worker that caches its token until shortly before expiry (the SDK token client does) needs about one request every four minutes.

With the .NET SDK (console app, Linux worker or another API host):

csharp
var platform = builder.Configuration.AddTenancyEngineEnvironment(builder.Environment.EnvironmentName);
// TenancyEngine:MachineAccess:ClientId, :ClientSecret (from a secret store), :Scopes
builder.Services.AddTenancyEngineMachineTokenClient(
    builder.Configuration.GetSection("TenancyEngine:MachineAccess"), platform);
builder.Services.AddHttpClient("bankweave", c => c.BaseAddress = new Uri("https://api.bankweave.example"))
    .AddTenancyEngineMachineToken();   // attaches a cached bearer, refreshes before expiry

The token client caches one token per credential, refreshes it 60 seconds before expiry, shares one request between concurrent callers, and picks up a rotated secret when the configuration source reloads (or call UpdateCredentials). Errors are typed and redacted (TenancyEngineMachineTokenException.Error is RejectedCredentials, IssuerUnavailable or InvalidResponse); no secret, token or upstream body appears in exception text or logs.

Browser and mobile apps must never hold a machine credential.

4. Your API verifies the token ​

csharp
var platform = builder.Configuration.AddTenancyEngineEnvironment(builder.Environment.EnvironmentName);
builder.Services.AddAuthentication()
    .AddTenancyEngineMachineAccess(builder.Configuration.GetSection("TenancyEngine:MachineAccess"), platform);
// ApplicationId, EnvironmentId, EnvironmentName, AllowedScopes: public identifiers, not secrets
builder.Services.AddAuthorizationBuilder()
    .AddPolicy("accounts.read", p => p.RequireTenancyEngineMachineScope("bankweave.accounts.read"));

app.MapGet("/accounts", async (HttpContext http) =>
{
    var caller = await http.GetTenancyEngineMachinePrincipalAsync();
    // caller.TenantId is the customer. Scope every query to it.
    return Results.Ok(await accounts.ListAsync(caller.TenantId));
}).RequireAuthorization("accounts.read");

The SDK checks the signature against the issuer's published keys, the issuer, the exact audienceurn:tenancyengine:application:{applicationId}:environment:{environmentId}, the token type (at+jwt), the lifetime, and that every binding claim is present exactly once. Expiry is exact; iat and nbf may be up to 60 seconds ahead of your host's clock, so a host whose clock runs slightly behind TenancyEngine does not reject fresh tokens. A token for another product, another environment or with a permission outside AllowedScopes is rejected with 401. When a request also names a tenant in its route or body, pass it as a selector so a mismatch fails:

csharp
var caller = await http.GetTenancyEngineMachinePrincipalAsync(new TenancyEngineMachineSelectors(TenantId: routeTenantId));

Verification makes no call to TenancyEngine per request.

Token claims ​

ClaimValue
issThe TenancyEngine issuer for the lane
audurn:tenancyengine:application:{applicationId}:environment:{environmentId}
sub, client_idThe credential's client ID
principal_kindmachine
organization_idYour TenancyEngine organization (not the customer's)
application_id, environment_id, environmentYour application and the credential's environment
tenant_idThe customer's tenant
scopeSpace-separated granted permissions
exp - iatAt most 300 seconds

Revocation, expiry and outages ​

EventEffect
Credential revoked, expired, or its secret rotatedNew tokens refused immediately
Tenant suspended, environment deactivated or removed from the tenant, application or organization deactivated, permission deactivatedNew tokens refused immediately
Tokens already issuedValid until they expire: at most 5 minutes (the declared revocation latency)
TenancyEngine issuer unreachableYour API keeps verifying existing tokens from cached signing keys; workers cannot get new tokens and see IssuerUnavailable within 5 minutes at most

If you need faster cut-off for a specific customer, enforce it in your own API as well (for example a per-tenant kill switch); the 5-minute bound is the platform guarantee.

Rotation without downtime: create a second credential for the same tenant and environment, deploy it, confirm Last used moves to the new one, then revoke the old one. Both work during the overlap. Rotate secret replaces the secret in place and is immediate for new token requests.

What a machine token does not grant ​

A valid token proves which customer is calling and which permissions you granted. It does not prove that the customer's subscription is active, does not grant paid features or usage, and does not grant any consent that your product handles itself (for example bank account consent). Check entitlements and your own resource authorization separately, scoped to caller.TenantId.

Machine tokens are not accepted by TenancyEngine's own APIs and are not accepted by other products.

TenancyEngine platform documentation