Skip to content

Commit ad39480

Browse files
committed
Add generated QR code login flow
Signed-off-by: Johannes Marbach <[email protected]>
1 parent 9436c76 commit ad39480

File tree

6 files changed

+574
-28
lines changed

6 files changed

+574
-28
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ impl From<qrcode::QRCodeLoginError> for HumanQrLoginError {
105105
| SecureChannelError::RendezvousChannel(_) => HumanQrLoginError::Unknown,
106106
SecureChannelError::SecureChannelMessage { .. }
107107
| SecureChannelError::Ecies(_)
108-
| SecureChannelError::InvalidCheckCode => HumanQrLoginError::ConnectionInsecure,
108+
| SecureChannelError::InvalidCheckCode
109+
| SecureChannelError::CannotReceiveCheckCode => {
110+
HumanQrLoginError::ConnectionInsecure
111+
}
109112
SecureChannelError::InvalidIntent => HumanQrLoginError::OtherDeviceNotSignedIn,
110113
},
111114

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ mod tests;
214214
#[cfg(feature = "e2e-encryption")]
215215
use self::cross_process::{CrossProcessRefreshLockGuard, CrossProcessRefreshManager};
216216
#[cfg(feature = "e2e-encryption")]
217-
use self::qrcode::LoginWithQrCode;
217+
use self::qrcode::{LoginWithGeneratedQrCode, LoginWithQrCode};
218218
pub use self::{
219219
account_management_url::{AccountManagementActionFull, AccountManagementUrlBuilder},
220220
auth_code_builder::{OAuthAuthCodeUrlBuilder, OAuthAuthorizationData},
@@ -459,6 +459,31 @@ impl OAuth {
459459
LoginWithQrCode::new(&self.client, data, registration_data)
460460
}
461461

462+
/// Log in using a generated QR code.
463+
///
464+
/// This method allows you to log in with a QR code, this device
465+
/// needs to display the QR code by calling this method so the existing
466+
/// device can scan it and grant the log in.
467+
///
468+
/// A successful login using this method will automatically mark the device
469+
/// as verified and transfer all end-to-end encryption related secrets, like
470+
/// the private cross-signing keys and the backup key from the existing
471+
/// device to the new device.
472+
///
473+
/// # Arguments
474+
///
475+
/// * `registration_data` - The data to restore or register the client with
476+
/// the server. If this is not provided, an error will occur unless
477+
/// [`OAuth::register_client()`] or [`OAuth::restore_registered_client()`]
478+
/// was called previously.
479+
#[cfg(feature = "e2e-encryption")]
480+
pub fn login_with_generated_qr_code<'a>(
481+
&'a self,
482+
registration_data: Option<&'a ClientRegistrationData>,
483+
) -> LoginWithGeneratedQrCode<'a> {
484+
LoginWithGeneratedQrCode::new(&self.client, registration_data)
485+
}
486+
462487
/// Restore or register the OAuth 2.0 client for the server with the given
463488
/// metadata, with the given optional [`ClientRegistrationData`].
464489
///

0 commit comments

Comments
 (0)