Authentication & keys
Every request to VPNBuilder is identified by one of a few credentials: a public app key, a user token, a secret reseller key, or a RevenueCat webhook secret. This guide explains each one, where it may live and how to rotate it.
Overview
| Credential | Format | Sent as | Lives in | Grants |
|---|---|---|---|---|
| App key | pk_<brand>_<32 chars> |
X-App-Key: pk_… |
Your apps (public) | Identifies your brand on the App API. On its own it can only register/sign in end users of your brand and read public config. |
| User token | <id>|<40 chars> |
Authorization: Bearer <token> (plus X-App-Key) |
The app, after sign-in | That one account's App API calls. |
| Reseller key | sk_<brand>_<48 chars> |
Authorization: Bearer sk_… |
Your server only (secret) | The whole Reseller API for your brand. |
| RevenueCat secret | any string you choose | Authorization header of RevenueCat's webhook |
RevenueCat dashboard + brand settings | Posting purchase events to /v2/webhooks/revenuecat. |
App key
- Sent as the
X-App-Keyheader on every App API request (all/v2routes except the RevenueCat webhook). - Missing or unknown key:
400 invalid_app_key. This check runs before token authentication, so a bad app key is a 400 even when the token is also wrong. - It is public: anyone can extract it from your app. It grants nothing beyond what a stranger installing your app can do.
User tokens
Obtained from POST /v2/auth/register (201), POST /v2/auth/login,
POST /v2/auth/reset-password and the TV flow POST /v2/auth/device-token.
They are opaque bearer tokens: store them in the platform keychain/keystore.
GET /v2/me HTTP/1.1
Host: mercury.vpnbuilder.org
Accept: application/json
X-App-Key: pk_acme_3Jx9cTq0aVb1mN8rLw2yKp5sDf7gHj4z
Authorization: Bearer 12|kX8bS0mQ2v7tYf4nR1cW9eJ6hL3pA5zD
Rules:
- Bound to the brand. A token sent with another brand's app key is
403 wrong_brand. Missing/expired/revoked token:401 unauthenticated. - Naming.
device_namein register/login/reset only labels the token (defaultapp; TV tokens are named after the TV'sdevice_name, defaultTV). Signing in again never replaces an existing token: each sign-in creates a new one. - Logout (
POST /v2/auth/logout) deletes only the current token. - Password change (
PUT /v2/me/password) deletes every other token of the account; the current one keeps working. - Password reset (
POST /v2/auth/reset-password) deletes all tokens and returns a fresh one. - Revoking a device (
DELETE /v2/devices/{id}) also deletes the token that last fetched that device's VPN profile. - Account deletion (
DELETE /v2/me) deletes all tokens.
Tokens do not expire on their own; treat a 401 as "signed out" and send the
user to the sign-in screen.
Device headers
Device-scoped App API calls identify the install, not just the account:
| Header | Required | Value |
|---|---|---|
X-Device-Id |
yes, on GET /v2/vpn/profile and PUT /v2/wireguard/key |
A stable random UUID generated once per install (≤191 chars). Keep it across app updates; a new id is a new device with new VPN credentials. |
X-Device-Name |
no | Human label shown in the device list, e.g. Ada's iPhone (≤100 chars). |
X-Device-Platform |
no | ios, android, macos, windows or linux (case-insensitive). Any other value is 422 validation_failed. |
A missing X-Device-Id on those two routes is 422 validation_failed with
fields.device_id. Send X-Device-Id on GET /v2/devices too so the list can
mark the current device, and on POST /v2/support/logs (its rate limit is
per device id).
Reseller key
- Sent as
Authorization: Bearer sk_…on every/reseller/v2request. Missing/unknown key:401 unauthenticated. - It is stored only as a hash on the platform and shown once when the brand is created or the key is rotated. Keep it in your server's secret store; never ship it in an app, a web page or a repository.
- It can read and modify every account of your brand, so treat a leak as an incident and rotate it.
RevenueCat webhook secret
POST /v2/webhooks/revenuecat uses no app key. RevenueCat sends the
Authorization header value you configure in its dashboard; VPNBuilder
compares it (with or without a Bearer prefix) with your brand's
revenuecat.secret setting to find your brand. Wrong or missing secret:
401 unauthenticated. See In-app purchases.
Rotating keys
Key rotation is done by the platform operator:
php artisan vb:brand:rotate-keys acme --app # new pk_ key
php artisan vb:brand:rotate-keys acme --reseller # new sk_ key
# no flag rotates both
- Reseller key: the old key stops working immediately. Deploy the new key to your backend at the same time.
- App key: apps with the old key get
400 invalid_app_keyimmediately, so only rotate it when you ship an app update, or when old builds must be cut off. Existing user tokens stay valid with the new app key (they are bound to the brand, not the key). - RevenueCat secret: ask the operator to set the new
revenuecat.secret, then update the header in the RevenueCat dashboard.