Skip to content

Commit b4b0f3a

Browse files
authored
refactor(sdk): Remove fallback support for the /auth_issuer endpoint
The `/auth_metadata` endpoint has been supported by Synapse for 6 months now so there shouldn't be any homeserver that still depend exclusively on it. This endpoint is also part of Matrix 1.15. Support for this endpoint has been removed from Ruma so this is necessary before an upgrade of the dependency. Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
1 parent ca99977 commit b4b0f3a

File tree

4 files changed

+20
-140
lines changed

4 files changed

+20
-140
lines changed

crates/matrix-sdk/CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ All notable changes to this project will be documented in this file.
3737

3838
### Bug fixes
3939

40-
- `m.room.avatar` has been added as required state for sliding sync until [the existing backend issue](https://github.com/element-hq/synapse/issues/18598)
40+
- `m.room.avatar` has been added as required state for sliding sync until [the existing backend issue](https://github.com/element-hq/synapse/issues/18598)
4141
causing deleted room avatars to not be flagged is fixed. ([#5293](https://github.com/matrix-org/matrix-rust-sdk/pull/5293))
4242

4343
## [0.12.0] - 2025-06-10
@@ -78,7 +78,7 @@ causing deleted room avatars to not be flagged is fixed. ([#5293](https://github
7878
- `Room::send_single_receipt()` and `Room::send_multiple_receipts()` now also unset the unread
7979
flag of the room if an unthreaded read receipt is sent.
8080
([#5055](https://github.com/matrix-org/matrix-rust-sdk/pull/5055))
81-
- `Client::is_user_ignored(&UserId)` can be used to check if a user is currently ignored.
81+
- `Client::is_user_ignored(&UserId)` can be used to check if a user is currently ignored.
8282
([#5081](https://github.com/matrix-org/matrix-rust-sdk/pull/5081))
8383
- `RoomSendQueue::send_gallery` has been added to allow sending MSC4274-style media galleries
8484
via the send queue under the `unstable-msc4274` feature.
@@ -89,12 +89,15 @@ causing deleted room avatars to not be flagged is fixed. ([#5293](https://github
8989
- A invited DM room joined with `Client::join_room_by_id()` or `Client::join_room_by_id_or_alias()`
9090
will now be correctly marked as a DM.
9191
([#5043](https://github.com/matrix-org/matrix-rust-sdk/pull/5043))
92-
- API responses with an HTTP status code `520` won't be retried anymore, as this is used by some proxies
92+
- API responses with an HTTP status code `520` won't be retried anymore, as this is used by some proxies
9393
(including Cloudflare) to warn that an unknown error has happened in the actual server.
9494
([#5105](https://github.com/matrix-org/matrix-rust-sdk/pull/5105))
9595

9696
### Refactor
9797

98+
- Support for the deprecated `GET /auth_issuer` endpoint was removed in the `OAuth` API. Only the
99+
`GET /auth_metadata` endpoint is used now.
100+
([#5302](https://github.com/matrix-org/matrix-rust-sdk/pull/5302))
98101
- `Room::push_context()` has been renamed into `Room::push_condition_room_ctx()`. The newer
99102
`Room::push_context` now returns a `matrix_sdk::Room::PushContext`, which can be used to compute
100103
the push actions for any event.

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

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,9 @@ use oauth2::{
185185
};
186186
pub use oauth2::{ClientId, CsrfToken};
187187
use ruma::{
188-
api::client::discovery::{
189-
get_authentication_issuer,
190-
get_authorization_server_metadata::{
191-
self,
192-
msc2965::{AccountManagementAction, AuthorizationServerMetadata},
193-
},
188+
api::client::discovery::get_authorization_server_metadata::{
189+
self,
190+
msc2965::{AccountManagementAction, AuthorizationServerMetadata},
194191
},
195192
serde::Raw,
196193
DeviceId, OwnedDeviceId,
@@ -207,7 +204,6 @@ mod auth_code_builder;
207204
mod cross_process;
208205
pub mod error;
209206
mod http_client;
210-
mod oidc_discovery;
211207
#[cfg(feature = "e2e-encryption")]
212208
pub mod qrcode;
213209
pub mod registration;
@@ -225,7 +221,6 @@ pub use self::{
225221
};
226222
use self::{
227223
http_client::OAuthHttpClient,
228-
oidc_discovery::discover,
229224
registration::{register_client, ClientMetadata, ClientRegistrationResponse},
230225
};
231226
use super::{AuthData, SessionTokens};
@@ -569,33 +564,6 @@ impl OAuth {
569564
Ok(metadata.account_management_uri.map(AccountManagementUrlBuilder::new))
570565
}
571566

572-
/// Discover the authentication issuer and retrieve the
573-
/// [`AuthorizationServerMetadata`] using the GET `/auth_issuer` endpoint
574-
/// previously defined in [MSC2965].
575-
///
576-
/// **Note**: This endpoint is deprecated.
577-
///
578-
/// MSC2956: https://github.com/matrix-org/matrix-spec-proposals/pull/2965
579-
async fn fallback_discover(
580-
&self,
581-
) -> Result<Raw<AuthorizationServerMetadata>, OAuthDiscoveryError> {
582-
#[allow(deprecated)]
583-
let issuer =
584-
match self.client.send(get_authentication_issuer::msc2965::Request::new()).await {
585-
Ok(response) => response.issuer,
586-
Err(error)
587-
if error
588-
.as_client_api_error()
589-
.is_some_and(|err| err.status_code == http::StatusCode::NOT_FOUND) =>
590-
{
591-
return Err(OAuthDiscoveryError::NotSupported);
592-
}
593-
Err(error) => return Err(error.into()),
594-
};
595-
596-
discover(self.http_client(), &issuer).await
597-
}
598-
599567
/// Fetch the OAuth 2.0 authorization server metadata of the homeserver.
600568
///
601569
/// Returns an error if a problem occurred when fetching or validating the
@@ -609,23 +577,20 @@ impl OAuth {
609577
.is_some_and(|err| err.status_code == http::StatusCode::NOT_FOUND)
610578
};
611579

612-
let raw_metadata = match self
580+
let response = self
613581
.client
614582
.send(get_authorization_server_metadata::msc2965::Request::new())
615583
.await
616-
{
617-
Ok(response) => response.metadata,
618-
// If the endpoint returns a 404, i.e. the server doesn't support the endpoint, attempt
619-
// to use the equivalent, but deprecated, endpoint.
620-
Err(error) if is_endpoint_unsupported(&error) => {
621-
// TODO: remove this fallback behavior when the metadata endpoint has wider
622-
// support.
623-
self.fallback_discover().await?
624-
}
625-
Err(error) => return Err(error.into()),
626-
};
584+
.map_err(|error| {
585+
// If the endpoint returns a 404, i.e. the server doesn't support the endpoint.
586+
if is_endpoint_unsupported(&error) {
587+
OAuthDiscoveryError::NotSupported
588+
} else {
589+
error.into()
590+
}
591+
})?;
627592

628-
let metadata = raw_metadata.deserialize()?;
593+
let metadata = response.metadata.deserialize()?;
629594

630595
if self.ctx().insecure_discover {
631596
metadata.insecure_validate_urls()?;

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

Lines changed: 0 additions & 64 deletions
This file was deleted.

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

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@ use ruma::{
77
api::client::discovery::get_authorization_server_metadata::msc2965::Prompt, device_id,
88
owned_device_id, user_id, DeviceId, ServerName,
99
};
10-
use serde_json::json;
1110
use tokio::sync::broadcast::error::TryRecvError;
1211
use url::Url;
13-
use wiremock::{
14-
matchers::{method, path},
15-
Mock, ResponseTemplate,
16-
};
1712

1813
use super::{
1914
AuthorizationCode, AuthorizationError, AuthorizationResponse, OAuth, OAuthAuthorizationData,
@@ -30,7 +25,7 @@ use crate::{
3025
oauth::{mock_client_id, mock_client_metadata, mock_redirect_uri, mock_session},
3126
MockClientBuilder,
3227
},
33-
mocks::{oauth::MockServerMetadataBuilder, MatrixMockServer},
28+
mocks::MatrixMockServer,
3429
},
3530
Client, Error, SessionChange,
3631
};
@@ -648,30 +643,11 @@ async fn test_server_metadata() {
648643
let server = MatrixMockServer::new().await;
649644
let client = server.client_builder().unlogged().build().await;
650645
let oauth = client.oauth();
651-
let issuer = server.server().uri();
652646

653647
// The endpoint is not mocked so it is not supported.
654648
let error = oauth.server_metadata().await.unwrap_err();
655649
assert!(error.is_not_supported());
656650

657-
// Mock the `GET /auth_issuer` fallback endpoint.
658-
Mock::given(method("GET"))
659-
.and(path("/_matrix/client/unstable/org.matrix.msc2965/auth_issuer"))
660-
.respond_with(ResponseTemplate::new(200).set_body_json(json!({"issuer": issuer})))
661-
.expect(1)
662-
.named("auth_issuer")
663-
.mount(server.server())
664-
.await;
665-
let metadata = MockServerMetadataBuilder::new(&issuer).build();
666-
Mock::given(method("GET"))
667-
.and(path("/.well-known/openid-configuration"))
668-
.respond_with(ResponseTemplate::new(200).set_body_json(metadata))
669-
.expect(1)
670-
.named("openid-configuration")
671-
.mount(server.server())
672-
.await;
673-
oauth.server_metadata().await.unwrap();
674-
675651
// Mock the `GET /auth_metadata` endpoint.
676652
let oauth_server = server.oauth();
677653
oauth_server.mock_server_metadata().ok().expect(1).named("auth_metadata").mount().await;

0 commit comments

Comments
 (0)