Repository navigation
fix(accounts): keep the tokens of a device's overlapping sign-ins - #1727
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.device_tokens, next to the device they belong to. Tokens issued before the upgrade are copied over and keep working./Devicesand the admin app list it once,/Sessionsshows one session, and its capabilities, WebSocket, remote control, SyncPlay group, play sessions and grants, play profiles and the name/Devices/Optionsgives it are the same whichever token asks.POST /Sessions/Logoutwith 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/users.md(Signed-in devices) anddocs/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/Deviceswith 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, andPOST /Sessions/Logoutwith 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.