Authenticating as an API client

Your integration authenticates as an API client with the OAuth 2.0 client-credentials grant: a service presents the client's id and secret and gets back an access token, with no person signing in. An API client is confidential: it holds a secret, so keep the secret server-side.

Get a token with client credentials

POST the token endpoint with grant_type=client_credentials, your client ID and secret, and the audience.

Never hard-code a secret. Load <CLIENT_SECRET> from an environment variable or a secrets manager. The examples read it from the environment.

curl
curl -sS -X POST https://auth.cybersentriq.com/oauth/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  --data-urlencode "grant_type=client_credentials" \
  --data-urlencode "client_id=<CLIENT_ID>" \
  --data-urlencode "client_secret=$CSIQ_CLIENT_SECRET" \
  --data-urlencode "audience=https://api.cybersentriq.com" \
  --data-urlencode "scope=api:full:read api:full:write"
TypeScript / Node
const body = new URLSearchParams({
  grant_type: "client_credentials",
  client_id: process.env.CSIQ_CLIENT_ID!,
  client_secret: process.env.CSIQ_CLIENT_SECRET!,
  audience: "https://api.cybersentriq.com",
  scope: "api:full:read api:full:write",
});

const res = await fetch("https://auth.cybersentriq.com/oauth/token", {
  method: "POST",
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
  body,
});
const { access_token } = await res.json();
Python
import os
import requests

res = requests.post(
    "https://auth.cybersentriq.com/oauth/token",
    data={
        "grant_type": "client_credentials",
        "client_id": os.environ["CSIQ_CLIENT_ID"],
        "client_secret": os.environ["CSIQ_CLIENT_SECRET"],
        "audience": "https://api.cybersentriq.com",
        "scope": "api:full:read api:full:write",
    },
)
access_token = res.json()["access_token"]
C#
using System.Net.Http;
using System.Text.Json;

var http = new HttpClient();
var form = new FormUrlEncodedContent(new Dictionary<string, string>
{
    ["grant_type"] = "client_credentials",
    ["client_id"] = Environment.GetEnvironmentVariable("CSIQ_CLIENT_ID"),
    ["client_secret"] = Environment.GetEnvironmentVariable("CSIQ_CLIENT_SECRET"),
    ["audience"] = "https://api.cybersentriq.com",
    ["scope"] = "api:full:read api:full:write",
});

var res = await http.PostAsync("https://auth.cybersentriq.com/oauth/token", form);
using var doc = JsonDocument.Parse(await res.Content.ReadAsStringAsync());
var accessToken = doc.RootElement.GetProperty("access_token").GetString();
Go
form := url.Values{
    "grant_type":    {"client_credentials"},
    "client_id":     {os.Getenv("CSIQ_CLIENT_ID")},
    "client_secret": {os.Getenv("CSIQ_CLIENT_SECRET")},
    "audience":      {"https://api.cybersentriq.com"},
    "scope":         {"api:full:read api:full:write"},
}

res, err := http.PostForm("https://auth.cybersentriq.com/oauth/token", form)
if err != nil {
    log.Fatal(err)
}
defer res.Body.Close()

var tok struct {
    AccessToken string `json:"access_token"`
    ExpiresIn   int    `json:"expires_in"`
    TokenType   string `json:"token_type"`
}
json.NewDecoder(res.Body).Decode(&tok)

Request both access scopes unless your integration only reads. See Access scopes.

The response is a bare access token. There is no refresh token for client credentials:

JSON
{
  "access_token": "eyJhbGciOiJSUzI1Ni(truncated)",
  "expires_in": 3600,
  "token_type": "Bearer"
}

The token's granted scope reflects what your API client's role allows: a viewer role receives api:full:read alone, a user or admin role both. What the client may do is decided by the API from its role when it calls. See Access scopes.

Renewing the access token

A token lasts an hour. Cache it and request another shortly before expires_in runs out, which at an hour means roughly hourly; requesting one per API call will find the token endpoint's rate limit instead. The client-credentials grant issues no refresh token and needs none: your service already holds the secret that gets it a token, so there is nothing to exchange.

If a call answers 401, request a new token and retry once. See Building an end-to-end integration for that pattern in every language.

Your first API client

You create your first API client from the API reference, signed in as an administrator of your organization:

  1. Select Log in and sign in to your CyberSentriq account.
  2. In the API reference, open GET /self/me, select Test Request, and send it. The response's orgId is the organization id you need. Leave the bearer token empty: the request runs as you.
  3. Open POST /iam/api-clients, select Test Request, and send your organization, a name and a role as the body, for example {"orgId":"<ORG_ID>","name":"nightly-backup-worker","role":"user"}.
  4. Store the secret from the response in your secrets manager. It is shown only once.

Creating a client asks you to verify your identity again if your last multi-factor check is not recent. The reference shows a Verify with MFA notice when that happens: complete the check, then send the request again. See Step-up verification in the API reference.

From then on your integration authenticates as that client, and can provision further clients through the API with its own token.

Provisioning an API client through the API

Once you hold an API client, you provision more through the API.

POST https://api.cybersentriq.com/iam/api-clients creates an API client on an organization you administer: a dedicated OAuth client is minted for the audience, and the new client's clientId and credential are returned. The same resource supports listing, reading, updating, rotating the secret, rolling public keys and deleting. For the full lifecycle, with the request and response fields and worked examples in every language, see Managing API clients.

The call needs an access token that carries api:full:write. See Access scopes.

Both client-secret and private_key_jwt authentication are supported for the minted client; choose with credentialType when you create it.

Send the organization, a name and a role as a JSON body:

Shell
curl -sS -X POST "https://api.cybersentriq.com/iam/api-clients?apiVersion=1.0" \
  -H "Authorization: Bearer <ADMIN_ACCESS_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{"orgId":"<ORG_ID>","name":"nightly-backup-worker","role":"user"}'

On success, you receive the new client's clientId and, for a secret client, its secret (shown once). Store the secret in your secrets manager, then use it with the client-credentials grant above.

This is the supported path for API integrations: provision your own API clients through the API. For the full lifecycle (create, list, read, update, rotate the secret, roll keys and delete, with the request and response fields and worked examples in every language), see Managing API clients.

Next