Skip to content

Client credentials

A service signs in as itself with a key pair (private_key_jwt) or a secret, and gets a short token with the scopes it needs.

Applies to EngineCloud
View as Markdown
On this page
  1. Create a client
  2. Get a token
  3. What the token can do

Create a client

In the console → Machines → OAuth clients, or with the API:

Terminal
curl -X POST https://<ref>.data.sypnia.com/auth/v1/admin/oauth/clients \
  -H "apikey: syp_sk_…" -H "content-type: application/json" \
  -d '{ "name": "billing-worker", "token_endpoint_auth_method": "private_key_jwt",
        "jwks": { "keys": [ { "kty": "OKP", "crv": "Ed25519", "x": "…", "kid": "bw-1" } ] },
        "scopes": ["data:read", "data:write"], "dpop_bound_access_tokens": true }'

The answer has the client_id (cli_…). With a key pair, the private key never leaves your service: the engine only knows the public half.

AuthenticationWhen
private_key_jwtRecommended. Nothing secret is stored by the engine; keys rotate by adding a new public key.
client_secret_basic / client_secret_postWhen a key pair is not possible. The secret (syp_cs_…) is shown once and stored as an argon2id hash.

Get a token

Sign a short JWT with your private key (RFC 7523) and send it:

Text
POST /auth/v1/oauth/token
content-type: application/x-www-form-urlencoded

grant_type=client_credentials
&client_id=cli_8fK2…
&client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer
&client_assertion=<JWT: iss=sub=cli_8fK2…, aud=https://<ref>.data.sypnia.com/auth/v1/oauth/token, exp=now+60, jti=random>
&scope=data:read data:write
JSON
{ "access_token": "eyJ…", "token_type": "DPoP", "expires_in": 900, "scope": "data:read data:write" }
  • The assertion lives at most 5 minutes and its jti works once.
  • scope must be within the client’s allowed scopes; resource (RFC 8707) picks the audience when the client may call several.
  • Client tokens last 15 minutes by default; ask for a new one when it expires. There is no refresh token for client credentials.

What the token can do

The client calls the Data API and SQL like anyone else. By default it runs as the authenticated role with sub set to its client_id, so your row-level security applies to machines too: write policies with sypnia.client_id(). A client with project:admin runs as service_role.

@sypnia/data/server does all of this for you:

TypeScript
import { createClient } from '@sypnia/data/server';
const sypnia = createClient(url, { client: { id: 'cli_8fK2…', privateKey: process.env.SYPNIA_CLIENT_KEY!, dpop: true } });
  1. Create a client
  2. Get a token
  3. What the token can do

    Search pages, sections and terms