Skip to content

Conversation

Johennes
Copy link
Contributor

@Johennes Johennes commented Sep 24, 2025

This pull request is a step towards adding the complementary QR login variant where the new device is the one generating the QR code and the existing device is the one scanning the QR code. Only the establishment of the secure channel and the completion of the login by the new device are covered in this change.

Naming feels really hard here. The new identifiers are all prefixed Generated.... We could prefix the existing identifiers Scanned... but I haven't bothered doing this yet in case someone has better ideas.

  • Public API changes documented in changelogs (optional)

Copy link

codecov bot commented Sep 24, 2025

Codecov Report

❌ Patch coverage is 90.02849% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.43%. Comparing base (ef440ee) to head (5e38519).
⚠️ Report is 34 commits behind head on main.

Files with missing lines Patch % Lines
...atrix-sdk/src/authentication/oauth/qrcode/login.rs 89.75% 19 Missing and 15 partials ⚠️
.../src/authentication/oauth/qrcode/secure_channel.rs 90.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #5711    +/-   ##
========================================
  Coverage   88.43%   88.43%            
========================================
  Files         360      360            
  Lines       99770   100114   +344     
  Branches    99770   100114   +344     
========================================
+ Hits        88232    88539   +307     
- Misses       7402     7423    +21     
- Partials     4136     4152    +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

codspeed-hq bot commented Sep 24, 2025

CodSpeed Performance Report

Merging #5711 will not alter performance

Comparing Johennes:johannes/qr-login-1 (5e38519) with main (588d604)

Summary

✅ 50 untouched

@Johennes Johennes force-pushed the johannes/qr-login-1 branch 6 times, most recently from 1bf637a to 4ee68ef Compare September 25, 2025 12:29
@Johennes Johennes marked this pull request as ready for review September 25, 2025 12:49
@Johennes Johennes requested a review from a team as a code owner September 25, 2025 12:49
@Johennes Johennes requested review from poljar and removed request for a team September 25, 2025 12:49
@poljar
Copy link
Contributor

poljar commented Oct 3, 2025

Could we split this PR up a bit?

  • Commit 1 is an easy code move.
  • Commit 2 is a breaking change lacking a changelog entry
  • Commit 3 is a breaking change lacking a changelog entry and a motivation in the commit message.
  • Commit 4 is the meat of the PR.

Ideally we would merge 1-3 as separate PRs and then discuss 4 in a more detailed manner.

@Johennes
Copy link
Contributor Author

Johennes commented Oct 3, 2025

Ok, sure. I'll put this one back into draft until the others have landed.

Signed-off-by: Johannes Marbach <[email protected]>
@Johennes Johennes force-pushed the johannes/qr-login-1 branch from 4ee68ef to 6cb59d0 Compare October 8, 2025 12:37
@Johennes Johennes marked this pull request as ready for review October 8, 2025 18:41
@Johennes
Copy link
Contributor Author

Johennes commented Oct 8, 2025

This is now reduced to the formerly last commit with the previous ones having landed on main.

Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this looks mostly good though needs a bit more work.

I'd like to change the public API a bit so we don't increase the number of methods.

The biggest problem is that the login is broken if the client chooses to use a default homeserver for the rendezvous.

Comment on lines 473 to 500
let http_client = self.client.inner.http_client.clone();

let secure_channel = SecureChannel::login(http_client, &self.client.homeserver()).await?;

assert_eq!(QrCodeModeData::Login, secure_channel.qr_code_data().mode_data);

let qr_code_data = secure_channel.qr_code_data().clone();

trace!("Generated QR code.");
self.state.set(LoginProgress::EstablishingSecureChannel(GeneratedQrProgress::QrReady(
qr_code_data,
)));

let (tx, rx) = tokio::sync::oneshot::channel();

let channel = secure_channel.connect().await?;

trace!("Waiting for checkcode.");
self.state.set(LoginProgress::EstablishingSecureChannel(GeneratedQrProgress::QrScanned(
CheckCodeSender::new(tx),
)));

let check_code = rx.await.map_err(|_| SecureChannelError::CannotReceiveCheckCode)?;

trace!("Received check code.");

channel.confirm(check_code)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function needs some more comments to describe what each step is achieving similar to how the LoginWithQrCode future does. Bonus points if you note the step numbers from the MSC in each block, something I failed to do as well.

Otherwise this it's pretty hard to double check which code blocks relate to which step in the process.

Comment on lines +82 to +84
- Add `OAuth::login_with_generated_qr_code` for generating a QR code on a new device
and logging it in with the help of an existing device scanning the code.
([#5711](https://github.com/matrix-org/matrix-rust-sdk/pull/5711))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not the only change, some error types got new variants as well. Extending the error types is a breaking change.

let message = channel.receive_json().await?;

match message {
QrAuthMessage::LoginProtocols { protocols, .. } => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A step is missing here which becomes obvious once you look at the rest of the fields the LoginProtocols message contains.

image

You'll need to modify the homeserver we're going to use and re-resolve well-known.

A test that swapping out the homeserver works would be nice as well.

I think that this is important if the client picks up a default homeserver for the rendezvous but actually wants to log in into the homeserver the existing device is using.

Please add comments to this method as well, describing what each code block does and at which step in the sequence diagram we're at.

Reuse SecureChannel::login in SecureChannel::new

Signed-off-by: Johannes Marbach <[email protected]>
Remove assert

Signed-off-by: Johannes Marbach <[email protected]>
Remove misleading comment

Signed-off-by: Johannes Marbach <[email protected]>
Clarify that the check code has to be supplied in digits representation

Signed-off-by: Johannes Marbach <[email protected]>
Use builder to avoid introducing another method and add example in doc comment

Signed-off-by: Johannes Marbach <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants