Authentication

The three kinds of token in Bunny: API client access tokens for your server, portal session tokens for one customer in the browser, and signup tokens for public signup pages. When to use each.

Every call to Bunny’s API carries a token in an Authorization: Bearer <token> header. Which token depends on where the call comes from and what it should be able to reach:

Token Use it in It can reach Created with
API client access token Your server only Your whole Bunny entity, limited by the API client’s scopes The client credentials grant, or Generate Access Token in Bunny
Portal session token The browser, with the customer portal and Bunny Components One account’s billing portalSessionCreate, called from your server
Signup token A public signup page or <Signup /> Signing up new customers, nothing else An API client with only the signup:read and signup:write scopes

API client access tokensLink to API client access tokens section

An API client is how your platform connects to Bunny. Create one in Bunny under Settings > Developers > API clients, give it only the scopes it needs, and keep its Client ID and Client Secret on your server. See API clients.

Your server exchanges the client ID and secret for an access token at https://<subdomain>.bunny.com/oauth/token with the OAuth 2.0 client credentials grant, then sends the token with every request to https://<subdomain>.bunny.com/graphql. Your subdomain is the one in the address you use to sign in to Bunny.

Access tokens expire after the API client’s token expiry, for example 7,200 seconds. A request with an expired token gets HTTP 401 with Token is expired. Get a new token and retry the request.

The Bunny SDKs do all of this for you: give them the client ID, secret and scopes, and they get tokens and replace expired ones.

To try the API without writing the token request, select an API client in Bunny and click Generate Access Token.

Details and examples: Authorizing API requests.

Never send an API client’s secret or access token to the browser. Anyone can read it from the page and reach all the data its scopes allow.

Portal session tokensLink to Portal session tokens section

A portal session token lets one customer see and manage their own billing in the browser, through the customer portal or Bunny Components. Your server creates it with portalSessionCreate for the signed-in customer’s tenant, using an API client with the portal:write scope, and sends only the portal session token to the browser.

It expires after at most 24 hours, so create one each time the customer opens billing rather than storing it.

Details: Portal session token.

Signup tokensLink to Signup tokens section

Signup pages run before the customer has an account, so there’s no tenant to create a portal session for. They use an access token from an API client whose only scopes are signup:read and signup:write. That token can do nothing but sign up new customers, so it’s safe in a public page.

Create a separate API client for signup. Never use one with any other scope.

Details: Signup page and <Signup />.