Skip to content
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

Implement logic for sign in with QR #7369

Merged
merged 101 commits into from
Oct 19, 2022
Merged

Conversation

hughns
Copy link
Member

@hughns hughns commented Oct 13, 2022

This PR is dependent on #7338. Compare

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

This PR has the logic to implement the UI from #7338

Motivation and context

The motivation is as per #7338

Screenshots / GIFs

See #7338

Tests

Testing requires generating a QR code in Element Web and scanning it in Element Android.

To generate a code in Element Web:

  • Go to preview build of Element Web: https://pr9403--matrix-react-sdk.netlify.app/
  • Choose test homeserver: synapse-msc3882.rendezvous.lab.element.dev
  • Register a user
  • Go to Menu -> All settings -> Labs and enable the QR feature

image

  • Then go to Security & Privacy and see the new Sign in with QR section:

image

  • Press Show QR to generate a QR:

image

To scan in Android:

  • Launch app when signed out
  • Enable the QR Code Login feature in Features:

image

- Go back to main screen - Select "I already have an account" - Press EDIT to enter a different homeserver - Enter https://synapse-msc3882.rendezvous.lab.element.dev - Press next - You should then see a new button:

image

- Press Scan QR code and follow instructions

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

Signed-off-by: Hugh Nimmo-Smith hughns@element.io

hughns and others added 30 commits October 13, 2022 15:28
# Conflicts:
#	library/ui-strings/src/main/res/values/strings.xml
#	library/ui-styles/src/main/res/values/stylable_sessions_list_header_view.xml
#	vector-app/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt
#	vector-app/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt
#	vector/src/main/java/im/vector/app/core/di/MavericksViewModelModule.kt
#	vector/src/main/java/im/vector/app/features/VectorFeatures.kt
#	vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt
#	vector/src/main/java/im/vector/app/features/settings/devices/v2/list/SessionsListHeaderView.kt
#	vector/src/main/res/layout/fragment_other_sessions.xml
#	vector/src/main/res/layout/fragment_settings_devices.xml
# Conflicts:
#	library/ui-strings/src/main/res/values/strings.xml
#	library/ui-styles/src/main/res/values/stylable_sessions_list_header_view.xml
#	vector-app/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt
#	vector-app/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt
#	vector/src/main/java/im/vector/app/core/di/MavericksViewModelModule.kt
#	vector/src/main/java/im/vector/app/features/VectorFeatures.kt
#	vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt
#	vector/src/main/java/im/vector/app/features/settings/devices/v2/list/SessionsListHeaderView.kt
#	vector/src/main/res/layout/fragment_other_sessions.xml
#	vector/src/main/res/layout/fragment_settings_devices.xml
@hughns hughns requested review from BillCarsonFr and removed request for ElementBot October 18, 2022 08:11

_viewEvents.post(QrCodeLoginViewEvents.NavigateToStatusScreen)

viewModelScope.launch(Dispatchers.IO) {
Copy link
Member

Choose a reason for hiding this comment

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

I think it's just calling session.coroutineDispatchers.io

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

Nice work.

There is a bit of architecture rework to do on the SDK, but I would not block the PR for that.
The only blocking remark is about the logs: #7369 (comment)

library/ui-strings/src/main/res/values/strings.xml Outdated Show resolved Hide resolved
}
import org.matrix.android.sdk.api.rendezvous.RendezvousFailureReason

class RendezvousError(val description: String, val reason: RendezvousFailureReason) : Exception(description)
Copy link
Member

Choose a reason for hiding this comment

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

You could extend Failure.FeatureFailure() instead.

Suggested change
class RendezvousError(val description: String, val reason: RendezvousFailureReason) : Exception(description)
class RendezvousError(val description: String, val reason: RendezvousFailureReason) : Failure.FeatureFailure()


val transport = SimpleHttpRendezvousTransport(parsed.rendezvous.transport.uri)

return Rendezvous(
Copy link
Member

Choose a reason for hiding this comment

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

You can return an instance of RendezvousImpl here.

/**
* Implementation of the Simple HTTP transport MSC3886: https://github.com/matrix-org/matrix-spec-proposals/pull/3886
*/
class SimpleHttpRendezvousTransport(rendezvousUri: String?) : RendezvousTransport {
Copy link
Member

Choose a reason for hiding this comment

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

internal.

QrCodeLoginErrorType.DEVICE_IS_NOT_SUPPORTED -> getString(R.string.qr_code_login_header_failed_device_is_not_supported_description)
QrCodeLoginErrorType.TIMEOUT -> getString(R.string.qr_code_login_header_failed_timeout_description)
QrCodeLoginErrorType.REQUEST_WAS_DENIED -> getString(R.string.qr_code_login_header_failed_denied_description)
private fun getErrorDescription(reason: RendezvousFailureReason): String {
Copy link
Member

Choose a reason for hiding this comment

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

I would move this method to DefaultErrorFormatter, and errorType could be a Throwable.

hughns and others added 8 commits October 18, 2022 12:07
Co-authored-by: Benoit Marty <benoitm@matrix.org>
…ndezvous/RendezvousChannel.kt

Co-authored-by: Benoit Marty <benoitm@matrix.org>
…ndezvous/channels/ECDHRendezvousChannel.kt

Co-authored-by: Benoit Marty <benoitm@matrix.org>
…ndezvous/RendezvousChannel.kt

Co-authored-by: Benoit Marty <benoitm@matrix.org>
@hughns
Copy link
Member Author

hughns commented Oct 18, 2022

Nice work.

There is a bit of architecture rework to do on the SDK, but I would not block the PR for that. The only blocking remark is about the logs: #7369 (comment)

Thank you. Blocker should now be resolved.

Re: architecture - I agree this needs work and my plan is to do this when we add in the next round of capabilities about signing in another device from the settings screen in Android.

@hughns hughns requested a review from bmarty October 18, 2022 11:33
@sonarcloud
Copy link

sonarcloud bot commented Oct 19, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@hughns hughns requested a review from bmarty October 19, 2022 09:56
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

LGTM, with the reserve of the architecture update in the future. Thanks!

@Johennes Johennes merged commit 451f5f8 into develop Oct 19, 2022
@Johennes Johennes deleted the feature/hughns/qr_code_login branch October 19, 2022 15:10
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.

6 participants