Skip to content

Commit 885845f

Browse files
committed
fix: Skip authorization headers when doing a /versions while doing a token refresh
1 parent 6ceb6e5 commit 885845f

File tree

1 file changed

+20
-11
lines changed
  • crates/matrix-sdk/src/authentication/oauth

1 file changed

+20
-11
lines changed

crates/matrix-sdk/src/authentication/oauth/mod.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -505,17 +505,26 @@ impl OAuth {
505505
.is_some_and(|err| err.status_code == http::StatusCode::NOT_FOUND)
506506
};
507507

508-
let response =
509-
self.client.send(get_authorization_server_metadata::v1::Request::new()).await.map_err(
510-
|error| {
511-
// If the endpoint returns a 404, i.e. the server doesn't support the endpoint.
512-
if is_endpoint_unsupported(&error) {
513-
OAuthDiscoveryError::NotSupported
514-
} else {
515-
error.into()
516-
}
517-
},
518-
)?;
508+
let response = self
509+
.client
510+
.send(get_authorization_server_metadata::v1::Request::new())
511+
// Skip auth while sending this request. This request itself might not require auth,
512+
// but as part of the building of the correct URL we might do a `/versions` call which
513+
// optionally accepts it.
514+
//
515+
// If we're fetching the server metadata to refresh our token, then we don't have valid
516+
// auth headers so the `/versions` call will fail and subsequently the refresh of the
517+
// token as well.
518+
.with_request_config(self.client.request_config().skip_auth())
519+
.await
520+
.map_err(|error| {
521+
// If the endpoint returns a 404, i.e. the server doesn't support the endpoint.
522+
if is_endpoint_unsupported(&error) {
523+
OAuthDiscoveryError::NotSupported
524+
} else {
525+
error.into()
526+
}
527+
})?;
519528

520529
let metadata = response.metadata.deserialize()?;
521530

0 commit comments

Comments
 (0)