veil

Finish a linked roles connection

Signed by the key that started, with the return code. The server trades Discord's code, checks that the Discord account is a verified account of the card, keeps the tokens encrypted and sends the facts.

POST/v1/discord/linked-roles/{state}/complete
Access
Signed request
Client
Local or server client

Parameters#

NameLocationMeaning
stateRequiredPathThe state start returned.
returnCodeRequiredJSONThe 32 hex characters the callback page got.

This call also needs the common signed-request headers, nonce and timestamp. Prepare and sign request.json before using the example. Request signing

Request examples#

cURL
curl -fsS -X POST \
  -H "X-Public-Key: $PUBLIC_KEY" -H "X-Signature: $REQUEST_SIGNATURE" \
  --json @request.json "https://veil.pub/v1/discord/linked-roles/{state}/complete"

Response#

HTTP 200application/json

The connection, with what Discord now shows.

FieldTypeMeaning
discordobject{id, username}: the Discord account.
statestringactive or retired.
connectedAtstringWhen it was connected.
lastPushAtstring | nullWhen Discord last accepted the facts.
lastCheckedAtstring | nullWhen the facts were last worked out.
nextPushAtstring | nullWhen the next push is due (null once retired).
shownobject | null{platform_name, platform_username, metadata}: what Discord holds.
widgetbooleanThe grant carries the profile widget.
widgetPushedAtstring | nullWhen the widget's data last reached Discord.
retiredAtstring | nullWhen it ended.
reasonstring | nullWhy it ended: discord_refused, removed_on_discord, discord_not_linked, suspended, unreachable, token_unreadable.

Response headers#

HeaderValueMeaning
Content-Typeapplication/jsonJSON, also for errors.
Cache-Controlno-storePrivate: never cached.

Errors#

API errors return an error object. Use error.code for program logic; error.message is English text for people and can change. Response and error guide

HTTPCodeMeaning and next step
400invalid_parameter

A parameter is missing or malformed.

Send n as the card's number, or returnCode as the 32 hex characters the page got.

403key_mismatch

The key is not an active device key of the card, or not the key that started this connection.

Sign with the device key of the browser that started.

403veil_suspended

The Veil staff suspended the card.

A suspended card gives no roles until the suspension ends.

404linked_roles_off

This server does not offer Discord linked roles.

Ask the server's operator, or check GET /v1/discord/linked-roles.

404not_found

No such card or connection, or the connection is over.

Start again from /discord/linked-roles.

409discord_account_alert

The card declared this Discord account stolen, moved or no longer used, and has not declared it regained. On complete, the grant was revoked.

Declare the account regained on the card, then connect.

409discord_not_linked

The Discord account that authorised is not a verified account of the card. Its grant was revoked; error.discord.username names it.

Sign in to Discord with the account on the card, or link that account to the card first.

409not_in_good_standing

The card is closing, has a takeover open or its name is hidden.

Settle that first, then connect.

409not_returned

Discord has not sent the browser back yet.

Finish on Discord first.

410erased

The card was closed.

A closed card has no connections.

410session_expired

The connection took more than 10 minutes.

Start again.

422discord_refused

Discord answered invalid_grant for the code: used, expired or not for this app. The message is fixed and repeats nothing Discord said.

Start again.

422not_for_organizations

Linked roles are for a person's card.

Use a person's card.

422scope_missing

Discord did not grant role_connections.write.

Start again and allow the connection.

422wrong_return_code

The return code is not this connection's.

Send the code the page got back, from the browser that started.

429too_many_attempts

Too many wrong return codes.

Start again.

503discord_unavailable

Discord did not answer, answered something unexpected or refused the app itself. A grant already received was revoked.

Try again in a few minutes.

HTTPCodeMeaning and next step
400invalid_nonce

The signed-request nonce has an invalid format.

Generate a fresh 16 to 128-character nonce using letters, digits, _ or -.

400invalid_signature_alg

X-Signature-Alg is unsupported.

Use a supported signing algorithm and matching key/signature encoding.

400invalid_timestamp

The signed-request timestamp is not Unix milliseconds.

Use an integer Unix timestamp in milliseconds and sign the corrected request.

401invalid_signature

The HTTP request signature does not verify.

Sign the exact method, path and body bytes, without changing them afterwards.

401missing_signature

The request requires a device signature and its headers are missing or unreadable.

Send X-Public-Key, X-Signature and the signed-request metadata. An API key does not replace a device signature.

401stale_timestamp

The signed timestamp is outside the accepted clock window.

Compare the server Date header with your clock, then generate a fresh nonce, timestamp and signature.

403key_banned

The device signing key is suspended by Veil staff.

Use an authorised active key or ask staff to review the restriction.

409replayed_nonce

The signing key already used this nonce.

Check whether the previous request succeeded before making a fresh signed request.

429rate_limited

An anonymous, signed-request or API-key allowance was exceeded.

Wait at least Retry-After seconds. Share a queue and retry budget across your workers.

500internal_error

An unexpected server error occurred. Internal details are not returned.

Retry reads with bounded backoff. Check write results before sending a new signed operation.

503busy

The application has reached a temporary concurrency or database limit.

Wait Retry-After seconds and retry with bounded backoff.