Skip to content

Commit 525f986

Browse files
committed
refactor(auth-qrcode): Rename everything OIDC to OAuth 2.0
Signed-off-by: Kévin Commaille <[email protected]>
1 parent d7dc1c9 commit 525f986

File tree

4 files changed

+74
-65
lines changed

4 files changed

+74
-65
lines changed

bindings/matrix-sdk-ffi/src/client_builder.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl From<qrcode::QRCodeLoginError> for HumanQrLoginError {
104104
_ => HumanQrLoginError::Unknown,
105105
},
106106

107-
QRCodeLoginError::Oidc(e) => {
107+
QRCodeLoginError::Oauth(e) => {
108108
if let Some(e) = e.as_request_token_error() {
109109
match e {
110110
DeviceCodeErrorResponseType::AccessDenied => HumanQrLoginError::Declined,
@@ -153,8 +153,8 @@ pub enum QrLoginProgress {
153153
/// first digit is a zero.
154154
check_code_string: String,
155155
},
156-
/// We are waiting for the login and for the OIDC provider to give us an
157-
/// access token.
156+
/// We are waiting for the login and for the OAuth 2.0 authorization server
157+
/// to give us an access token.
158158
WaitingForToken { user_code: String },
159159
/// The login has successfully finished.
160160
Done,
@@ -673,8 +673,8 @@ impl ClientBuilder {
673673
///
674674
/// This method will build the client and immediately attempt to log the
675675
/// client in using the provided [`QrCodeData`] using the login
676-
/// mechanism described in [MSC4108]. As such this methods requires OIDC
677-
/// support as well as sliding sync support.
676+
/// mechanism described in [MSC4108]. As such this methods requires OAuth
677+
/// 2.0 support as well as sliding sync support.
678678
///
679679
/// The usage of the progress_listener is required to transfer the
680680
/// [`CheckCode`] to the existing client.

crates/matrix-sdk/src/authentication/qrcode/login.rs

+39-32
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use tracing::trace;
3030
use vodozemac::ecies::CheckCode;
3131

3232
use super::{
33-
messages::LoginFailureReason, oidc_client::OidcClient, DeviceAuhorizationOidcError,
33+
messages::LoginFailureReason, oauth_client::OauthClient, DeviceAuthorizationOauthError,
3434
SecureChannelError,
3535
};
3636
#[cfg(doc)]
@@ -66,11 +66,13 @@ pub enum LoginProgress {
6666
/// The check code we need to, out of band, send to the other device.
6767
check_code: CheckCode,
6868
},
69-
/// We're waiting for the OIDC provider to give us the access token. This
70-
/// will only happen if the other device allows the OIDC provider to so.
69+
/// We're waiting for the OAuth 2.0 authorization server to give us the
70+
/// access token. This will only happen if the other device allows the
71+
/// OAuth 2.0 authorization server to do so.
7172
WaitingForToken {
72-
/// The user code the OIDC provider has given us, the OIDC provider
73-
/// might ask the other device to enter this code.
73+
/// The user code the OAuth 2.0 authorization server has given us, the
74+
/// OAuth 2.0 authorization server might ask the other device to
75+
/// enter this code.
7476
user_code: String,
7577
},
7678
/// The login process has completed.
@@ -115,20 +117,20 @@ impl<'a> IntoFuture for LoginWithQrCode<'a> {
115117
let check_code = channel.check_code().to_owned();
116118
self.state.set(LoginProgress::EstablishingSecureChannel { check_code });
117119

118-
// Register the client with the OIDC provider.
119-
trace!("Registering the client with the OIDC provider.");
120-
let oidc_client = self.register_client().await?;
120+
// Register the client with the OAuth 2.0 authorization server.
121+
trace!("Registering the client with the OAuth 2.0 authorization server.");
122+
let oauth_client = self.register_client().await?;
121123

122124
// We want to use the Curve25519 public key for the device ID, so let's generate
123125
// a new vodozemac `Account` now.
124126
let account = vodozemac::olm::Account::new();
125127
let public_key = account.identity_keys().curve25519;
126128
let device_id = public_key;
127129

128-
// Let's tell the OIDC provider that we want to log in using the device
129-
// authorization grant described in [RFC8628](https://datatracker.ietf.org/doc/html/rfc8628).
130+
// Let's tell the OAuth 2.0 authorization server that we want to log in using
131+
// the device authorization grant described in [RFC8628](https://datatracker.ietf.org/doc/html/rfc8628).
130132
trace!("Requesting device authorization.");
131-
let auth_grant_response = oidc_client.request_device_authorization(device_id).await?;
133+
let auth_grant_response = oauth_client.request_device_authorization(device_id).await?;
132134

133135
// Now we need to inform the other device of the login protocols we picked and
134136
// the URL they should use to log us in.
@@ -155,17 +157,17 @@ impl<'a> IntoFuture for LoginWithQrCode<'a> {
155157
}
156158
}
157159

158-
// The OIDC provider may or may not show this user code to double check that
159-
// we're talking to the right OIDC provider. Let us display this, so
160+
// The OAuth 2.0 authorization server may or may not show this user code to
161+
// double check that we're talking to the right server. Let us display this, so
160162
// the other device can double check this as well.
161163
let user_code = auth_grant_response.user_code();
162164
self.state
163165
.set(LoginProgress::WaitingForToken { user_code: user_code.secret().to_owned() });
164166

165-
// Let's now wait for the access token to be provided to use by the OIDC
166-
// provider.
167-
trace!("Waiting for the OIDC provider to give us the access token.");
168-
let session_tokens = match oidc_client.wait_for_tokens(&auth_grant_response).await {
167+
// Let's now wait for the access token to be provided to use by the OAuth 2.0
168+
// authorization server.
169+
trace!("Waiting for the OAuth 2.0 authorization server to give us the access token.");
170+
let session_tokens = match oauth_client.wait_for_tokens(&auth_grant_response).await {
169171
Ok(t) => t,
170172
Err(e) => {
171173
// If we received an error, and it's one of the ones we should report to the
@@ -192,11 +194,11 @@ impl<'a> IntoFuture for LoginWithQrCode<'a> {
192194
};
193195
self.client.oidc().set_session_tokens(session_tokens);
194196

195-
// We only received an access token from the OIDC provider, we have no clue who
196-
// we are, so we need to figure out our user ID now.
197-
// TODO: This snippet is almost the same as the Oidc::finish_login_method(), why
198-
// is that method even a public method and not called as part of the set session
199-
// tokens method.
197+
// We only received an access token from the OAuth 2.0 authorization server, we
198+
// have no clue who we are, so we need to figure out our user ID
199+
// now. TODO: This snippet is almost the same as the
200+
// Oidc::finish_login_method(), why is that method even a public
201+
// method and not called as part of the set session tokens method.
200202
trace!("Discovering our own user id.");
201203
let whoami_response =
202204
self.client.whoami().await.map_err(QRCodeLoginError::UserIdDiscovery)?;
@@ -290,16 +292,17 @@ impl<'a> LoginWithQrCode<'a> {
290292
Ok(channel)
291293
}
292294

293-
async fn register_client(&self) -> Result<OidcClient, DeviceAuhorizationOidcError> {
295+
async fn register_client(&self) -> Result<OauthClient, DeviceAuthorizationOauthError> {
294296
let oidc = self.client.oidc();
295297

296-
// Let's figure out the OIDC issuer, this fetches the info from the homeserver.
298+
// Let's figure out the OAuth 2.0 issuer, this fetches the info from the
299+
// homeserver.
297300
let issuer = oidc
298301
.fetch_authentication_issuer()
299302
.await
300-
.map_err(DeviceAuhorizationOidcError::AuthenticationIssuer)?;
303+
.map_err(DeviceAuthorizationOauthError::AuthenticationIssuer)?;
301304

302-
// Now we register the client with the OIDC provider.
305+
// Now we register the client with the OAuth 2.0 authorization server.
303306
let registration_response =
304307
oidc.register_client(&issuer, self.client_metadata.clone(), None).await?;
305308

@@ -317,7 +320,7 @@ impl<'a> LoginWithQrCode<'a> {
317320
let http_client = self.client.inner.http_client.clone();
318321
let server_metadata = oidc.provider_metadata().await?;
319322

320-
OidcClient::new(registration_response.client_id, &server_metadata, http_client)
323+
OauthClient::new(registration_response.client_id, &server_metadata, http_client)
321324
}
322325
}
323326

@@ -620,7 +623,10 @@ mod test {
620623
alice.send_json(message).await.unwrap();
621624
}
622625

623-
async fn mock_oidc_provider(server: &MockServer, token_response: ResponseTemplate) {
626+
async fn mock_oauth_authorization_server(
627+
server: &MockServer,
628+
token_response: ResponseTemplate,
629+
) {
624630
Mock::given(method("GET"))
625631
.and(path("/_matrix/client/unstable/org.matrix.msc2965/auth_issuer"))
626632
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
@@ -680,7 +686,8 @@ mod test {
680686
let rendezvous_server = MockedRendezvousServer::new(&server, "abcdEFG12345").await;
681687
let (sender, receiver) = tokio::sync::oneshot::channel();
682688

683-
mock_oidc_provider(&server, ResponseTemplate::new(200).set_body_json(token())).await;
689+
mock_oauth_authorization_server(&server, ResponseTemplate::new(200).set_body_json(token()))
690+
.await;
684691

685692
Mock::given(method("GET"))
686693
.and(path("/_matrix/client/r0/account/whoami"))
@@ -775,7 +782,7 @@ mod test {
775782
let rendezvous_server = MockedRendezvousServer::new(&server, "abcdEFG12345").await;
776783
let (sender, receiver) = tokio::sync::oneshot::channel();
777784

778-
mock_oidc_provider(&server, token_response).await;
785+
mock_oauth_authorization_server(&server, token_response).await;
779786

780787
Mock::given(method("GET"))
781788
.and(path("/_matrix/client/r0/account/whoami"))
@@ -841,7 +848,7 @@ mod test {
841848
)
842849
.await;
843850

844-
assert_let!(Err(QRCodeLoginError::Oidc(e)) = result);
851+
assert_let!(Err(QRCodeLoginError::Oauth(e)) = result);
845852
assert_eq!(
846853
e.as_request_token_error(),
847854
Some(&DeviceCodeErrorResponseType::AccessDenied),
@@ -859,7 +866,7 @@ mod test {
859866
)
860867
.await;
861868

862-
assert_let!(Err(QRCodeLoginError::Oidc(e)) = result);
869+
assert_let!(Err(QRCodeLoginError::Oauth(e)) = result);
863870
assert_eq!(
864871
e.as_request_token_error(),
865872
Some(&DeviceCodeErrorResponseType::ExpiredToken),

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

+19-18
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414

1515
//! Types for the QR code login support defined in [MSC4108](https://github.com/matrix-org/matrix-spec-proposals/pull/4108).
1616
//!
17-
//! Please note, QR code logins are only supported when using OIDC as the
18-
//! auththentication mechanism, native Matrix authentication does not support
19-
//! it.
17+
//! Please note, QR code logins are only supported when using OAuth 2.0 as the
18+
//! authentication mechanism, native Matrix authentication does not support it.
2019
//!
2120
//! This currently only implements the case where the new device is scanning the
2221
//! QR code. To log in using a QR code, please take a look at the
23-
//! [`Oidc::login_with_qr_code()`] method
22+
//! [`Oidc::login_with_qr_code()`] method.
2423
2524
use as_variant::as_variant;
2625
use matrix_sdk_base::crypto::SecretImportError;
@@ -39,7 +38,7 @@ use crate::{authentication::oidc::CrossProcessRefreshLockError, HttpError};
3938

4039
mod login;
4140
mod messages;
42-
mod oidc_client;
41+
mod oauth_client;
4342
mod rendezvous_channel;
4443
mod secure_channel;
4544

@@ -57,9 +56,10 @@ pub use self::{
5756
#[derive(Debug, Error)]
5857
#[cfg_attr(feature = "uniffi", derive(uniffi::Error), uniffi(flat_error))]
5958
pub enum QRCodeLoginError {
60-
/// An error happened while we were communicating with the OIDC provider.
59+
/// An error happened while we were communicating with the OAuth 2.0
60+
/// authorization server.
6161
#[error(transparent)]
62-
Oidc(#[from] DeviceAuhorizationOidcError),
62+
Oauth(#[from] DeviceAuthorizationOauthError),
6363

6464
/// The other device has signaled to us that the login has failed.
6565
#[error("The login failed, reason: {reason}")]
@@ -88,7 +88,8 @@ pub enum QRCodeLoginError {
8888
CrossProcessRefreshLock(#[from] CrossProcessRefreshLockError),
8989

9090
/// An error happened while we were trying to discover our user and device
91-
/// ID, after we have acquired an access token from the OIDC provider.
91+
/// ID, after we have acquired an access token from the OAuth 2.0
92+
/// authorization server.
9293
#[error(transparent)]
9394
UserIdDiscovery(HttpError),
9495

@@ -108,13 +109,13 @@ pub enum QRCodeLoginError {
108109
}
109110

110111
/// Error type describing failures in the interaction between the device
111-
/// attempting to log in and the OIDC provider.
112+
/// attempting to log in and the OAuth 2.0 authorization server.
112113
#[derive(Debug, Error)]
113-
pub enum DeviceAuhorizationOidcError {
114-
/// A generic OIDC error happened while we were attempting to register the
115-
/// device with the OIDC provider.
114+
pub enum DeviceAuthorizationOauthError {
115+
/// A generic OAuth 2.0 error happened while we were attempting to register
116+
/// the device with the OAuth 2.0 authorization server.
116117
#[error(transparent)]
117-
Oidc(#[from] crate::authentication::oidc::OidcError),
118+
Oauth(#[from] crate::authentication::oidc::OidcError),
118119

119120
/// The OAuth 2.0 server doesn't support the device authorization grant.
120121
#[error("OAuth 2.0 server doesn't support the device authorization grant")]
@@ -126,23 +127,23 @@ pub enum DeviceAuhorizationOidcError {
126127
AuthenticationIssuer(HttpError),
127128

128129
/// An error happened while we attempted to request a device authorization
129-
/// from the OIDC provider.
130+
/// from the Oauth 2.0 authorization server.
130131
#[error(transparent)]
131132
DeviceAuthorization(#[from] BasicRequestTokenError<HttpClientError<reqwest::Error>>),
132133

133134
/// An error happened while waiting for the access token to be issued and
134-
/// sent to us by the OIDC provider.
135+
/// sent to us by the Oauth 2.0 authorization server.
135136
#[error(transparent)]
136137
RequestToken(
137138
#[from] RequestTokenError<HttpClientError<reqwest::Error>, DeviceCodeErrorResponse>,
138139
),
139140
}
140141

141-
impl DeviceAuhorizationOidcError {
142-
/// If the [`DeviceAuhorizationOidcError`] is of the
142+
impl DeviceAuthorizationOauthError {
143+
/// If the [`DeviceAuthorizationOauthError`] is of the
143144
/// [`DeviceCodeErrorResponseType`] error variant, return it.
144145
pub fn as_request_token_error(&self) -> Option<&DeviceCodeErrorResponseType> {
145-
let error = as_variant!(self, DeviceAuhorizationOidcError::RequestToken)?;
146+
let error = as_variant!(self, DeviceAuthorizationOauthError::RequestToken)?;
146147
let request_token_error = as_variant!(error, RequestTokenError::ServerResponse)?;
147148

148149
Some(request_token_error.error())

crates/matrix-sdk/src/authentication/qrcode/oidc_client.rs renamed to crates/matrix-sdk/src/authentication/qrcode/oauth_client.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use oauth2::{
2626
};
2727
use vodozemac::Curve25519PublicKey;
2828

29-
use super::DeviceAuhorizationOidcError;
29+
use super::DeviceAuthorizationOauthError;
3030
use crate::{authentication::oidc::OidcSessionTokens, http_client::HttpClient};
3131

3232
/// Oauth 2.0 Basic client.
@@ -38,20 +38,21 @@ type OauthClientInner<
3838
HasTokenUrl = EndpointSet,
3939
> = BasicClient<HasAuthUrl, HasDeviceAuthUrl, HasIntrospectionUrl, HasRevocationUrl, HasTokenUrl>;
4040

41-
/// An OIDC specific HTTP client.
41+
/// An OAuth 2.0 specific HTTP client.
4242
///
43-
/// This is used to communicate with the OIDC provider exclusively.
44-
pub(super) struct OidcClient {
43+
/// This is used to communicate with the OAuth 2.0 authorization server
44+
/// exclusively.
45+
pub(super) struct OauthClient {
4546
inner: OauthClientInner,
4647
http_client: HttpClient,
4748
}
4849

49-
impl OidcClient {
50+
impl OauthClient {
5051
pub(super) fn new(
5152
client_id: String,
5253
server_metadata: &VerifiedProviderMetadata,
5354
http_client: HttpClient,
54-
) -> Result<Self, DeviceAuhorizationOidcError> {
55+
) -> Result<Self, DeviceAuthorizationOauthError> {
5556
let client_id = ClientId::new(client_id);
5657

5758
let token_endpoint = TokenUrl::from_url(server_metadata.token_endpoint().clone());
@@ -63,19 +64,19 @@ impl OidcClient {
6364
.device_authorization_endpoint
6465
.clone()
6566
.map(DeviceAuthorizationUrl::from_url)
66-
.ok_or(DeviceAuhorizationOidcError::NoDeviceAuthorizationEndpoint)?;
67+
.ok_or(DeviceAuthorizationOauthError::NoDeviceAuthorizationEndpoint)?;
6768

6869
let oauth2_client = BasicClient::new(client_id)
6970
.set_token_uri(token_endpoint)
7071
.set_device_authorization_url(device_authorization_endpoint);
7172

72-
Ok(OidcClient { inner: oauth2_client, http_client })
73+
Ok(Self { inner: oauth2_client, http_client })
7374
}
7475

7576
pub(super) async fn request_device_authorization(
7677
&self,
7778
device_id: Curve25519PublicKey,
78-
) -> Result<StandardDeviceAuthorizationResponse, DeviceAuhorizationOidcError> {
79+
) -> Result<StandardDeviceAuthorizationResponse, DeviceAuthorizationOauthError> {
7980
let scopes = [
8081
ScopeToken::MatrixApi(MatrixApiScopeToken::Full),
8182
ScopeToken::try_with_matrix_device(device_id.to_base64()).expect(
@@ -99,7 +100,7 @@ impl OidcClient {
99100
pub(super) async fn wait_for_tokens(
100101
&self,
101102
details: &StandardDeviceAuthorizationResponse,
102-
) -> Result<OidcSessionTokens, DeviceAuhorizationOidcError> {
103+
) -> Result<OidcSessionTokens, DeviceAuthorizationOauthError> {
103104
let response = self
104105
.inner
105106
.exchange_device_access_token(details)

0 commit comments

Comments
 (0)