Skip to content
LocusQ

Tokens

Console tokens are credentials for the hosted LocusQ APIs. Hosted LocusQ APIs are not online yet: a token can be issued, listed and checked today, and it will work with those APIs when they are. Self-hosted tools do not read console tokens; they keep their own keys, such as LOCUSQ_TILEX_ADMIN_KEYS, ROUTER_API_KEYS and the geocoder api_keys file.

Public and secret tokens

  • pk. public tokens are for code that runs in a browser. Every account gets a default public token, which you can refresh but not delete. The console can show a public token again.
  • sk. secret tokens are for servers. A secret token is shown once, when you create it; only its hash, prefix and last four characters are stored.

Manage tokens in the console under Tokens: give a token a name, pick its scopes and, for public tokens, its allowed URLs.

Scopes

Public scopes:

  • tiles:read: read map tiles
  • styles:read: read map styles
  • fonts:read: read map fonts
  • geocode:read: search and geocode
  • route:read: calculate routes

Secret scopes:

  • tiles:write: upload map tiles
  • styles:write: publish map styles
  • tokens:manage: manage tokens

Any secret scope makes the token an sk. token.

URL restrictions

A public token can be limited to the pages allowed to use it, for example https://app.example.com, https://*.example.com or https://example.com/app. http is accepted only for localhost. Secret tokens have no URL restrictions.

Token format

A token is pk. or sk., then 43 base62 characters of random data, then a 6-character checksum: 52 characters in all. The checksum only catches typos; it proves nothing about the token. Services must not store tokens; if they need a lookup key, they use the SHA-256 hex digest of the whole token.

Checking a token from a service

A LocusQ service asks this site whether a token is live. The call is server to server, authenticated with a shared service secret, and never made from a browser.

text
POST /api/v1/tokens/introspect
Authorization: Bearer <INTROSPECT_SECRET>
Content-Type: application/json

{ "token": "pk.…", "url": "https://app.example.com/page" }

url is the page the end user came from (the Referer or Origin the service saw). Send the full page URL: a token restricted to a path only matches a full page URL. The answer for a live token:

json
{"active":true,"type":"public","scopes":["tiles:read"],"allowedUrls":[],"owner":"42"}
  • {"active":false}: do not serve the request. Malformed, unknown, revoked and URL-not-allowed tokens all get the same answer.
  • 503: the token store could not be checked. Retry with backoff; it does not mean revoked.
  • 401, 400, 413, 429: wrong secret, bad body, body over 4 KB, or too many calls.

Cache active: true answers for at most 60 seconds and active: false for at most 10, keyed by token and URL. A revoked token therefore stops working within about a minute.