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:
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:
client_secret_basic or client_secret_post). The easiest option.private_key_jwt). More secure, as no secret is sent.In the Admin UI go to Applications and click Create:
client_credentials) under grant typesclient_secret_post)https://api.quasr.io to be accepted by the Management API. It does by default; if you set your own Access Token Audiences, make sure to include it. Don't enable Access Token Encryption for such applications.In the application's Factors tab click Create, and choose the factor of step 1:
Then set the Authentication Factor (config.authentication.factor) of the application to this enrollment. See Applications — Configuration.
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:
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 ruleThe Billing Service: a rule and a permission for each of the granular scopes it needs
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.
https://api.quasr.io/scopes/admin/claims/search) and reads their account (https://api.quasr.io/scopes/admin/accounts/get). Create a scope control with Permission Required for each, see Management API — Authorization. See Authorization for the scopes of each operation.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_basiccurl -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_postcurl -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_jwtThe 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:
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.