Applications — Machine (M2M)

Appplications

In this section you will learn how to set up an application for machine-to-machine (M2M) communication, i.e. a back-end, script or tool that calls an API on its own behalf rather than on behalf of a user. For example to build your own tenant administration, to connect your CRM or other tools with Quasr, or to configure your Quasr tenant automatically as part of your DevOps process.

Such applications use the OAuth 2.0 Client Credentials grant: they authenticate with their own credential (a client secret or a private key) at the token endpoint and receive an access token. To use the Management API, the access token must contain an admin scope, such as https://api.quasr.io/scopes/admin.

The setup consists of the following steps:

  1. Create a factor for the credential
  2. Create the application
  3. Create the credential
  4. Grant the scopes
  5. Request an access token
  6. Call the API

1. Create a factor

The application authenticates with an enrollment of a factor, so first make sure your tenant has a suitable factor. In the Admin UI go to Factors and click Create:

  • Secret - for a client secret (client_secret_basic or client_secret_post). The easiest option.
  • Private Key or Hosted Key Set - for signed assertions (private_key_jwt). More secure, as no secret is sent.
  1. 1Must be at least the score of the scopes the application requests - the Admin Access control requires 5

2. Create the application

In the Admin UI go to Applications and click Create:

  • choose a label and set the status to Enabled
  • enable Client Credentials (client_credentials) under grant types
  • select the authentication method matching your factor, e.g. Client Secret (Body) (client_secret_post)
  1. 1New applications start disabled - enable it, or token requests are rejected
  2. 2The only grant needed to get tokens on its own behalf
  3. 3Must match the credential: Client Secret (Header or Body) for a secret, Private Key (JWT) for a key

3. Create the credential

In the application's Factors tab click Create, and choose the factor of step 1:

  • for a secret, leave the value empty to have a strong secret generated
  • for a private key, provide your public key or leave it empty to have a key pair generated; for a hosted key set, provide its URL
  1. 1Leave empty and a strong secret is generated - it's shown only once, right after Create

Then set the Authentication Factor (config.authentication.factor) of the application to this enrollment. See Applications — Configuration.

4. Grant the scopes

The scopes an application can get are the scope controls attached to it with a rule. Admin scopes require a permission, so for each scope, in the application's Controls tab:

  1. attach the scope control, e.g. Admin Access (https://api.quasr.io/scopes/admin) or a more granular one, as required (always in the token) or optional (only when requested), and enable the rule
  2. grant the application a permission for the scope control, and enable it

The Billing Service: a rule and a permission for each of the granular scopes it needs

  1. 1The permission: grants the control to this application itself
  2. 2The rule: lets the application request the scope at all - a machine client needs both

Applications don't need to consent to scopes they request for themselves. If the application lacks the permission, or its factor's score is too low, the token request is rejected.

5. Request an access token

The application requests an access token at the token endpoint (https://{tenant_id}.api.quasr.io/oauth2/token) with grant type client_credentials, and optionally the space-separated scopes it wants in scope. The body can be form URL-encoded or JSON. Depending on the authentication method:

Client Secret (Header) - client_secret_basic
curl -X POST https://{tenant_id}.api.quasr.io/oauth2/token \    -u '{client_id}:{client_secret}' \    -d 'grant_type=client_credentials' \    --data-urlencode 'scope=https://api.quasr.io/scopes/admin'
Client Secret (Body) - client_secret_post
curl -X POST https://{tenant_id}.api.quasr.io/oauth2/token \    -d 'grant_type=client_credentials' \    -d 'client_id={client_id}' \    --data-urlencode 'client_secret={client_secret}' \    --data-urlencode 'scope=https://api.quasr.io/scopes/admin'
Private Key JWT - private_key_jwt

The client assertion is a token signed with the application's private key, with the client ID as iss and sub, the token endpoint as aud and a short expiry. See Factors — JWT.

curl -X POST https://{tenant_id}.api.quasr.io/oauth2/token \    -d 'grant_type=client_credentials' \    -d 'client_id={client_id}' \    -d 'client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer' \    -d 'client_assertion={signed_jwt}' \    --data-urlencode 'scope=https://api.quasr.io/scopes/admin'

A successful response looks as follows, where expires_in is in seconds and expires_at a Unix timestamp:

{    "token_type": "Bearer",    "access_token": "eyJhbGciOiJSUzI1NiIs...",    "expires_in": 86400,    "expires_at": 1767225600}

You can also try this from the Admin UI with the application's Test button:

  1. 1The scope parameter: scopes with a required rule are always in the token, optional ones only when requested

6. Call the API

The application calls the Management API with the access token as bearer token, for example to list the first 10 accounts of your tenant:

curl -X POST https://{tenant_id}.api.quasr.io/graphql \    -H 'Authorization: Bearer {access_token}' \    -H 'Content-Type: application/json' \    -d '{ "query": "query { listAccounts(limit: 10) { items { id label status } nextToken } }" }'

AI agents can use the same access token with the Agent API.

Best Practices

  • Reuse tokens - Request a new access token only when the current one is about to expire, rather than for every call. Access tokens are valid for 1 day by default (Access Token Expiration); keep this short for applications with broad scopes.
  • Mind the rate limits - Back-end integrations often run from a fixed IP, which is temporarily blocked when it exceeds 500 requests in 5 minutes. See Rate Limits.
  • Rotate credentials - Create a new enrollment, switch the application's authentication factor to it, and then delete the old one. With a hosted key set you can rotate keys without changing the application. See Rotation.
  • DevOps - When configuring your tenant from a CI/CD pipeline, store the credential in the pipeline's secret store and request a token at the start of each run.
2026.11.22 | © Copyright 2026 Quasr BV