Info
- Sign-in for apps and dedicated servers under
/api/v2/auth, the signed-in account under /api/v2/me. Paths below are relative to /api/v2
- Calls without a token name the app in
X-App-Key, see API
- A player sign-in gives a 1 h access token and a refresh token, and makes the person a member of the app
- Answers follow OAuth: the tokens on success, a refused sign-in
400 with an OAuth code: invalid_request, invalid_grant, authorization_pending, slow_down, expired_token, access_denied. An unknown app is 401
- Concepts: Sign-in & Sessions. Unity side: Auth in Unity Core
The flow
- With an account:
POST /auth/password
- Without one:
POST /auth/guest. The first one answers a guest_key the device keeps and sends next time
- On a device without a keyboard:
POST /auth/device-codes, show the code, then poll POST /auth/device-codes/token until someone approves it on the website
- Keep the refresh token. When the access token runs out or a call answers
401 token_expired, call POST /auth/refresh. On 401 session_ended the sign-in is over: sign in again
- A guest adds an account with a link code (
/me/link-code)
- Dedicated servers:
POST /auth/server with their server ID and secret, or POST /auth/machine with a linked machine's token
- After sign-in, terms, usage data sharing and remote config are their own calls: Legal API, Analytics API, Remote Config API
Sign-in
POST /auth/register - make an account: email, password, optional device_name, device_id
201 with the tokens, as a sign-in answers, when the hub sends no mail and so asks no email confirmation
202 with email and email_confirmation_required when the email has to be confirmed first: show "check your email", then sign in with the password
- With mail on, an email that already has an account answers the same
202 and its owner gets a mail, so nobody learns which emails have accounts. Without mail: 409 email_taken
400 weak_password with the reasons in detail and errors on password, 400 invalid_request for other bad input
- Passwords have at least 10 characters and can't be one known from data breaches
- With
email_confirmation_required the hub mails a confirmation link, and password sign-in answers email_not_confirmed until it is opened
- Makes the username from the email and records no terms, see Legal API
- With mail on, accounts that never confirm and never sign in are deleted after 7 days
POST /auth/password - email, password, optional device_name, device_id
invalid_grant for a wrong email or password
email_not_confirmed while the email isn't confirmed; a new link goes out, valid for 2 hours
- The sign-in acts with the person's own and group app roles, never hub staff roles
POST /auth/guest - optional guest_key (up to 256 characters), device_name, device_id
- Without
guest_key the hub makes a new guest, with a generated name like BraveOtter1234, and answers its guest_key (shg_…) once. Keep it on the device and send it to sign in again
- A key the hub doesn't know:
invalid_grant
403 guests_off when the app allows no guests (App Settings › Sign-in › Guests)
- Guests get only the Member role; the app's default roles come once they add an email
account_already_linked once the guest added an account: sign in the way it was linked
POST /auth/device-codes - optional device_name, device_id. Answers
device_code - keep it on the device, it's sent when polling
user_code - 8 letters shown as XXXX-XXXX
verification_uri - the /activate page, verification_uri_complete - the same with the code filled in, for a QR code. Opened from another network than the device's, the page asks to type the code
expires_in (10 min) and interval (5 s), in seconds
POST /auth/device-codes/token - device_code
authorization_pending until a signed-in person approves the code on the website, slow_down when polled faster than interval
- Then the tokens, once.
access_denied when the code was denied, expired_token when it expired, was used or belongs to another app
- The website approves with its own sign-in, where two-factor applies, so the token keeps the person's hub staff roles