Skip to content

App: Refresh Tokens Implementation#5293

Merged
langleyd merged 20 commits intodevelopfrom
langleyd/5292_refresh_tokens
Jan 31, 2022
Merged

App: Refresh Tokens Implementation#5293
langleyd merged 20 commits intodevelopfrom
langleyd/5292_refresh_tokens

Conversation

@langleyd
Copy link
Copy Markdown
Member

@langleyd langleyd commented Dec 9, 2021

Resolves #5292

Dependant on matrix-org/matrix-ios-sdk#1319

Included in this PR

  • Introduces BuildSettings.authEnableRefreshTokens which enables refresh token auth on the client, which takes effect on the next user login. I the user is already logged in access token auth will remain in use until the user logs out.
  • Adds refresh token and the current access token expiration timestamp to the MXKAccount coding so that it is persisted when accounts are saved.
  • We also listen for the MXRestClientDidRefreshTokensNotification and save accounts when the tokens change.
  • Split out the a new MXKAccountData class from MXKAccount that contains just the codable data so that we can read/write account data to disk without the sideeffects that occur with in MXKAccount.
  • Use MXKAccountData to read credentials from disk and write them back in a single transaction using NSFileCoordinator. This is used within the refresh token flow to avoid data race conditions/corruption when refreshing tokens across processes (App + Notification, Sharing, Siri extensions).
  • Fixed a bug of the grey spinner staying up on the HomeViewControllerWithBannerWrapperViewController. It now passes start/stop events through to the underlying HomeViewController which correctly listens to sync events via inheriting MXKViewController.

Todo:

  • Further testing on extension use cases.
  • Add posthog events for unauthenticated.
  • Test disconnecting and reconnecting to an identity server from settings.

@langleyd langleyd changed the title Refresh Tokens Refresh Tokens Implementation Dec 9, 2021
@langleyd langleyd changed the title Refresh Tokens Implementation App Refresh Tokens Implementation Dec 14, 2021
@langleyd langleyd changed the title App Refresh Tokens Implementation App: Refresh Tokens Implementation Dec 14, 2021
@langleyd
Copy link
Copy Markdown
Member Author

langleyd commented Dec 15, 2021

Just realised refresh tokens will be a bit of a problem with the notification extension. The refresh token rotates each time you request a new access token (so you get a new access token and refresh token in the response). So you need to coordinate any processes and insure there is only 1 refresh exchange happening at any point in time. If you request a refresh with an invalid refresh I think you'l be signed out.

…ut side effects. Also change force reload of accounts to stop double load on init.
- Remove some duplication of logout behaviour
- Fix additional spinner on homeViewController
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 11, 2022

📱 Scan the QR code below to install the build for this PR.
🔒 This build is for internal testing purpose. Only devices listed in the ad-hoc provisioning profile can install Element Alpha.

QR code

If you can't scan the QR code you can install the build via this link: https://i.diawi.com/xLodiE

@langleyd langleyd marked this pull request as ready for review January 24, 2022 21:14
@langleyd langleyd merged commit 4566bd8 into develop Jan 31, 2022
@langleyd langleyd deleted the langleyd/5292_refresh_tokens branch January 31, 2022 08:59
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.

Implement Refresh Tokens

3 participants