Authentication, permissions and workspace scope
On this page
Keep three things apart in server code: the credential, the target workspace and the person you act for. None grants the others.
Plan: All plans
Every SDK request carries a credential (the integration key), a target workspace and sometimes an actor (the person on whose behalf you act). The API checks each one. Mixing them up, for example taking a workspace or user id from the browser, is the most common way integrations leak data, so the SDK keeps them apart.
Before you start #
- A trusted server application with the SDK registered.
- An explicitly authorized installation connection.
Step by step #
- 1Keep the credential on the serverResolve the SDK only in server code. Never send the integration key to JavaScript, and never expose a general-purpose browser proxy to the API. Load the key from a secret provider; for keys managed by the host, register a provider with
AddClientCraft<TConnectionProvider>(). - 2Treat the workspace as a target, not a permission
ForWorkspace(tenantId)returns a separately scoped client. It does not grant access or change the credential owner. The API decides whether this connection may work on that workspace.1using ClientCraft.Sdk;23public sealed class WorkspaceLeads(IClientCraftClient client)4{5 // workspaceId comes from your own trusted configuration or database, never from a request header or query string.6 public async Task<int> CountAsync(string workspaceId, CancellationToken ct)7 {8 var page = await client.ForWorkspace(workspaceId).Crm.Leads.ListAsync(cancellationToken: ct);9 return page.Total;10 }11} - 3Derive the actor on the serverAn interactive actor comes from a trusted server session through an approved context provider, or from
IClientCraftClientFactory.Create(connection, actorId)with an id you verified yourself. Never copy an actor or workspace id from a visitor's header or query parameter as proof of authority. A machine client without an actor does not invent one. - 4Keep each operation's identityUse a stable idempotency key for creates. Updates need the version the API returned and the full editable state. Don't retry a write with a new key after a timeout.
NoteA refused request is not evidence that the workspace is empty. Fix the grant or membership through supported administration. Never switch to another workspace, account or credential to hide the failure.
What happens next #
Create workspace API keys and webhooks for machine access without the SDK.
Was this article helpful?