Skip to content

feat: add refresh token handling http client #2033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TheOneWithTheBraid
Copy link
Contributor

Sorry for once again coming up with a random PR ... Can I kindly ask you to check whether this implementation matches your expectations about handling soft-logout in more advanced use cases ?

This will especially be relevant for end users once #2024 might be shipped to client developers.

  • implement a MatrixRefreshTokenClient to await token refresh before dispatching http requests
  • improve documentation about soft logout logic
  • fix dartdoc locations about soft logout

Fixes: #2027

@TheOneWithTheBraid TheOneWithTheBraid force-pushed the braid/refresh-token-http-client branch from c7a965c to 84480e8 Compare May 15, 2025 11:36
@TheOneWithTheBraid
Copy link
Contributor Author

Is there any update on review of this PR ?

- implement a `MatrixRefreshTokenClient` to await token refresh before
  dispatching http requests
- improve documentation about soft logout logic
- fix dartdoc locations about soft logout

Fixes: famedly#2027

Signed-off-by: The one with the braid <info@braid.business>
@TheOneWithTheBraid TheOneWithTheBraid force-pushed the braid/refresh-token-http-client branch from 84480e8 to 356f831 Compare May 20, 2025 08:57
// we are actually initialized
client.onSync.value != null &&
// the request is to the homeserver rather than e.g. IDP
request.url.host == client.homeserver?.host &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also add this check: request.url.pathSegments.first == '_matrix'. Someone coud place for example a synapse module at: /_custom/api/v1/...

final headers = request.headers;
// hours wasted : unknown :facepalm:
headers.removeWhere((k, _) => k.toLowerCase() == 'authorization');
headers['Authorization'] = 'Bearer ${client.bearerToken!}';
Copy link
Contributor

Choose a reason for hiding this comment

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

this now always adds the Authorization header right? Even if we don't have a token or don't want to set it for some reason.

Copy link
Contributor

@krille-chan krille-chan left a comment

Choose a reason for hiding this comment

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

Not sure if I'm happy with doing it on httpclient level. I really get why we want to do it this way we also check it unnecessarily often.

Doing this check on sync had the reason that we do it around every 30 seconds periodically. If we do it for every single request we would have this check done quite a lot, like multiple times per second.

With refresh tokens the access token has a lifetime of 5 minutes by default. Actually we know when it will be no longer valid so we could refresh it 1 minute before the lifetime ends. In the sync handler we do exactly this. If this is not working, we should investigate the reason for it

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.

Make http requests soft logout aware
2 participants