Skip to content

Device-code authentication (direct adapters)

Direct desktop / in-document adapters (the Office.js Word add-in, the LibreOffice UNO adapter) authenticate with a Myra-native device authorization grant modelled on RFC 8628. It is not an Entra / Microsoft flow — it issues a Myra credential a user approves in their browser, so a residency-strict tenant keeps every token on Myra infrastructure.

The flow issues a short-lived access token plus a rotating, one-time-use refresh token. The access token is an ordinary gateway token: a front door presents it as Authorization: Bearer myra_... to the /v1 inference plane (or /copilot/v1) with no special handling — it is validated exactly like a personal API token (tenant fence, account-state gates, viewer bar, and its own short expiry all apply).


1. Start a flow — device authorization endpoint

POST /admin/auth/device/authorize — no session required (the caller is a headless client).

Request (JSON):

Field Type Required Notes
gateway_id string yes The target gateway (the tenant's document-AI gateway).
client_label string no Free text shown to the approver (e.g. "LibreOffice on host-42"). A value with a control, line-break or invisible formatting character, invalid UTF-8, or more than 255 bytes is refused with 400 invalid_request (never silently altered); a non-string value is refused the same way; an empty value counts as absent. Behaviour change: a non-string, over-long or refused-character client_label used to be stripped or truncated and the request succeeded; it is now 400 invalid_request (see refused characters).

Response 200:

{
  "device_code": "dvc_9f8e…",
  "user_code": "WXYZ-2345",
  "verification_uri": "https://ai.myra.eu/device",
  "verification_uri_complete": "https://ai.myra.eu/device?user_code=WXYZ-2345",
  "expires_in": 600,
  "interval": 5
}

The client shows user_code and verification_uri (or opens verification_uri_complete) to the user, then polls the token endpoint every interval seconds until the user approves.

Rejected / errors (all application/json):

Condition Status error
gateway_id absent, empty, non-string, over 36 bytes, invalid UTF-8, containing control/format characters, or unknown 400 invalid_request (an unknown gateway is deliberately indistinguishable from a bad request — no existence oracle)
Body is not valid JSON, or is valid JSON that is not an object (an array, string, number, boolean or null) 400 invalid_request, with an error_description naming the cause (request body is not valid JSON / request body must be a JSON object) and no code member. A body over the structure budget keeps 413, an unreadable one 503 temporarily_unavailable with Retry-After: 10. An absent or blank body is not malformed: it is read as no fields and gets the missing-gateway_id answer above
The caller's client address is absent (no usable X-Forwarded-For hop and no peer address) 400 invalid_request, error_description client address missing
The caller's client address is malformed (e.g. unknown, an empty hop, a non-address string) 400 invalid_request, error_description client address malformed
Too many pending authorizations from the caller's client address for this gateway (5) 429 slow_down, error_description too many pending device authorizations from this address
Too many pending authorizations for the gateway (50) 429 slow_down
A transient storage conflict (nothing was written; retry) 503 temporarily_unavailable
Any other storage fault 500 server_error

Per-address cap. This endpoint is unauthenticated, so a pending authorization is also limited to 5 per client address per gateway, on top of the 50 per gateway. The client address is the same per-client-IP key the other unauthenticated routes use: an IPv4 address exactly, an IPv6 address by its /64 (an IPv4-mapped IPv6 address counts as the IPv4 address). Clients behind one NAT, VPN or /64 share the 5 slots. A slot is freed when the authorization is approved, denied, exchanged for a token, or expires (600 s); the limit is a live count of pending rows, so there is nothing to reset. The address comes from the CDN-supplied X-Forwarded-For (the CDN replaces any client-sent value). An empty X-Forwarded-For header counts as no header (the peer address is used); a present header whose first hop is blank (, or , 1.2.3.4) is malformed. A caller with at least 10 distinct addresses can still occupy the 50 per-gateway slots for up to 600 s; the per-address cap narrows that to a caller that controls many addresses, it does not remove it.


2. Poll / rotate — token endpoint

POST /admin/auth/device/token — no session required. JSON body (a Myra-native deviation from RFC 8628's form-encoding). grant_type is an exact allowlist:

2a. Poll (device_code grant)

{ "grant_type": "urn:ietf:params:oauth:grant-type:device_code", "device_code": "dvc_9f8e…" }

While pending, the endpoint returns an RFC 8628 error (HTTP 400 for all of them, per RFC 6749 §5.2):

Situation error
Not yet approved authorization_pending
Polling faster than interval slow_down
The user denied the device access_denied
The device_code expired (600 s) expired_token
Unknown / already-consumed device_code invalid_grant

On approval, 200:

{
  "access_token": "myra_…",
  "token_type": "Bearer",
  "expires_in": 900,
  "refresh_token": "dvr_…"
}

The device_code is single-use — it is consumed when the tokens are issued.

2b. Rotate (refresh_token grant)

{ "grant_type": "refresh_token", "refresh_token": "dvr_…" }
  • A valid, current refresh token → 200 with a new access_token and a new refresh_token (the old refresh token is now dead — store the new one).
  • A replayed refresh token (one already rotated away, or from a revoked family) is treated as token theft: the entire token family is revoked immediately (every access + refresh token in it) and the response is 400 invalid_grant. The client must re-run the device flow.
  • Past the family's absolute lifetime (90 days, or the tenant's token_max_lifetime_days if lower) → the family is revoked and the response is 400 invalid_grant; re-authenticate.

Input validation (fail-closed). grant_type absent → 400 invalid_request; an unknown or non-string grant_type → 400 unsupported_grant_type (absent and malformed are distinct — neither falls through to a grant). device_code / refresh_token must be non-empty strings; a missing or wrong-typed value is 400 invalid_request (it is never fed to the hasher). A body that is not valid JSON or not a JSON object ([], 42, null, "x") is 400 invalid_request with an error_description naming the cause; an absent or blank body is read as no fields and answers 400 invalid_request (grant_type required). Both routes answer the OAuth error shape (error, error_description), never the admin code member. A transient storage fault is 503 temporarily_unavailable (retry); any other storage fault is 500 server_error.


3. Approve in the browser — verification endpoints

These require an authenticated aig_admin session (the user logs in normally). They are the JSON contract behind the /device verification page in the web app — the human front door the verification_uri (https://ai.myra.eu/device) and verification_uri_complete (…/device?user_code=…) open. That page previews the pending authorization and offers Approve / Deny; it is also reachable from Settings › Devices. A bad, unknown or expired code shows a single generic "no matching request" state (it never distinguishes them — mirroring the uniform 404 below), and the client is never the authz boundary: the server re-checks every call.

  • GET /admin/v1/device/pending?user_code=WXYZ-2345 — preview: { gateway_id, gateway_name, client_label, approvable } so the page can show what is being authorized. approvable (boolean) is false when the code's gateway is not in the caller's own workspace: approving it would be refused (403 gateway_outside_owner_tenant, see below), denying it still works — the page then offers Deny only.
  • POST /admin/v1/device/approve — body { "user_code": "WXYZ-2345" } plus the optional step_up_token (step-up; for a caller on password and second-factor sign-in without it 403 step_up_required, and the SPA asks for the second factor and sends once more; other callers need not send it and the field is ignored). The approving session is the browser session on the verification page. The check comes after the uniform 404 and the tenant, department and self-mint checks, so an unknown code never costs a token. Approves the device; the minted token acts as the approving user. Response 200 { "ok": true, "gateway_id", "client_label" }. The approver's department must allow the code's gateway (403 department_gateway_not_allowed).
  • POST /admin/v1/device/deny — body { "user_code": "WXYZ-2345" }. Response 200 { "ok": true }.

All three routes refuse an impersonation session and allow 30 attempts per user in 5 minutes; over that budget they answer 429 { "error": "too many attempts, try again later" }. Approve and deny answer 400 { "error": "request body must be a JSON object", "code": "malformed_body" } for a body that is a JSON array, string, number, boolean or null (and request body is not valid JSON for undecodable text); an absent or blank body is read as no fields and answers 400 { "error": "user_code required" }.

Authorization. The approver must have access to the code's gateway (platform admin, or same tenant). Approve additionally requires a role that may mint credentials (a viewer / read-only or impersonating session is refused), and — because the minted token acts as the approver — the code's gateway must be in the approver's own workspace: a platform administrator may preview and deny another workspace's code, but approving it answers 403 gateway_outside_owner_tenant and writes nothing (an administrator account without a workspace can approve none). The page then says the device asks for another workspace's gateway. See A token lives in its owner's own workspace. An unknown user_code and a user_code the caller may not reach both return the same 404 { "error": "not found" } — there is no cross-tenant existence oracle. A missing or mistyped user_code on the preview (GET /admin/v1/device/pending) answers the same 404. Each of these 404s is recorded as one access.denied security event (status 404, no entity; the code is not logged), so probing codes is visible to your administrators and the security record is written the same way in both cases. A request that loses a status race (the code was approved, denied or expired by someone else between lookup and update) is a plain 404 that is not recorded as an access.denied event. Approve and deny with a missing or malformed user_code stay 400. user_code is case-insensitive and the dash is optional.


4. Manage & revoke device sessions

Session-gated:

  • GET /admin/v1/device/families — the caller's own active device sessions (id, gateway, label, timestamps — never any secret). Admins may pass ?user_id=<id> (requires USERS_MANAGE, subject to user-access rules) to list another user's sessions for targeted revocation. Without user_id you get your own sessions. user_id must be a single non-empty id: a repeated (?user_id=a&user_id=b), bare (?user_id) or empty (?user_id=) value answers 400 { "error": "invalid user_id", "code": "invalid_user_id" } (never your own list), and a query with more than 100 parameters answers 400 { "error": "too many query parameters", "code": "malformed_query" }. Any other id that does not name a user you may reach answers the audited 404 not found.
  • DELETE /admin/v1/device/families/{id} — server-side revocation. The owner may revoke their own session; an admin may revoke another user's session on a gateway they can reach if they out-rank that user (the same rule as for that user's tokens: a tenant_admin may revoke a member's session, not a peer tenant_admin's — see Users & tokens); any refusal answers 404 { "error": "not found" }, like an unknown session, and is recorded as one access.denied security event (status 404, no entity). A missing USERS_MANAGE permission and an owner you do not out-rank also get this 404 rather than 403, by design, so the route is no family-existence oracle. A revoke that loses a race with another revoke is a plain 404, not recorded as access.denied. Revoking kills the access token, the family, and every refresh token in it. A successful revoke answers 200 { "ok": true }.

In the web app these back the device-session list on /device (Settings › Devices): each active family is shown with its label, gateway and timestamps, and a Revoke action calls the DELETE above (with a confirm).

Disabling, deleting, or deprovisioning a user also revokes all of their device families automatically. A global background clean-up job (all tenants at once) deletes expired authorizations and token families that are past their absolute lifetime or were revoked longer ago than the retention period. The clean-up is housekeeping only: expiry and single use are enforced on every request regardless.


5. What a front door consumes

The access_token is a standard myra_ gateway token bound to the approved user + gateway, scoped ["inference"], labelled device, with a short expiry. A front door presents it as Authorization: Bearer <access_token> on /v1 or /copilot/v1 — no device-specific validation is needed. Because the token is gateway-scoped, an exfiltrated device token grants inference only on its one gateway, as its one user, and only until it expires (≤ 15 min) or is revoked.

Client token storage: the OS keyring is required and a plaintext fallback is refused — a headless client with no secret store re-authenticates instead of persisting a refresh token in the clear.

Token lifetime policy. The tenant token lifetime policy applies to this flow. token_max_lifetime_days shortens the family's absolute lifetime (the 90 days above) to that many days if the cap is lower; a cap never lengthens it. Every access token the family issues, including after a refresh, also expires no later than the family's absolute expiry, and expires_in reports that clamped value. Existing families are not shortened when the cap is set or lowered. With self_mint_tokens set to 0, POST /admin/v1/device/approve answers 403 self_mint_disabled and nothing is written; denying a code still works. A malformed or missing tenant policy row answers 500 server_error on the token endpoint, and nothing is minted.