Skip to content

fix(accounts): keep the tokens of a device's overlapping sign-ins - #1727

Merged
moodiness merged 2 commits into
mainfrom
fix/device-sign-ins
Dec 5, 2026
Merged

moodiness merged 2 commits into
mainfrom
fix/device-sign-ins

Conversation

@moodiness

Copy link
Copy Markdown
Owner

Polyfin kept one row per user and device identifier, and signing in again from the same device replaced its token. An app that signs in several times at once with one DeviceId, and keeps using each token it was given, ended up with one working token: its other requests got 401, signed in again, and took the token of the one before, in a loop.

Jellyfin gives each sign-in a device entry of its own, and a sign-in signs out the earlier entries of its user and device (SessionManager.GetAuthorizationToken). Sign-ins at the same moment each miss the others, so they all keep working until the device's next sign-in.

  • The access tokens move to a table of their own, device_tokens, next to the device they belong to. Tokens issued before the upgrade are copied over and keep working.
  • A sign-in keeps the device's tokens issued in the minute before it, 8 at most with its own, and retires older ones: they answer 401 from then on. So parallel sign-ins all work, and the next sign-in a minute or more later ends them, as on Jellyfin, without rows growing without bound.
  • The device stays one row: /Devices and the admin app list it once, /Sessions shows one session, and its capabilities, WebSocket, remote control, SyncPlay group, play sessions and grants, play profiles and the name /Devices/Options gives it are the same whichever token asks.
  • A sign-in that keeps no earlier token starts the device anew and clears its capabilities, as every sign-in did before; one that joins recent tokens keeps them.
  • A sign-in through the identity provider and one without keep no token of each other, so no token opens the admin app without a code because another sign-in of its device went through the provider.
  • POST /Sessions/Logout with any token signs the whole device out, every token with it; so do signing it out under Devices, DELETE /Devices?id=, a password change from another device and disabling or deleting the account. A password change from the device keeps all its tokens. API keys are untouched.
  • Docs: docs/users.md (Signed-in devices) and docs/jellyfin-api.md (Signing in again from a device for apps).

Upgrading: nothing to do. Every app stays signed in.

Tests:

  • TestParallelSignInsFromOneDeviceEachKeepTheirToken (new): 8 sign-ins at once from one device all work, on one device. Fails with no overlap kept.
  • TestSigningInAgainFromADeviceRetiresOnlyItsOlderTokens (was ...ReplacesOnlyItsToken): a sign-in of a moment before keeps working; once a minute has passed, the next sign-in retires both, other devices and users untouched. Fails when older tokens are not retired.
  • TestADeviceHoldsBoundedTokens (new): past 8 sign-ins the oldest tokens are retired, however recent. Fails without the bound.
  • TestSignInsThroughTheProviderAndWithoutKeepNoTokenOfEachOther (new). Fails when the provider is not compared.
  • TestOnlyADeviceSigningInAnewForgetsItsCapabilities (new): kept across an overlapping sign-in, cleared by a later one. Fails both when never cleared and when always cleared.
  • TestSigningADeviceOutEndsEveryToken (new): the app's sign-out, the user's, by device identifier, a password change from another device and disabling the account each end both tokens of the device and tell of it once; a password change from the device keeps both. Fails when the app's sign-out ends only its own token.
  • TestOverlappingSignInsFromOneDeviceShareIt (new, Jellyfin API): four parallel sign-ins; one device in /Devices with its name and capabilities, one session for every token, one token's socket gets the SyncPlay group another made and a remote command, Quick Connect approves with a third, and POST /Sessions/Logout with one ends every token, the socket and the group while another device and an API key go on. Fails with no overlap kept, and when the sign-out ends only its own token.
  • TestSignInAndSignOut: a token of a moment before works, both end with a later sign-in, the last with its logout.
  • TestDeviceTokensKeepTheSignInsMadeBefore (new): the migration keeps each device's token, which goes with its device. Fails without the copy.
  • TestEveryChangeIsSeenFromTheNextRequest, TestCapabilitiesLeaveOtherDevicesSignInsResolved, TestAUserPastTheBoundIsBroughtToItAtTheirNextSignIn: adjusted to the new table, still passing.

Signing in again from a device replaced its token, so an app that signs
in several times at once from one device identifier kept one working
token, and its other requests got 401 in a loop.

A device now keeps its tokens in device_tokens. A sign-in keeps the
device's tokens issued in the minute before it, 8 at most with its own,
and retires older ones, as Jellyfin signs out a device's earlier sign-
ins while sign-ins at the same moment miss each other. The device stays
one row: its session, capabilities, socket, SyncPlay group, grants and
listing are the same whichever token asks, and signing it out, by the
app, an administrator, a password change from another device or
disabling the account, ends every token. A sign-in that keeps no earlier
token resets the capabilities, and one through the identity provider and
one without keep no token of each other. Tokens issued before the
upgrade keep working.
Devices lists a device once however many times its app signed in, and
the API notes tell which tokens a sign-in keeps and what ends them.
@moodiness
moodiness marked this pull request as ready for review December 5, 2026 03:14
@moodiness
moodiness merged commit 540ca96 into main Dec 5, 2026
54 checks passed
@moodiness
moodiness deleted the fix/device-sign-ins branch December 5, 2026 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant