Sign in

Exchange a sign-in code for an account token

Changed on

The last step of Sign in with OnlyWorlds: the tool's own page, back from the sign-in with code and state in its address, checks state against the one it sent, then posts the code with its PKCE verifier. No credential on the request. Send it once, before any other request, and take code out of the address bar first: a code is single use, so a reload would spend it on a refusal.

A tool's registry entry may ask for consent that outlives its tokens (consent_outlives_tokens): revoking its token at sign-out or when its page closes then keeps the person's Continue, so the next sign-in to its https address asks nothing, and only Disconnect on the account page ends it. A tool's registry entry may ask for a lifetime on its tokens (token_lifetime_hours, 1 to 720): the token it gets expires that many hours after the exchange, and an expired token is answered 401 key_revoked on every route, exactly as a revoked one, so the tool signs the person in again.

A listed tool that only reads may add scope=world:read to the sign-in request: the token it gets here is read-only, and the answer says so with scope: "world:read". It reads everything the person's account reads; every write (a world key minted, a world made, another token minted, an AI call) is refused with 403 permission_error, except revoking the token itself. Without a scope the answer has no scope field and the token writes as the account does, but for a listed tool the registry marks read-only, whose token is read-only whatever it asks, and for the clients below. A read-only sign-in gets no AI door token: ai_uses with its code is 422 invalid_request (param ai_uses), and the code is spent.

A client that registered itself, or one whose client_id starts worlds-only- (a game, client_id worlds-only-games, among them), always gets a read-only token, and a narrower one: it reads the list of the account's worlds (its rows carry no keys), and in a world it names with world the world, its elements, search, metadata and what changed in it (GET /changes); it may revoke itself. Every other route that takes the account token refuses it with 403 permission_error; a world key's route, a reader route called without world and the old /api/worldapi routes but their metadata answer it as they answer any account token. Its token ends at its registry entry's lifetime when the entry has one, else 720 hours after the exchange.

post/api/v2/auth/token

Request

  • Base URL
    https://www.onlyworlds.com
  • Auth
    none required

Request body

object required
grant_type, 'authorization_code' required
code, string required

The code the return address carried. Single use, valid for 60 seconds.

code_verifier, string required

The PKCE verifier whose S256 hash was the request's code_challenge.

client_id, string required

As in the sign-in request.

redirect_uri, string required

As in the sign-in request, byte for byte.

ai_uses, string[]

Optional: also mint an AI door token for these AI uses (their slugs, as GET /api/v2/account/ai lists them), answered as ai_token. An unknown use is 422 and spends the code.

ai_lifetime_minutes, integer

Optional, with ai_uses only: the AI door token ends this many minutes after the exchange, or at midnight UTC if that comes first. Omitted: at midnight UTC.

Response

Signed in: an ow_a_ account token for the person, shown only here, and who they are; with ai_uses in the body, an AI door token beside it (ai_token). Cache-Control: no-store.

object required
token, string required

An ow_a_ account token, shown only in this answer. Send it as Authorization: Bearer on the /account routes (a client that registered itself, or one whose client_id starts worlds-only- (a game's among them): on the list of worlds and the reads of a world that the scope description lists). It is listed on the person's account page, named for the tool and the browser (a native app: by the tool's name alone; a client that registered itself: by the host it returns the person to), where they can revoke it.

token_id, string uuid required

The token's id: a tool done with the token revokes it with DELETE /api/v2/account/tokens/{token_id}, sending the token itself as the bearer; the world keys it minted go with it, unless the tool holds another live token that is not read-only, or the registry marks it as asking each time (its keys stay).

token_type, 'bearer' required
scope, 'world:read'

When the sign-in request asked scope=world:read, and always for a client that registered itself, a game (client_id worlds-only-games), another client whose client_id starts worlds-only-, or a listed tool the registry marks read-only: the token is read-only. Another listed tool's reads as the account does, and every write is refused with 403 permission_error ("This token is read-only: it comes from a read-only sign-in and cannot write. Use a write key with its PIN, or sign in again without scope world:read where the tool asked for it."), but one: revoking itself with DELETE /api/v2/account/tokens/{token_id}. A client that registered itself, or one whose client_id starts worlds-only- (a game's among them), gets a token that reads worlds and nothing else: GET /api/v2/account/worlds (its rows carry no keys), and a world it names with world (GET /api/v2/world, an element type's list and one element, GET /api/v2/search, and the metadata at /api/metadata/ and /api/worldapi/metadata/), and it may revoke itself. Every other route that takes the account token refuses it with 403 permission_error ("This token reads worlds only: the list of the account's worlds, their elements, search, metadata and a world, and what changed in them. It reaches nothing else on the account."). The rest answer it as they answer any account token: a world key's route, a reader route called without world, and the old /api/worldapi routes but their metadata. It ends at its registry entry's lifetime when the entry has one, else 720 hours after the exchange (expires_at). Another listed tool's sign-in that asked no scope carries no scope field, and its token writes as the account does.

expires_at, string date-time nullable required

When the token stops working: for a tool whose registry entry asks for a lifetime (token_lifetime_hours), that many hours after the exchange; for a client that registered itself, or a game or another client whose client_id starts worlds-only- with none, 720 hours after it; null for another listed tool with none, whose token works until it is revoked.

account, object required
ai_token, object

Only when the body asked for it with ai_uses: an AI door token, beside the account token above, shown only in this answer. It opens GET /api/v2/account/ai and POST /api/v2/account/ai/{use} for the uses it names, as the person, on their token rating, and nothing else (every other route 401 wrong_audience; another use 403 use_not_granted). Revoking the account token leaves it live, so a tool may revoke the account token at once and keep this one for the AI calls.

Changes

    • info

      added the optional property error/limit to the response with the status

    • info

      added the optional property error/limit to the response with the status

    • info

      added the optional property error/limit to the response with the status

    1 more change in this revision