Custom Storefronts

Tokens and rate limits

Verify access tokens, read their claims, handle expiry and sign-out, and stay within the Auth API rate limits

Access tokens

Access tokens are JWTs signed with RS256.

ItemValue
Public keys (JWKS)<AUTH_SERVER>/.well-known/jwks.json
Issuer (iss)<AUTH_SERVER>
Lifetime9 hours

The JWKS can contain more than one key. Select the key by the kid header. Standard JWT libraries do this for you.

Verify a token on your server

Verify the signature, the issuer, and the expiry before you trust a claim. Example with the jose library:

import { createRemoteJWKSet, jwtVerify } from 'jose'

const jwks = createRemoteJWKSet(new URL(`${process.env.AUTH_SERVER}/.well-known/jwks.json`))

export async function verifyAccessToken(token: string) {
  const { payload } = await jwtVerify(token, jwks, { issuer: process.env.AUTH_SERVER })
  return payload
}

Customer token claims

Claims of a token with scope: "CUSTOMER":

ClaimTypeMeaning
issstringAuth API base URL
substringCustomer ID, as a string
iat, expnumberIssue time and expiry time, in seconds
scopestringCUSTOMER
typestringcustomer
operator-idnumberID of your organisation (the manufacturer)
operator-namestringYour store name
customer-idnumberCustomer ID
customer-principalstringSign-in identifier (the email address, in lower case)
customer-organisation-idnumberID of the customer's organisation
client-idstringClient ID of the storefront credentials
first-name, last-namestringCustomer name
languagestringCustomer language, in lower case (default en)
notification-preferencestringDefault EMAIL
has-custom-pricingbooleanThe customer has custom pricing
is-approvedbooleanAlways true (customers who are not approved get no token)

Claims are read at sign-in. A change to the customer profile shows in the token after the next sign-in.

Guest token claims

Claims of a token with scope: "ANONYMOUS": iss, sub (a random ID for this guest), iat, exp, scope (ANONYMOUS), type (anonymous), operator-id, operator-name, client-id.

Lifetime, refresh, and sign-out

  • A token is valid for 9 hours. There is no refresh token.
  • When a customer token expires, the customer must sign in again.
  • When a guest token expires, get a new guest token.
  • There is no sign-out endpoint. To sign a customer out, delete the token that your storefront holds.
  • A token stays valid until it expires, unless the manufacturer un-approves or deletes the customer's organisation. Then every token issued to that organisation's customers stops working at once and the API returns 401. The customer cannot sign in again while the organisation is not approved.
  • Store tokens carefully. An HttpOnly, Secure cookie set by your server is a good choice.

Rate limits

When you exceed a limit, the API returns 429. Some 429 responses have a Retry-After header (seconds). Wait, then try again.

Limits for each set of storefront credentials

LimitValue
All /customer/* calls600 in 1 minute
Guest sessions (/customer/anonymous)1200 in 15 minutes
Sign-in codes sent (/customer/otp/send)600 in 15 minutes
Sign-up codes sent (/customer/signup/otp/send)600 in 15 minutes
Pre-auth calls (/customer/login/pre-auth)1800 in 15 minutes

Limits for each end customer

These limits apply to one email address at your store.

LimitValue
Sign-in codes sent5 in 15 minutes
Sign-up codes sent5 in 15 minutes
Incorrect codes10 in 15 minutes
Incorrect passwords10 in 15 minutes

After a customer uses up the incorrect-code or incorrect-password limit, the correct value also gives 429 until the 15 minutes end. A new sign-in code resets the incorrect-code limit.

Guidance

  • Do not get a new guest token on each page load. Get one for each visitor and keep it.
  • Show a clear "try again later" message on 429.

Last updated on

On this page