Skip to content

Commit 09513ea

Browse files
zecakehpoljar
authored andcommitted
refactor(oidc): Only support authorization URL parameters defined in MSCs
`prompt=create` is defined in MSC2964, and `login_hint=mxid:@user:server.name` is defined in MSC4198. The other parameters came from OpenID Connect. Signed-off-by: Kévin Commaille <[email protected]>
1 parent fda9177 commit 09513ea

File tree

2 files changed

+13
-89
lines changed

2 files changed

+13
-89
lines changed

crates/matrix-sdk/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ simpler methods:
8080
- Only one request is made to revoke the access token, since the server is
8181
supposed to revoke both the access token and the associated refresh token
8282
when the request is made.
83+
- [**breaking**]: Remove most of the parameter methods of
84+
`OidcAuthCodeUrlBuilder`, since they were parameters defined in OpenID
85+
Connect. Only the `prompt` and `user_id_hint` parameters are still supported.
86+
([#4699](https://github.com/matrix-org/matrix-rust-sdk/pull/4699))
8387

8488
## [0.10.0] - 2025-02-04
8589

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

Lines changed: 9 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use std::{collections::HashSet, num::NonZeroU32};
16-
17-
use language_tags::LanguageTag;
1815
use mas_oidc_client::{
1916
requests::authorization_code::{build_authorization_url, AuthorizationRequestData},
20-
types::{
21-
requests::{Display, Prompt},
22-
scope::Scope,
23-
},
17+
types::{requests::Prompt, scope::Scope},
2418
};
2519
use ruma::UserId;
2620
use tracing::{info, instrument};
@@ -38,92 +32,36 @@ pub struct OidcAuthCodeUrlBuilder {
3832
oidc: Oidc,
3933
scope: Scope,
4034
redirect_uri: Url,
41-
display: Option<Display>,
4235
prompt: Option<Vec<Prompt>>,
43-
max_age: Option<NonZeroU32>,
44-
ui_locales: Option<Vec<LanguageTag>>,
4536
login_hint: Option<String>,
46-
acr_values: Option<HashSet<String>>,
4737
}
4838

4939
impl OidcAuthCodeUrlBuilder {
5040
pub(super) fn new(oidc: Oidc, scope: Scope, redirect_uri: Url) -> Self {
51-
Self {
52-
oidc,
53-
scope,
54-
redirect_uri,
55-
display: None,
56-
prompt: None,
57-
max_age: None,
58-
ui_locales: None,
59-
login_hint: None,
60-
acr_values: None,
61-
}
62-
}
63-
64-
/// Set how the Authorization Server should display the authentication and
65-
/// consent user interface pages to the End-User.
66-
pub fn display(mut self, display: Display) -> Self {
67-
self.display = Some(display);
68-
self
41+
Self { oidc, scope, redirect_uri, prompt: None, login_hint: None }
6942
}
7043

7144
/// Set the [`Prompt`] of the authorization URL.
7245
///
46+
/// If this is not set, it is assumed that the user wants to log into an
47+
/// existing account.
48+
///
7349
/// [`Prompt::Create`] can be used to signify that the user wants to
74-
/// register a new account. If [`Prompt::None`] is used, it must be the only
75-
/// value.
50+
/// register a new account.
7651
pub fn prompt(mut self, prompt: Vec<Prompt>) -> Self {
7752
self.prompt = Some(prompt);
7853
self
7954
}
8055

81-
/// Set the allowable elapsed time in seconds since the last time the
82-
/// End-User was actively authenticated by the OpenID Provider.
83-
pub fn max_age(mut self, max_age: NonZeroU32) -> Self {
84-
self.max_age = Some(max_age);
85-
self
86-
}
87-
88-
/// Set the preferred locales of the user.
89-
///
90-
/// Must be ordered from the preferred locale to the least preferred locale.
91-
pub fn ui_locales(mut self, ui_locales: Vec<LanguageTag>) -> Self {
92-
self.ui_locales = Some(ui_locales);
93-
self
94-
}
95-
96-
/// Set the hint to the Authorization Server about the login identifier the
97-
/// End-User might use to log in.
98-
///
99-
/// To set a Matrix user ID as a login hint, use [`Self::user_id_hint()`].
100-
///
101-
/// Erases any value set with [`Self::user_id_hint()`].
102-
pub fn login_hint(mut self, login_hint: String) -> Self {
103-
self.login_hint = Some(login_hint);
104-
self
105-
}
106-
10756
/// Set the hint to the Authorization Server about the Matrix user ID the
108-
/// End-User might use to log in.
109-
///
110-
/// To set another type of identifier as a login hint, use
111-
/// [`Self::login_hint()`].
57+
/// End-User might use to log in, as defined in [MSC4198].
11258
///
113-
/// Erases any value set with [`Self::login_hint()`].
59+
/// [MSC4198]: https://github.com/matrix-org/matrix-spec-proposals/pull/4198
11460
pub fn user_id_hint(mut self, user_id: &UserId) -> Self {
11561
self.login_hint = Some(format!("mxid:{user_id}"));
11662
self
11763
}
11864

119-
/// Set the requested Authentication Context Class Reference values.
120-
///
121-
/// This is only necessary with specific providers.
122-
pub fn acr_values(mut self, acr_values: HashSet<String>) -> Self {
123-
self.acr_values = Some(acr_values);
124-
self
125-
}
126-
12765
/// Get the URL that should be presented to login via the Authorization Code
12866
/// flow.
12967
///
@@ -135,17 +73,7 @@ impl OidcAuthCodeUrlBuilder {
13573
/// request fails.
13674
#[instrument(target = "matrix_sdk::client", skip_all)]
13775
pub async fn build(self) -> Result<OidcAuthorizationData, OidcError> {
138-
let Self {
139-
oidc,
140-
scope,
141-
redirect_uri,
142-
display,
143-
prompt,
144-
max_age,
145-
ui_locales,
146-
login_hint,
147-
acr_values,
148-
} = self;
76+
let Self { oidc, scope, redirect_uri, prompt, login_hint } = self;
14977

15078
let data = oidc.data().ok_or(OidcError::NotAuthenticated)?;
15179
info!(
@@ -159,16 +87,8 @@ impl OidcAuthCodeUrlBuilder {
15987
AuthorizationRequestData::new(data.client_id.0.clone(), scope, redirect_uri);
16088
authorization_data.code_challenge_methods_supported =
16189
provider_metadata.code_challenge_methods_supported.clone();
162-
authorization_data.display = display;
16390
authorization_data.prompt = prompt;
164-
authorization_data.max_age = max_age;
165-
authorization_data.ui_locales = ui_locales;
16691
authorization_data.login_hint = login_hint;
167-
authorization_data.acr_values = acr_values;
168-
169-
if let Some(id_token) = oidc.latest_id_token() {
170-
authorization_data.id_token_hint = Some(id_token.into_string());
171-
}
17292

17393
let authorization_endpoint = provider_metadata.authorization_endpoint();
17494

0 commit comments

Comments
 (0)