Brindlemark Sandbox API · How-to guide and reference

Authentication

Get an access token with the OAuth 2.0 client credentials grant, send it with every request, and renew it before it expires.

Fictional sandbox. An independent demonstration with fictional data. It isn’t affiliated with or endorsed by Swan or any bank, and it isn’t legal advice.

The sandbox uses the OAuth 2.0 client credentials grant. Your platform's server sends its client ID and secret to the token endpoint, gets an access token, and sends that token with every GraphQL request. No user takes part: the token acts for your platform.

Setting Value in the sandbox
Token endpoint POST http://localhost:4100/oauth/token
Grant type client_credentials
Client ID sandbox-demo, or SANDBOX_CLIENT_ID
Client secret sandbox-demo-secret, or SANDBOX_CLIENT_SECRET
Token type Bearer
Lifetime 3,600 seconds, given as expires_in

Get an Access Token#

Send the grant type and your credentials as a form, application/x-www-form-urlencoded. curl's -d sends that type:

Example: Get an access token

curl -s -X POST http://localhost:4100/oauth/token \
  -d grant_type=client_credentials \
  -d client_id=sandbox-demo \
  -d client_secret=sandbox-demo-secret

Response, HTTP 200, with the headers Cache-Control: no-store and Pragma: no-cache:

{
  "access_token": "sbx_LZgZ9TMrtTuMJBwuFgG9Y6f5a4lzQlmK",
  "token_type": "Bearer",
  "expires_in": 3600
}
Field What it is
access_token The token to send with each request. Treat it like a password: don't log it.
token_type Always Bearer.
expires_in Seconds until the token stops working.

Cache-Control: no-store tells every cache on the way not to keep the answer, because it holds a credential.

Authenticate with HTTP Basic Instead#

You can send the client ID and secret in an Authorization: Basic header instead of the form. curl's -u builds it:

Example: Get an access token with HTTP Basic authentication

curl -s -X POST http://localhost:4100/oauth/token \
  -u sandbox-demo:sandbox-demo-secret \
  -d grant_type=client_credentials

Response, HTTP 200, with the headers Cache-Control: no-store and Pragma: no-cache:

{
  "access_token": "sbx_1ap9P0U0X4DCbEgMcpGpcBjQV4eT77E2",
  "token_type": "Bearer",
  "expires_in": 3600
}

Use one method in a request. A request that sends the secret both ways is refused with invalid_request.

Send the Token#

Send the token in the Authorization header of every request to /graphql:

Authorization: Bearer sbx_your_access_token

A request without it is refused with HTTP 401, before any GraphQL runs:

Example: Send a query without a token

query Holder {
  accountHolder(id: "ah_0001") { id }
}

Sent without an Authorization header.

Response, HTTP 401, with the header WWW-Authenticate: Bearer realm="Brindlemark sandbox":

{
  "errors": [
    {
      "message": "Send an access token: Authorization: Bearer <token>. Get one from POST /oauth/token.",
      "extensions": {
        "code": "UNAUTHENTICATED"
      }
    }
  ]
}

The WWW-Authenticate header names the scheme the API expects: Bearer.

Renew the Token#

The sandbox gives no refresh token. When a token is close to its end, ask for a new one with the same request as the first time.

  1. Read expires_in from the answer, rather than writing 3,600 into your code.
  2. Ask for a new token a little before that time, such as a minute before.
  3. If a request is refused with error="invalid_token" in WWW-Authenticate, get a new token and send the request again, once.

This is what an expired token gets:

Example: Use a token after it expired

query Payment($id: ID!) {
  payment(id: $id) { id status }
}

Variables:

{
  "id": "pay_0001"
}

Sent 3,600 seconds after the request before it, on the sandbox's clock.

Response, HTTP 401, with the header WWW-Authenticate: Bearer realm="Brindlemark sandbox", error="invalid_token", error_description="The access token expired":

{
  "errors": [
    {
      "message": "The access token expired at 2026-12-01T10:00:02Z. Get a new one from POST /oauth/token.",
      "extensions": {
        "code": "UNAUTHENTICATED"
      }
    }
  ]
}

Token Errors#

The token endpoint answers errors in the OAuth 2.0 form: an error code and an error_description for people.

HTTP status error Cause What to do
401 invalid_client The client ID or secret is wrong or missing. Check the credentials, and the values of SANDBOX_CLIENT_ID and SANDBOX_CLIENT_SECRET the sandbox started with.
400 unsupported_grant_type grant_type isn't client_credentials. Send grant_type=client_credentials.
400 invalid_request grant_type is missing, the body isn't form-encoded, or the secret was sent two ways. Send a form with grant_type, and authenticate one way.

Example: Ask for a token with a wrong secret

curl -s -X POST http://localhost:4100/oauth/token \
  -d grant_type=client_credentials \
  -d client_id=sandbox-demo \
  -d client_secret=not-the-secret

Response, HTTP 401, with the headers WWW-Authenticate: Basic realm="Brindlemark sandbox", Cache-Control: no-store and Pragma: no-cache:

{
  "error": "invalid_client",
  "error_description": "The client ID or the client secret is wrong."
}

Example: Ask for a token with another grant type

curl -s -X POST http://localhost:4100/oauth/token \
  -d grant_type=password \
  -d client_id=sandbox-demo \
  -d client_secret=sandbox-demo-secret

Response, HTTP 400, with the headers Cache-Control: no-store and Pragma: no-cache:

{
  "error": "unsupported_grant_type",
  "error_description": "This server accepts only grant_type=client_credentials."
}

Keep the Secret Safe#

  • Keep the client secret on your server. A browser or a mobile app can't keep a secret: anyone can read it there.
  • Keep it out of source control. Read it from the environment or a secrets manager, as the sandbox reads SANDBOX_CLIENT_SECRET.
  • Keep tokens out of logs. A token in a log works for anyone who reads the log until it expires.