feat(backend): paired devices with device tokens, scope, limits and terminal login
Platform v2 step 1.8 (APPS_PLATFORM D-8, section 6.3).
- devices + device_pair_requests tables (Alembic 0007_devices); sessions.device_id
becomes a FK. Device tokens are stored as sha256 only; the plain token is generated
when the device picks it up, once.
- /api/devices: pair-request (public, rate-limited, LAN-only in the proxy) + polling
with a per-request secret; manager approve/list/rename/config/login mode/link/
reassign/revoke (key core.devices.manage); the device's own /me and /me/users.
- Approving or reassigning checks the app's licence and its `devices` limit
(license.limit_reached); after a downgrade the newest devices beyond the limit are
refused, the oldest keep working.
- X-Xenia-Device: core/access/context.py loads the device (device.not_paired /
device.revoked), tags logs with device=, throttles last_seen_at. check() and
module_required() apply the app's scope (device.out_of_scope); require_device(app).
- POST /api/auth/login {client: "terminal"} uses the device's login mode (device ->
auth.default_login_mode -> app's first mode); tap/none only here. The session is
bound to the device (device.required without its header) and replaces the
device's previous user. Revoke/reassign end the device's sessions.
- Registry: a device app with user logins must declare '<app>.access'.
- Proxy: location /api/devices/pair-request LAN-only on the :443 servers (both copies).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -46,7 +46,7 @@ CODES: dict[str, tuple[int, str]] = {
|
||||
"module.not_licensed": (402, "This site's license doesn't include {module}."),
|
||||
"module.unknown": (404, "There is no module {module}."),
|
||||
"module.cannot_disable": (400, "{module} is part of the core and can't be turned off."),
|
||||
"license.limit_reached": (402, "License limit reached for {limit} ({max})."),
|
||||
"license.limit_reached": (402, "License limit reached for {module} {limit} ({max})."),
|
||||
"license.expired": (402, "The license has expired."),
|
||||
"license.history_limited": (402, "This license shows only the last {days} days of history ({module})."),
|
||||
# identity
|
||||
@@ -60,6 +60,14 @@ CODES: dict[str, tuple[int, str]] = {
|
||||
"auth.session_not_found": (404, "Session not found."),
|
||||
"device.revoked": (401, "This device was removed. Pair it again."),
|
||||
"device.not_paired": (401, "This device isn't paired with the venue."),
|
||||
"device.out_of_scope": (403, "A {app} device can't do this ({key})."),
|
||||
"device.required": (401, "This login belongs to a paired device. Use it from that device."),
|
||||
"device.not_found": (404, "Device {device_id} not found."),
|
||||
"device.pair_code_invalid": (404, "That pairing code is wrong or has expired."),
|
||||
"device.pair_rate_limited": (429, "Too many pairing requests. Wait a few minutes and try again."),
|
||||
"device.not_an_app": (422, "{app} is not an app that runs on a device."),
|
||||
"device.login_mode_invalid": (422, "A {app} device can't use the login mode {mode}."),
|
||||
"device.link_invalid": (422, "Device {device_id} can't be linked to this device."),
|
||||
# validation
|
||||
"validation.invalid": (422, "Some fields are invalid."),
|
||||
"validation.unknown_language": (422, "Unsupported language: {language}."),
|
||||
|
||||
Reference in New Issue
Block a user