Skip to content

Add support for login link #4752

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

Merged
merged 13 commits into from
May 21, 2025
Merged

Add support for login link #4752

merged 13 commits into from
May 21, 2025

Conversation

bmarty
Copy link
Member

@bmarty bmarty commented May 20, 2025

Content

Add support for login link

Motivation and context

Let the application be opened when the user opens link like

https://mobile.element.io/element?account_provider=example.org&login_hint=mxid:@alice:example.org

Closes #4705

Screenshots / GIFs

SignInDeepLink.mp4

Tests

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

  • Changes have been tested on an Android device or Android emulator with API 24
  • UI change has been tested on both light and dark themes
  • Accessibility has been taken into account. See https://github.com/element-hq/element-x-android/blob/develop/CONTRIBUTING.md#accessibility
  • Pull request is based on the develop branch
  • Pull request title will be used in the release note, it clearly define what will change for the user
  • Pull request includes screenshots or videos if containing UI changes
  • You've made a self review of your PR

@bmarty bmarty added PR-Feature For a new feature Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. labels May 20, 2025
@github-actions github-actions bot removed the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label May 20, 2025
Copy link
Contributor

github-actions bot commented May 20, 2025

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/baetwX

Copy link

codecov bot commented May 20, 2025

Codecov Report

Attention: Patch coverage is 81.33333% with 42 lines in your changes missing coverage. Please review.

Project coverage is 80.32%. Comparing base (e50dfa9) to head (59a508f).
Report is 9 commits behind head on develop.

Files with missing lines Patch % Lines
...android/features/login/impl/login/LoginModeView.kt 31.57% 21 Missing and 5 partials ⚠️
...roid/features/login/impl/DefaultLoginEntryPoint.kt 0.00% 4 Missing ⚠️
...ment/android/features/login/api/LoginEntryPoint.kt 0.00% 3 Missing ⚠️
.../element/android/features/login/api/LoginParams.kt 60.00% 2 Missing ⚠️
...t/android/features/login/impl/login/LoginHelper.kt 96.22% 1 Missing and 1 partial ⚠️
.../features/login/impl/DefaultLoginIntentResolver.kt 88.88% 0 Missing and 1 partial ⚠️
...firmaccountprovider/ConfirmAccountProviderState.kt 50.00% 0 Missing and 1 partial ⚠️
...nfirmaccountprovider/ConfirmAccountProviderView.kt 90.00% 1 Missing ⚠️
...s/login/impl/screens/onboarding/OnBoardingState.kt 88.88% 0 Missing and 1 partial ⚠️
...atrix/impl/auth/RustMatrixAuthenticationService.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4752      +/-   ##
===========================================
+ Coverage    80.31%   80.32%   +0.01%     
===========================================
  Files         2127     2135       +8     
  Lines        56330    56441     +111     
  Branches      7057     7069      +12     
===========================================
+ Hits         45241    45336      +95     
- Misses        8672     8688      +16     
  Partials      2417     2417              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bmarty bmarty marked this pull request as ready for review May 20, 2025 16:02
@bmarty bmarty requested a review from a team as a code owner May 20, 2025 16:02
@bmarty bmarty requested review from jmartinesp and removed request for a team May 20, 2025 16:02
@jmartinesp
Copy link
Member

While testing it, I got this error (and a dialog for it), then the log in progressed to the 'confirm your identity' screen soon after:

E  elementx: Failed to login with OIDC
   org.matrix.rustcomponents.sdk.OidcException$CallbackUrlInvalid: The supplied callback URL used to complete OIDC is invalid.
   	at org.matrix.rustcomponents.sdk.FfiConverterTypeOidcError.read(matrix_sdk_ffi.kt:35595)
   	at org.matrix.rustcomponents.sdk.FfiConverterTypeOidcError.read(matrix_sdk_ffi.kt:35589)
   	at org.matrix.rustcomponents.sdk.FfiConverter$DefaultImpls.liftFromRustBuffer(matrix_sdk_ffi.kt:237)
   	at org.matrix.rustcomponents.sdk.FfiConverterRustBuffer$DefaultImpls.liftFromRustBuffer(matrix_sdk_ffi.kt:249)
   	at org.matrix.rustcomponents.sdk.FfiConverterTypeOidcError.liftFromRustBuffer(matrix_sdk_ffi.kt:35589)
   	at org.matrix.rustcomponents.sdk.FfiConverterTypeOidcError.liftFromRustBuffer(matrix_sdk_ffi.kt:35589)
   	at org.matrix.rustcomponents.sdk.FfiConverterRustBuffer$DefaultImpls.lift(matrix_sdk_ffi.kt:250)
   	at org.matrix.rustcomponents.sdk.FfiConverterTypeOidcError.lift(matrix_sdk_ffi.kt:35589)
   	at org.matrix.rustcomponents.sdk.FfiConverterTypeOidcError.lift(matrix_sdk_ffi.kt:35589)
   	at org.matrix.rustcomponents.sdk.OidcException$ErrorHandler.lift(matrix_sdk_ffi.kt:35585)
   	at org.matrix.rustcomponents.sdk.OidcException$ErrorHandler.lift(matrix_sdk_ffi.kt:35584)
   	at org.matrix.rustcomponents.sdk.Matrix_sdk_ffiKt.uniffiCheckCallStatus(matrix_sdk_ffi.kt:313)
   	at org.matrix.rustcomponents.sdk.Matrix_sdk_ffiKt.access$uniffiCheckCallStatus(matrix_sdk_ffi.kt:1)
   	at org.matrix.rustcomponents.sdk.Matrix_sdk_ffiKt.uniffiRustCallAsync(matrix_sdk_ffi.kt:46823)
   	at org.matrix.rustcomponents.sdk.Client.loginWithOidcCallback$suspendImpl(matrix_sdk_ffi.kt:7843)
   	at org.matrix.rustcomponents.sdk.Client.loginWithOidcCallback(Unknown Source:0)
   	at io.element.android.libraries.matrix.impl.auth.RustMatrixAuthenticationService$loginWithOidc$2.invokeSuspend(RustMatrixAuthenticationService.kt:234)
   	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
   	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
   	at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:124)
   	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:89)
   	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:586)
   	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:820)
   	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:717)
   	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:704)
    | RustMatrixAuthenticationService.kt:254

Copy link
Member

@jmartinesp jmartinesp left a comment

Choose a reason for hiding this comment

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

A few comments. I'd approve the PR, but it seems risky with the issue I found above.

Copy link
Member

Choose a reason for hiding this comment

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

Was this accidentally added? I think you mentioned this was generated by the IDE before.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes :/

Does your IDE removes the added section? I do not know how to get ride of this change that I always have to not commit.

I'll revert the change for this PR.

switchToNotLoggedInFlow(params)
} else {
// Just ignore the login link if we already have a session
Timber.w("Login link ignored, we already have a session")
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 we should try to give some feedback to the user in this case, although I guess there's no easy way to display a dialog/toast from here 🫤 .

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe. Showing a dialog is not in the flow. If one day we have multi account, we could be able to handle the link in all cases.

image

import kotlinx.parcelize.Parcelize

@Parcelize
data class LoginParams(
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add some docs for what these are used for?

get() = loginFlowAction.value

@Composable
fun Start() {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this could behave like collectAsState, directly returning the loginFlowAction current value so you don't have to expose it separately?

private val defaultLoginUserStory: DefaultLoginUserStory,
private val webClientUrlForAuthenticationRetriever: WebClientUrlForAuthenticationRetriever,
) {
private lateinit var loginFlowAction: MutableState<AsyncData<LoginFlow>>
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 you can initialise the state here instead of in the Start composable and it'll work the same, without the lateinit added complexity.

import kotlinx.coroutines.launch
import javax.inject.Inject

class LoginHelper @Inject constructor(
Copy link
Member

Choose a reason for hiding this comment

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

Some docs for this class would be quite helpful.

import io.element.android.libraries.ui.strings.CommonStrings

@Composable
fun LoginFlowView(
Copy link
Member

Choose a reason for hiding this comment

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

I know it's named like this because it's based on the LoginFlow value, but it kind of conflicts with the FlowNode components we have, so it took me a while to understand this is not managing a flow of screen/components. Maybe we should try thinking about a better name...

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I do not like this name either. Do you have a better idea? I can't think of any...

Copy link
Member

Choose a reason for hiding this comment

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

Maybe rename LoginFlow to AccountSetup so you have:

sealed interface AccountSetup {
    data object PasswordLogin : AccountSetup
    data class OidcLogin(val oidcDetails: OidcDetails) : AccountSetup
    data class AccountCreation(val url: String) : AccountSetup
}

And this can now be AccountSetupView. I can't come up with a better name, it's tricky one 🫤 .

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I will go for LoginMode and extract this interface.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, although AccountCreation is technically not a login mode 🤓 .

bmarty added 5 commits May 21, 2025 10:20
Move LoginFlow to package io.element.android.features.login.impl.login
Rename some implementation of LoginMode
Rename LoginFlowView to LoginModeView
Using launchMode singleTask to avoid multiple instances of the Activity when the app is already open. This is important for incoming share and for opening the application from a mobile.element.io link.

Closes #4074
@bmarty
Copy link
Member Author

bmarty commented May 21, 2025

While testing it, I got this error (and a dialog for it)

Thanks for reporting. It was due to multiple instance of the application to run in parallel. It was possible when opening a mobile.element.io link from an application that do not create a separate task like Google Keep Note. Google Chrome create a separate task.

I fixed that in 59a508f

Note that this also has the effect to close #4074 and incoming share still work as expected.

Copy link

@ElementBot
Copy link
Collaborator

Warnings
⚠️

app/src/main/AndroidManifest.xml#L112 - This intent filter has the format of an Android App Link but is missing the autoVerify attribute; add android:autoVerify="true" to ensure your domain will be validated and enable App Link-related Lint warnings. If you do not want clicked URLs to bring the user to your app, remove the android.intent.category.BROWSABLE category, or set android:autoVerify="false" to make it clear this is not intended to be an Android App Link.

Generated by 🚫 dangerJS against 59a508f

Copy link
Member

@jmartinesp jmartinesp left a comment

Choose a reason for hiding this comment

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

Thanks for the changes, now that everything works we can approve it!

@bmarty bmarty merged commit 5a2aeac into develop May 21, 2025
30 of 31 checks passed
@bmarty bmarty deleted the feature/bma/deeplink branch May 21, 2025 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Feature For a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task] Deeplink to specify account provider & user
3 participants