Hatchmate Core API

The authorisation-code flow and the system-token exchange.


Begin the authorisation-code flow (E25)

GET
https://api.hatchmate.nz
/v1/oauth/authorize
hatchmate_session (cookie)

Authenticated by the shell's hatchmate_session cookie (ID-46). The only operation in the contract that accepts a customer_id from the client: it runs before any token exists and the choice is checked against the session's memberships (API-16, API-85). An unknown or inactive app_slug, or a customer_id the session's user is not a member of, is 404.

Begin the authorisation-code flow (E25) › query Parameters

app_slug
​string · pattern: ^[a-z0-9][a-z0-9-]{0… · required

The apps registry slug of the target app (TM-61).

customer_id
​string · uuid · required

The customer the user chooses to act as. Validated against the session's memberships; carried only in the token it causes to be minted.

Begin the authorisation-code flow (E25) › Responses

Redirect to a redirect_uri registered on the apps row, carrying code and state only — never a token (TK-1).

No data returned

Complete the browser login (E56)

GET
https://api.hatchmate.nz
/v1/oauth/callback

The Keycloak return leg (API-132). Consumes the single-use state, exchanges code back-channel, creates the hatchmate_session and redirects into the shell. Every failure of the state, the code exchange or the subject binding is a 400 that does not say which.

Complete the browser login (E56) › query Parameters

state
​string · maxLength: 512 · required

The single-use value issued by E55.

code
​string · maxLength: 512

The Keycloak authorisation code. Absent when Keycloak returns error.

error
​string · maxLength: 128

Keycloak's error code. Its presence is a 400 code-rejected.

error_description
​string · maxLength: 512

Keycloak's error text. Never echoed.

Complete the browser login (E56) › Responses

Redirect into the shell, with the session cookie set.

No data returned

Begin the browser login (E55)

GET
https://api.hatchmate.nz
/v1/oauth/login

Starts the shell login (API-132). Generates state, nonce and a PKCE verifier, persists them (ID-54) and redirects to the Keycloak authorisation endpoint. Takes no credential and sets no cookie. The optional return_to is a relative path the shell is sent to after login.

Begin the browser login (E55) › query Parameters

return_to
​string · maxLength: 512 · pattern: ^/($|[^/].*)

A relative path beginning / and not //, at most 512 characters. Defaults to the shell root.

Begin the browser login (E55) › Responses

Redirect to the Keycloak authorisation endpoint.

No data returned

Exchange an authorisation code for a token (E26)

POST
https://api.hatchmate.nz
/v1/oauth/token
basic

HTTP Basic client credentials — the apps row's client_id and client_secret. 401 is byte-identical for an unknown client_id and a wrong secret. Form encoding is the single exemption from API-49 (API-85, RFC 6749).

Exchange an authorisation code for a token (E26) › Request Body

E26 request body, `application/x-www-form-urlencoded` (`API-85`).
code
​string · minLength: 1 · required
code_verifier
​string · minLength: 1 · required
grant_type
​string · enum · required
Enum values:
authorization_code
redirect_uri
​string · uri · required

Exchange an authorisation code for a token (E26) › Responses

An app-facing access token (TK-9).

E26 and E27. Shape owned by `TK-9`.
access_token
​string · required
expires_in
​integer · min: 1 · required
token_type
​string · enum · required
Enum values:
Bearer