API FundamentalsAuthentication and Access Tokens

Authentication and Access Tokens

Exchange your client ID and client secret for a short-lived access token, and send that token with every Scrut API request.

The Scrut API uses the OAuth 2.0 client credentials grant. Your integration exchanges a client ID and client secret for a short-lived access token, then sends that token with every /v1 request.

Credentials and Tokens

Authentication uses two layers:

ItemWhat it isLifetime
API credentialA client ID and client secret that an Org Admin creates in the Developer Console12 months, never, or a custom date. Ends early if revoked.
Access tokenA Bearer token your integration requests with the credentialOne hour

To create, store, or revoke a credential, see Create API Credentials.

Important: Never commit credentials to version control or expose them in client-side code.

Get an Access Token

Send a POST request to /oauth/token with a JSON body. The token endpoint accepts application/json only, not application/x-www-form-urlencoded.

curl -X POST https://api.scrut.io/oauth/token \
  -H "Content-Type: application/json" \
  -d '{
    "grant_type": "client_credentials",
    "client_id": "'"$SCRUT_CLIENT_ID"'",
    "client_secret": "'"$SCRUT_CLIENT_SECRET"'"
  }'

Request Body

FieldRequiredValue
grant_typeYesAlways client_credentials
client_idYesThe client ID from your API credential
client_secretYesThe client secret from your API credential

Token Response

A successful request returns the token object:

{
  "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
  "token_type": "Bearer",
  "expires_in": 3600,
  "scope": "control:read, evidence:read, framework:read, policy:read, test:read, vulnerability:read"
}
FieldDescription
access_tokenThe token to send in the Authorization header
token_typeAlways Bearer
expires_inSeconds until the token expires
scopeThe scopes granted to your credential, as a comma-separated string. See Scopes and Permissions.

The token endpoint returns the standard OAuth token object. It doesn't use the { data, meta } envelope that /v1 endpoints use.

Send the Token

Include the token as a Bearer token in the Authorization header of every /v1 request:

curl https://api.scrut.io/v1/policies \
  -H "Authorization: Bearer $SCRUT_ACCESS_TOKEN"

Token Behavior

  • Tokens expire after 3600 seconds (one hour).
  • There's no refresh token. Request a new token with your credentials when the current one expires.
  • Several tokens from the same credential can be valid at the same time, until each one expires.
  • Revoking a credential invalidates all outstanding tokens.
  • When a credential expires, its tokens stop working, and new token requests fail. Create a new credential and update your integration before the expiry date.

Pro Tip! Reuse a token until it's close to expiring instead of requesting a new one for every call. The token endpoint allows 10 requests per 60 seconds per credential. See Rate Limits.

Authentication Errors

Error codeReturned byWhat to do
invalid_request/oauth/tokenCheck that grant_type is client_credentials and every field is present.
invalid_client/oauth/tokenVerify the client ID and secret. If the credential is revoked or expired, create a new one.
unauthorized/v1 endpointsCheck that the Authorization header contains a valid Bearer token.
token_stale/v1 endpointsRequest a new token.
token_revoked/v1 endpointsThe credential was revoked. Create a new credential.
token_credential_expired/v1 endpointsThe credential expired. Create a new credential.

For the full list, see Errors.

Contact support@scrut.io for further assistance.