Make player token reset non-breaking (deferred rotation)

The maintenance-page reset used to rotate auth_code immediately. Because the
token also guards the playlist endpoints, that stopped a player from syncing
content the instant the button was pressed -- before the player ever had a
chance to react -- and clients that do not understand the heartbeat's
401 auth_required would have stayed broken until redeployed.

Split the model behaviour:

* request_reauth()  -- sets the flag only (used by the admin reset endpoints
  and the automatic interval). The current token stays valid, so there is no
  outage while the player is being asked to re-authenticate.
* issue_new_token() -- replaces the token now (used by the existing
  "regenerate auth code" action, where the admin is shown the new value).
* mark_authenticated() -- if a reset was pending, this is where the old token
  is retired: a new token is issued and returned to the player in the
  /api/auth/player response.

Net effect: the reset is a request the player acts on, never a forced logout.
A player that ignores it keeps working and shows as "awaiting re-auth" in the
UI; one that handles it gets a fresh token and the old one stops working.

Maintenance page wording updated to match (request vs reset; "awaiting
re-auth" badge), plus a themed info note explaining it is not a forced logout.

Adds docs/player-auth-reset.md describing the protocol and exactly what the
player client (Kiwy-Signage) still needs to implement: detect 401 /
auth_required on the heartbeat (and on the token-guarded endpoints), re-run
POST /api/auth/player with the stored quick-connect code, save the new
auth_code and retry. No password or SSH redeploy required.

Verified end-to-end: token unchanged and still accepted after the request
(200), heartbeat answers 401 auth_required=token_reset, re-auth issues a
different token, the old token is then rejected (403) and the new one accepted
(200), flag cleared; the interval path only flags without rotating.
This commit is contained in:
2026-10-14 23:14:11 +03:00
parent 4dc8506c9b
commit 6b0e51898c
6 changed files with 287 additions and 62 deletions
+6 -4
View File
@@ -300,10 +300,12 @@ def regenerate_auth_code(player_id: int):
try:
player = Player.query.get_or_404(player_id)
# Issue a new auth code and stamp the issue time so the maintenance
# page's reset interval measures age from this point. A manual
# regenerate keeps its previous behaviour (no forced re-auth).
new_auth_code = player.rotate_auth_token(force_reauth=False)
# Issue a new auth code immediately and stamp the issue time so the
# maintenance page's reset interval measures age from this point. The
# admin is shown the new value, so an immediate swap is intended here —
# unlike the maintenance page, which only asks the player to re-auth.
new_auth_code = player.issue_new_token()
player.auth_reset_required = False
db.session.commit()
log_action('info', f'Auth code regenerated for player "{player.name}" (ID: {player_id})')