-
Notifications
You must be signed in to change notification settings - Fork 332
feat(oauth): add flow for logging in using a QR code generated on the logged out device #5711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is 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. |
CodSpeed Performance ReportMerging #5711 will not alter performanceComparing Summary
|
1bf637a
to
4ee68ef
Compare
Could we split this PR up a bit?
Ideally we would merge 1-3 as separate PRs and then discuss 4 in a more detailed manner. |
Ok, sure. I'll put this one back into draft until the others have landed. |
Signed-off-by: Johannes Marbach <[email protected]>
4ee68ef
to
6cb59d0
Compare
This is now reduced to the formerly last commit with the previous ones having landed on |
There was a problem hiding this 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.
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) | ||
} |
There was a problem hiding this comment.
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.
- 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)) |
There was a problem hiding this comment.
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, .. } => { |
There was a problem hiding this comment.
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.

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]>
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 identifiersScanned...
but I haven't bothered doing this yet in case someone has better ideas.