Switch to dark mode

Access Tokens

An access token is a short-lived credential for a single order. You mint one on your server with createAccessToken and pass it to a page the public can open, such as an order page or the Refund Manager embed.

Use it where you would otherwise expose an API key. Anyone who views a page can copy the credential out of it. An API key with orders:read reads every order on your sales agent. An access token only reaches the order it was minted for, and only until it expires.

What a token can do

A token has one or both of these capabilities. You choose them when you mint it:

Capability Grants
READ Read the order, its bookings, its refunds and its payments
WRITE Start a refund of the order, and pay for it through the payment gateway (Stripe)

WRITE includes READ. A token minted with capabilities: [WRITE] comes back with both.

A token can call these operations and no others:

Everything else fails with UNAUTHORIZED. That includes any field about your sales agent or your cost centers, so a token can't reveal your commercial setup. An id that doesn't belong to the token's order is treated as not found, so a token can't be used to find out which other orders exist.

A token never gets more access than the key that minted it. Minting fails unless the key itself can do what the token is for: read the order for READ, and also refund it and pay for it through the payment gateway for WRITE. A token can never pay with wallet or invoice, and it can't mint other tokens.

Minting a token

Mint tokens on your server, never in the browser. For a READ token, the key you mint with only needs the base scope for the environment (live or test). For a WRITE token it also needs orders:read, which is what allows refunds, and payments:stripe. See API Scopes.

graphql
mutation CreateAccessToken {
  createAccessToken(
    restrictions: { orderId: "order_23g1n60755h44685v217w7k3r1" }
    capabilities: [READ, WRITE]
    ttlSeconds: 900
  ) {
    id
    token
    capabilities
    expiresAt
  }
}
Argument Description
restrictions The order the token is for, as an Order.id. Required
capabilities What the token may do. Defaults to [READ]. An empty list fails with INVALID_CAPABILITIES
ttlSeconds How long the token is valid, in seconds. From 1 to 86400 (24 hours), and 900 by default. Other values fail with INVALID_TTL

You can mint a token for any order you can read with node. Any other orderId fails with NOT_FOUND, whether the order doesn't exist, isn't yours, or its booking never completed. Empty restrictions fail with INVALID_RESTRICTIONS.

The secret is returned once

The token field holds the secret, and only in the response from createAccessToken. We store a hash of it, so it can't be read again: reading the token back with node returns token: null. If you lose it, mint a new one.

Mint a new token each time you render the page. Minting is a single request.

Using a token

Send the token in the api-key header, in place of your API key:

http
POST / HTTP/1.1
Host: api-gateway.allaboard.eu
Accept: application/graphql-response+json
api-key: aat_your-access-token-here
session: 550e8400-e29b-41d4-a716-446655440000
Content-Type: application/json

{"query": "..."}

The session header is required, as for any other request. See Required Headers.

Requests made with a token are attributed to the sales agent and user that minted it. Your order history and audit trail look the same as if you had made the requests yourself.

Revoking a token

A token stops working at expiresAt. To end it sooner, call revokeAccessToken with the token's id. This is the value of the id field, not the secret:

graphql
mutation RevokeAccessToken {
  revokeAccessToken(id: "access_token_f672y6q0a5b6c3t3t7s044q7n4") {
    id
    revokedAt
  }
}

Revoking a token that is already revoked succeeds, and revokedAt keeps its original time. The sales agent that minted the token can revoke it, and so can any agent above it in the agent tree. Anyone else gets NOT_AUTHORIZED. An id that matches no token fails with NOT_FOUND, which is also what you get if you pass the secret by mistake.

To check a token's expiresAt and revokedAt, read it with node, using the key that minted it. A token can't read itself. A null revokedAt doesn't mean the token still works, since it may have expired. Requests with an expired or revoked token fail with NOT_AUTHENTICATED, so mint a new one.

API Scopes
The scopes the minting key needs.
Configuring embeds safely
Which credential each embed takes.
Refund Manager Embed
The embed that takes an access token.
Error Codes
The errors these mutations return.