TV sign-in
Let customers sign in on a TV (or any device without a comfortable keyboard) by typing a short code on their phone or your website, following the OAuth 2.0 device authorization pattern (RFC 8628).
The flow
TV app VPNBuilder Phone app / website
│ POST /v2/auth/device-code │ │
│──────────────────────────────▶ │ │
│ device_code, user_code, │ │
│ verification_url, interval │ │
│◀────────────────────────────── │ │
│ shows "ABCD-2345" + QR code │ │
│ │ user types/scans the code │
│ POST /v2/auth/device-token │ │
│ (every `interval` seconds) │ │
│──────────────────────────────▶ │ │
│ 428 authorization_pending │ │
│◀────────────────────────────── │ POST /v2/auth/device-approve │
│ │ ◀───────────────────────────── │ (signed-in app)
│ │ or POST /reseller/v2/accounts/{id}/device-approve
│ │ ◀───────────────────────────── │ (your website backend)
│ POST /v2/auth/device-token │ │
│──────────────────────────────▶ │ │
│ 200 {token, user} │ │
│◀────────────────────────────── │ │
All App API calls carry X-App-Key. Approval needs no active plan (it is a
sign-in, like a password login).
1. The TV requests a code
curl -X POST https://mercury.vpnbuilder.org/v2/auth/device-code \
-H 'Accept: application/json' -H 'Content-Type: application/json' \
-H 'X-App-Key: pk_acme_3Jx9cTq0aVb1mN8rLw2yKp5sDf7gHj4z' \
-d '{"device_name": "Living room TV", "platform": "androidtv"}'
{
"device_code": "Vb3kQ9xR2mT7pL4wZ8nC1yF6hJ0sD5gA2eK9uB3qW7rX4tN1",
"user_code": "ABCD-2345",
"verification_url": "https://acme.example.com/tv",
"verification_url_complete": "https://acme.example.com/tv?code=ABCD-2345",
"expires_in": 600,
"interval": 5
}
device_name(≤100 chars) andplatform(free text ≤32 chars, e.g.androidtv,tvos,firetv) are optional; they are shown to the approver and the token is named afterdevice_name(defaultTV).device_codeis the TV's secret (48 characters): keep it in memory, never display it.user_codeis 8 characters fromABCDEFGHJKMNPQRSTUVWXYZ23456789(no 0/O, 1/I/L), shown asXXXX-XXXX.verification_urlis your brand'slinks.tvsetting, else yourlinks.website+/tv, elsenull(thenverification_url_completeisnulltoo and you should tell the user to approve from the phone app).- Rate limit: 10 codes per minute per brand and IP address.
On screen: show the user_code large, the verification_url as text, and a
QR code of verification_url_complete so a phone camera opens the page with
the code filled in. Also say "or open the Acme app on your phone → Sign in a TV".
2. The TV polls for the token
Every interval seconds (5), until the code expires (600 seconds):
curl -X POST https://mercury.vpnbuilder.org/v2/auth/device-token \
-H 'Accept: application/json' -H 'Content-Type: application/json' \
-H 'X-App-Key: pk_acme_3Jx9cTq0aVb1mN8rLw2yKp5sDf7gHj4z' \
-d '{"device_code": "Vb3kQ9xR2mT7pL4wZ8nC1yF6hJ0sD5gA2eK9uB3qW7rX4tN1"}'
| Response | Meaning | What the TV does |
|---|---|---|
200 {token, user} |
Approved. The code is consumed (single use). | Store the token, continue as signed in. |
428 authorization_pending |
Not approved yet. | Keep polling at interval. |
429 slow_down |
Polled sooner than interval (1 s tolerance) since the last poll. |
Add 5 seconds to your interval (RFC 8628) and continue. |
410 expired_token |
Expired, unknown or already used. | Stop; offer "Get a new code" (start again). |
403 access_denied |
The user tapped "Deny". The code is then deleted (later polls get 410). |
Stop; show "Sign-in cancelled". |
429 rate_limited |
More than 60 polls per minute from your brand + IP. | Wait for Retry-After seconds. |
When the code expires while the screen is still open, request a new code automatically and refresh the display.
3a. Approve from your phone app
In the signed-in app, add a "Sign in a TV" screen where the user types the code (accept lower case, with or without the dash or spaces):
curl -X POST https://mercury.vpnbuilder.org/v2/auth/device-approve \
-H 'Accept: application/json' -H 'Content-Type: application/json' \
-H 'X-App-Key: pk_acme_3Jx9cTq0aVb1mN8rLw2yKp5sDf7gHj4z' \
-H 'Authorization: Bearer 12|kX8bS0mQ2v7tYf4nR1cW9eJ6hL3pA5zD' \
-d '{"user_code": "abcd2345"}'
{"device_name": "Living room TV", "platform": "androidtv"}
Show "Living room TV is now signed in". The TV is signed in to the same
account as the approving app. POST /v2/auth/device-deny with the same body
(→ 204) rejects it. Both return 404 not_found for a code that is unknown,
expired or no longer pending.
Tip: before approving you cannot look the code up from the app; show a clear "Only enter a code shown on your own TV" warning.
3b. Approve from your website
Build a /tv page on your website (that is where verification_url points by
default). Your backend uses the Reseller API:
- Read
?code=from the URL (prefill the input), or let the user type it. - Look it up to show what is being signed in:
curl https://mercury.vpnbuilder.org/reseller/v2/device-codes/ABCD-2345 \
-H 'Accept: application/json' \
-H 'Authorization: Bearer sk_acme_Q7vTn2LxP9sRk4Wb8yHc1Me6Ud3Fj5Ga0Zq7Np2Vt9Xs4Kr'
{"device_name": "Living room TV", "platform": "androidtv", "expires_at": "2026-12-02T17:54:00Z"}
404 not_found = wrong or expired code: ask the user to check the TV.
3. Make sure the customer is signed in on your website (e.g. with
POST /reseller/v2/accounts/verify), then approve for their account id:
curl -X POST https://mercury.vpnbuilder.org/reseller/v2/accounts/42/device-approve \
-H 'Accept: application/json' -H 'Content-Type: application/json' \
-H 'Authorization: Bearer sk_acme_Q7vTn2LxP9sRk4Wb8yHc1Me6Ud3Fj5Ga0Zq7Np2Vt9Xs4Kr' \
-d '{"user_code": "ABCD-2345"}'
{"device_name": "Living room TV", "platform": "androidtv"}
The TV's next poll receives its token. The Reseller API has no deny call: an unapproved code simply expires.
Security notes
- The
device_codeis stored only as a hash and is single use. - Codes are scoped to your brand: another brand's app or website cannot approve them.
- Expired and used codes are cleaned up hourly.