Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Support refresh tokens #7802

Merged
merged 8 commits into from
Feb 15, 2022
Merged

Support refresh tokens #7802

merged 8 commits into from
Feb 15, 2022

Conversation

turt2live
Copy link
Member

@turt2live turt2live commented Feb 15, 2022

This was reverted

#7821


MSC: matrix-org/matrix-spec-proposals#2918
Fixes element-hq/element-web#18698
Fixes element-hq/element-web#20648
Requires matrix-org/matrix-js-sdk#2178

Reviewable commit-by-commit

Note: There's a lot of logging in this PR. That is intentional to ensure that if/when something goes wrong we can chase the exact code path. It does not log any tokens - just where the code is going. Overall, it should be fairly low volume spam (and can be relaxed at a later date).


This approach uses indexeddb (through a mutex library) to manage which tab actually triggers the refresh, preventing issues where multiple tabs try to update the token. If multiple tabs update the token then the server might consider the account hacked and hard logout all the tokens.

If for some reason the timer code gets it wrong, or the user has been offline for too long and the token can't be refreshed, they should be sent to a soft logout screen by the server. This will retain the user's encryption state - they simply need to reauthenticate to get an active access token again.

This additionally contains a change to fix soft logout not working, per the issue links above.

Of interest may be the IPC approach which was ultimately declined in favour of this change instead: #7803


This change is marked as an internal change (Task), so will not be included in the changelog.

Preview: https://pr7802--matrix-react-sdk.netlify.app
⚠️ Do you trust the author of this PR? Maybe this build will steal your keys or give you malware. Exercise caution. Use test accounts.

Previously, the user would be soft logged out because the tabs would fight each other. Now with timing (and approach) differences, the tabs are less likely to conflict with each other.
@turt2live turt2live added the T-Enhancement New features, changes in functionality, performance boosts, user-facing improvements label Feb 15, 2022
@turt2live
Copy link
Member Author

argh, even after trying to fix the branch name on the js-sdk side I still screwed it up. Will leave it alone and fix the CI once reviewed.

@turt2live turt2live marked this pull request as ready for review February 15, 2022 03:46
@turt2live turt2live requested a review from a team as a code owner February 15, 2022 03:46
Copy link
Member

@t3chguy t3chguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks sane otherwise

src/TokenLifecycle.ts Outdated Show resolved Hide resolved
src/TokenLifecycle.ts Outdated Show resolved Hide resolved
src/MatrixClientPeg.ts Outdated Show resolved Hide resolved
@turt2live turt2live enabled auto-merge (squash) February 15, 2022 20:08
@turt2live turt2live merged commit 8395934 into develop Feb 15, 2022
@turt2live turt2live deleted the travis/refresh-token-idb branch February 15, 2022 20:16
turt2live added a commit that referenced this pull request Feb 16, 2022
@turt2live turt2live added T-Task Refactoring, enabling or disabling functionality, other engineering tasks and removed T-Enhancement New features, changes in functionality, performance boosts, user-facing improvements labels Feb 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Task Refactoring, enabling or disabling functionality, other engineering tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Soft logout disables encryption when logging back in Support refresh tokens
2 participants