Skip to content

Commit fda9177

Browse files
zecakehpoljar
authored andcommitted
refactor(oidc): Remove support for Pushed Authorization Requests
It is a small optimization which makes the URL smaller, but it is not part of the next-gen auth MSCs and is not supported by the oauth2 crate, so let's drop it. Signed-off-by: Kévin Commaille <[email protected]>
1 parent 21960a5 commit fda9177

File tree

4 files changed

+10
-93
lines changed

4 files changed

+10
-93
lines changed

crates/matrix-sdk/src/authentication/oidc/auth_code_builder.rs

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use mas_oidc_client::{
2323
},
2424
};
2525
use ruma::UserId;
26-
use tracing::{error, info, instrument};
26+
use tracing::{info, instrument};
2727
use url::Url;
2828

2929
use super::{Oidc, OidcError};
@@ -171,55 +171,12 @@ impl OidcAuthCodeUrlBuilder {
171171
}
172172

173173
let authorization_endpoint = provider_metadata.authorization_endpoint();
174-
let mut rng = super::rng()?;
175-
176-
// Try a pushed authorization request if the provider supports it.
177-
let (url, validation_data) = if let Some(par_endpoint) =
178-
&provider_metadata.pushed_authorization_request_endpoint
179-
{
180-
let client_credentials = oidc.data().ok_or(OidcError::NotAuthenticated)?.credentials();
181-
182-
let res = oidc
183-
.backend
184-
.build_par_authorization_url(
185-
client_credentials.clone(),
186-
par_endpoint,
187-
authorization_endpoint.clone(),
188-
authorization_data.clone(),
189-
)
190-
.await;
191-
192-
match res {
193-
Ok(res) => res,
194-
Err(error) => {
195-
// Keycloak doesn't allow public clients to use the PAR endpoint, so we
196-
// should try a regular authorization URL instead.
197-
// See: <https://github.com/keycloak/keycloak/issues/8939>
198-
let client_metadata =
199-
oidc.client_metadata().ok_or(OidcError::NotAuthenticated)?;
200-
201-
// If the client said that PAR should be enforced, we should not try without
202-
// it, so just return the error.
203-
if client_metadata.require_pushed_authorization_requests.unwrap_or(false) {
204-
return Err(error);
205-
}
206-
207-
error!(
208-
?error,
209-
"Error making a request to the Pushed Authorization Request endpoint. \
210-
Falling back to a regular authorization URL"
211-
);
212-
213-
build_authorization_url(
214-
authorization_endpoint.clone(),
215-
authorization_data,
216-
&mut rng,
217-
)?
218-
}
219-
}
220-
} else {
221-
build_authorization_url(authorization_endpoint.clone(), authorization_data, &mut rng)?
222-
};
174+
175+
let (url, validation_data) = build_authorization_url(
176+
authorization_endpoint.clone(),
177+
authorization_data,
178+
&mut super::rng()?,
179+
)?;
223180

224181
let state = validation_data.state.clone();
225182

crates/matrix-sdk/src/authentication/oidc/backend/mock.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use mas_oidc_client::{
2222
DiscoveryError as OidcDiscoveryError, Error as OidcClientError, ErrorBody as OidcErrorBody,
2323
HttpError as OidcHttpError, TokenRefreshError, TokenRequestError,
2424
},
25-
requests::authorization_code::{AuthorizationRequestData, AuthorizationValidationData},
25+
requests::authorization_code::AuthorizationValidationData,
2626
types::{
2727
client_credentials::ClientCredentials,
2828
errors::ClientErrorCode,
@@ -192,16 +192,6 @@ impl OidcBackend for MockImpl {
192192
})
193193
}
194194

195-
async fn build_par_authorization_url(
196-
&self,
197-
_client_credentials: ClientCredentials,
198-
_par_endpoint: &Url,
199-
_authorization_endpoint: Url,
200-
_authorization_data: AuthorizationRequestData,
201-
) -> Result<(Url, AuthorizationValidationData), OidcError> {
202-
unimplemented!()
203-
}
204-
205195
async fn revoke_token(
206196
&self,
207197
_client_credentials: ClientCredentials,

crates/matrix-sdk/src/authentication/oidc/backend/mod.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//! Used mostly for testing purposes.
1818
1919
use mas_oidc_client::{
20-
requests::authorization_code::{AuthorizationRequestData, AuthorizationValidationData},
20+
requests::authorization_code::AuthorizationValidationData,
2121
types::{
2222
client_credentials::ClientCredentials,
2323
iana::oauth::OAuthTokenTypeHint,
@@ -72,14 +72,6 @@ pub(super) trait OidcBackend: std::fmt::Debug + Send + Sync {
7272
latest_id_token: Option<IdToken<'static>>,
7373
) -> Result<RefreshedSessionTokens, OidcError>;
7474

75-
async fn build_par_authorization_url(
76-
&self,
77-
client_credentials: ClientCredentials,
78-
par_endpoint: &Url,
79-
authorization_endpoint: Url,
80-
authorization_data: AuthorizationRequestData,
81-
) -> Result<(Url, AuthorizationValidationData), OidcError>;
82-
8375
async fn revoke_token(
8476
&self,
8577
client_credentials: ClientCredentials,

crates/matrix-sdk/src/authentication/oidc/backend/server.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ use mas_oidc_client::{
2323
http_service::HttpService,
2424
jose::jwk::PublicJsonWebKeySet,
2525
requests::{
26-
authorization_code::{
27-
access_token_with_authorization_code, build_par_authorization_url,
28-
AuthorizationRequestData, AuthorizationValidationData,
29-
},
26+
authorization_code::{access_token_with_authorization_code, AuthorizationValidationData},
3027
discovery::{discover, insecure_discover},
3128
jose::{fetch_jwks, JwtVerificationData},
3229
refresh_token::refresh_access_token,
@@ -225,25 +222,6 @@ impl OidcBackend for OidcServer {
225222
.map_err(Into::into)
226223
}
227224

228-
async fn build_par_authorization_url(
229-
&self,
230-
client_credentials: ClientCredentials,
231-
par_endpoint: &Url,
232-
authorization_endpoint: Url,
233-
authorization_data: AuthorizationRequestData,
234-
) -> Result<(Url, AuthorizationValidationData), OidcError> {
235-
Ok(build_par_authorization_url(
236-
&self.http_service(),
237-
client_credentials,
238-
par_endpoint,
239-
authorization_endpoint,
240-
authorization_data,
241-
Utc::now(),
242-
&mut rng()?,
243-
)
244-
.await?)
245-
}
246-
247225
async fn revoke_token(
248226
&self,
249227
client_credentials: ClientCredentials,

0 commit comments

Comments
 (0)