# API reference: auth

Identity of the caller

## GET /v1/auth/me

`getMe` · scope `key:read` · Who am I

Returns the authenticated principal: the user and how they authenticated (session or API key, and the key's scopes). List org memberships via `GET /v1/orgs`. `account` says whether the person has chosen their handle. It also says how they answered the welcome questions. This tells a client when to ask.

Responses:

- `200`: The authenticated principal.
- `401`: Missing or invalid credentials.

## PATCH /v1/auth/me

`updateMe` · scope `session` · Change my handle or my welcome answers

Changes the signed-in person's handle, records their answers to the welcome questions, or both. Only a signed-in person may do this. A key cannot rename the account it belongs to. A handle follows the organization rules: letters, digits and dashes, no dash at either end, at most 64 characters. Case is ignored and the handle is stored in lower case. A handle already used by a user or an organization is a `409`. So is a name the site keeps for its own pages. If the old handle ever owned a repository, it keeps pointing at this account. Its repository addresses still resolve, and nobody else can take it. API keys and robots refer to the account by id, so a rename changes nothing for them. An account may hold at most five old handles. Each rename is recorded in the activity feed.

Request body: `application/json`, required.

Responses:

- `200`: The account after the change.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).
- `422`: Request failed validation.

## DELETE /v1/auth/key

`revokeOwnApiKey` · scope `key:read` · Revoke the API key that calls

Ends the API key that sends the request, at once, with the short-lived keys made from it. A program that was handed a key for one job calls it when the job is done, so the key does not outlive it. A key can only end itself this way. Minting, listing and revoking other keys stay with a signed-in person. A session has no key to end (`422`). Any key may call it, a key limited to some repos too. The revocation is audited as the key's own.

Responses:

- `204`: The calling key is revoked.
- `401`: Missing or invalid credentials.
- `422`: Request failed validation.

## POST /v1/desktop-sign-ins

`authorizeDesktopApp` · scope `session` · Let a desktop app on this computer act as you

The hub's sign-in page calls this when a signed-in person approves a desktop app. The app opened that page itself, with a PKCE challenge and the port it listens on, on this computer only. The answer is a one-time code and the address it goes to, `http://127.0.0.1:<port>/callback`. The page sends the browser there. Only the app that made the challenge can turn the code into a key (`exchangeDesktopCode`), so a link sent by someone else yields them nothing. Session only.

Request body: `application/json`, required.

Responses:

- `201`: Approved; the browser goes to `redirect_uri` with the code.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `422`: Request failed validation.

## POST /v1/desktop-sign-ins/token

`exchangeDesktopCode` · scope `none` · The desktop app turns its code into a key

The app sends the code it received on its own loopback address and the PKCE verifier only it holds. The answer is a key that expires in seven days, a refresh token, and who the key acts as. A code works once and for one minute. An unknown, used or expired code, and a verifier that does not match, all get the same `404`.

Request body: `application/json`, required.

Responses:

- `200`: Signed in; `key.key` and `refresh_token` are shown this once.
- `404`: Resource not found (or hidden from the caller).
- `422`: Request failed validation.

## POST /v1/desktop-sign-ins/refresh

`refreshDesktopKey` · scope `none` · Renew a desktop app's key

Before its key expires, the app sends its refresh token. The answer is a new key and a new refresh token, and the old key stops working. A refresh token works once. Using one twice ends the sign-in, because it means someone else has it too. An expired key renews until thirty days after the last renewal (the grace window). A key the person revoked or rotated on the keys page, or one made from a key that no longer works, ends the sign-in instead (`404`).

Request body: `application/json`, required.

Responses:

- `200`: Renewed; the new `key.key` and `refresh_token` are shown this once.
- `404`: Resource not found (or hidden from the caller).
- `422`: Request failed validation.
