* fix(client-tokens): let a client token revoke itself without me.write
A device that signs out or re-pairs had no way to revoke its own token
unless it held me.write, which also lets it mint tokens and approve
pairings. DELETE /api/client-tokens/{id} now skips the me.write check
when the id is the token authenticating the request.
Fixes#5274
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(client-tokens): code-review pass on self-revoke
Annotate raise_auth_error as NoReturn, trim the delete_token docstring, and
cover a me.write token revoking a sibling, the revoked token failing to
authenticate, and socket closure on self-revoke.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(client-tokens): revoke the calling token through DELETE /current
Self-revoke moves to an id-less route so a device never needs to know its
token id, and DELETE /{token_id} keeps me.write in its decorator and in
OpenAPI. The device-authorization token response now also returns token_id.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* refactor(client-tokens): simplify pass, reuse raise_auth_error for /current
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* revert(client-tokens): drop DELETE /current and the device-flow token_id
Self-revoke stays on DELETE /{token_id} with the in-handler check.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* feat(device-auth): return the issued token's id from the device token poll
A device paired through the device-authorization flow can now revoke its
own token with DELETE /api/client-tokens/{id}, as tokens from /exchange can.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Update docs/BACKEND_ARCHITECTURE.md
* docs: format client tokens table
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
- Replace the inline bytes-to-text decodes with redis_handler.as_text
- Add utils.auth.token_device_id for a request's token-bound device
- Look up a group's member tokens in one query and close them in one pass
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* chore(deps): bump redis to 8.1 and fakeredis to 2.38
redis-py 6.2.0 -> 8.1.0 and fakeredis 2.30.1 -> 2.38.0. RQ 2.12
(redis!=6,>=3.5) and fakeredis (redis>=4.3) both accept redis 8.
fakeredis 2.38 types FakeServer's version argument as a tuple, so pass
(7,) instead of 7. Behaviour is unchanged since fakeredis normalises an
int to a one-element tuple.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wzuPg8vDEjsQ8xqvZgFwx
* chore(deps): drop types-redis in favour of redis-py's own types
types-redis only covers redis 4.6 and shadowed the inline types that
redis 8 ships, so mypy was checking calls against a stale API. Removing
it also drops its transitive stub packages (types-cffi, types-pyopenssl,
types-setuptools), which nothing else uses.
redis-py's types differ from the stubs in three ways:
- Redis, AsyncRedis and Pipeline are not generic, so drop the [str] and
[bytes] parameters.
- Responses are typed bytes | str regardless of decode_responses, so cast
at the few call sites that rely on the decoded (or raw) type.
- watch, unwatch, multi, aclose and execute_command are unannotated, so
add redis to untyped_calls_exclude, as is done for rq and apprise.
Also replace setex, deprecated in redis 8, with set(..., ex=...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wzuPg8vDEjsQ8xqvZgFwx
* fix(device-auth): replace deprecated GETSET with SET ... GET
code-review step. GETSET is deprecated since Redis 6.2 in favour of
SET with GET. Using it with ex= also sets the poll key's TTL in the same
command, instead of a separate EXPIRE that a crash could skip.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014wzuPg8vDEjsQ8xqvZgFwx
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
GET /heartbeat/metadata/{source} needs no authentication and each call
probes a third-party API through that provider's process-global outbound
limiter, so an unthrottled caller could queue up enough probes to starve
scans and burn the API quota.
Cap it at 20 requests per minute per IP per source. The limit is applied
after the source is parsed, so an invalid source still gets a cheap 400
and arbitrary path values cannot grow the Redis keyspace.
The incr/expire/429 block this needed already existed twice, so extract
it into utils/rate_limit.py and point the device authorization and client
token exchange limits at it. The device auth behaviour is unchanged; the
client token exchange window is now fixed rather than refreshing its TTL
on every request, matching the comment device auth already carried.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
- device/init returns a relative verification_path; the client joins it
with its own origin
- Render the v2 approval screen via the named v2 router outlet (was blank)
- DevicePair: RSpinner, keyboard-accessible scope chips, scrollable scopes;
DevicePairShell uses always-light overlay tokens (no hex)
Implements RFC 8628-style device authorization so clients
(argosy-launcher, grout) can pair by display instead of manually
copying tokens. Device posts to an open /api/auth/device/init with
its identifier and requested scopes; the server returns device_code
+ user_code + QR URL. User scans QR, lands at /pair/device, approves
(optionally editing name/scopes/expiry); the device's next poll on
/api/auth/device/token returns a ClientToken bound 1:1 to a newly-
created (or deduped) Device record. Downstream endpoints
(/play-sessions, /sync/negotiate) infer device_id from the bound
token so the client doesn't have to ship it on every call.
- Migrations 0080/0081: devices.client_device_identifier (unique
per user) and client_tokens.device_id FK (ON DELETE SET NULL)
- Five new endpoints under /api/auth/device (init/pending/approve/
deny/token) with Redis-backed state, per-IP rate limits, and
RFC-compliant error codes (authorization_pending, slow_down,
expired_token, access_denied)
- HybridAuthBackend surfaces bound device_id on request.state and
bumps devices.last_seen with a 5-minute debounce
- /api/users/me returns current_device_id for bound tokens so a
device can identify itself from its token alone
- Frontend approval screen at /pair/device with editable scopes/
name/expiry (defaults to Never), 3s auto-close countdown
- ClientApiTokens settings list shows bound-device chip
- 20 i18n keys added to all 17 locales; generated models updated
- 52 new tests across 13 classes; full suite 1334 passed
Planning and review assisted by Claude Code.