-
Notifications
You must be signed in to change notification settings - Fork 187
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
Sign in with QR code #2793
Sign in with QR code #2793
Changes from all commits
855647f
cb0287a
188e5e1
8af1d52
ad608bb
6f36885
2a30842
253ce12
c9a2e29
c83e6c5
92ea84c
0542be7
a3ba41c
4803864
8f35a7b
a580355
2fc6499
f4b51f9
d6ef9be
5791d32
7b2c4ad
dc435f8
18a8fd8
def8af2
f3b2aa8
14775d5
bf87cfe
1ec15c0
57e7379
e12c19e
6bd9135
f01de85
f4a24cc
261aef6
e8acd32
4141f7a
b38ec55
3b56690
338f819
fe2e2f3
a503634
c70a890
fdbcd04
ac1e464
5d474e2
1356778
91cdb8c
14b21dd
43276e3
c50ec27
f4e8f3b
3336a3b
32e1609
53f5f09
bfd27ed
13c5007
b81556f
fdc1f8f
9f615c4
0688064
6ff42bc
13c97ca
a2ac07a
6b5e558
6375be4
eab9676
7fad1a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
*/ | ||
plugins { | ||
id("io.element.android-library") | ||
id("kotlin-parcelize") | ||
} | ||
|
||
android { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) 2024 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.element.android.features.login.impl.di | ||
|
||
import com.squareup.anvil.annotations.ContributesTo | ||
import io.element.android.features.login.impl.qrcode.QrCodeLoginManager | ||
|
||
@ContributesTo(QrCodeLoginScope::class) | ||
interface QrCodeLoginBindings { | ||
fun qrCodeLoginManager(): QrCodeLoginManager | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (c) 2024 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.element.android.features.login.impl.di | ||
|
||
import com.squareup.anvil.annotations.ContributesTo | ||
import com.squareup.anvil.annotations.MergeSubcomponent | ||
import dagger.Subcomponent | ||
import io.element.android.libraries.architecture.NodeFactoriesBindings | ||
import io.element.android.libraries.di.AppScope | ||
import io.element.android.libraries.di.SingleIn | ||
|
||
@SingleIn(QrCodeLoginScope::class) | ||
@MergeSubcomponent(QrCodeLoginScope::class) | ||
interface QrCodeLoginComponent : NodeFactoriesBindings { | ||
@Subcomponent.Builder | ||
interface Builder { | ||
fun build(): QrCodeLoginComponent | ||
} | ||
|
||
@ContributesTo(AppScope::class) | ||
interface ParentBindings { | ||
fun qrCodeLoginComponentBuilder(): Builder | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright (c) 2024 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.element.android.features.login.impl.di | ||
|
||
abstract class QrCodeLoginScope private constructor() | ||
Check warning on line 19 in features/login/impl/src/main/kotlin/io/element/android/features/login/impl/di/QrCodeLoginScope.kt
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) 2024 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.element.android.features.login.impl.qrcode | ||
|
||
import com.squareup.anvil.annotations.ContributesBinding | ||
import io.element.android.features.login.impl.di.QrCodeLoginScope | ||
import io.element.android.libraries.di.SingleIn | ||
import io.element.android.libraries.matrix.api.auth.MatrixAuthenticationService | ||
import io.element.android.libraries.matrix.api.auth.qrlogin.MatrixQrCodeLoginData | ||
import io.element.android.libraries.matrix.api.auth.qrlogin.QrCodeLoginStep | ||
import io.element.android.libraries.matrix.api.auth.qrlogin.QrLoginException | ||
import io.element.android.libraries.matrix.api.core.SessionId | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import javax.inject.Inject | ||
|
||
@SingleIn(QrCodeLoginScope::class) | ||
@ContributesBinding(QrCodeLoginScope::class) | ||
class DefaultQrCodeLoginManager @Inject constructor( | ||
private val authenticationService: MatrixAuthenticationService, | ||
) : QrCodeLoginManager { | ||
private val _currentLoginStep = MutableStateFlow<QrCodeLoginStep>(QrCodeLoginStep.Uninitialized) | ||
override val currentLoginStep: StateFlow<QrCodeLoginStep> = _currentLoginStep | ||
|
||
override suspend fun authenticate(qrCodeLoginData: MatrixQrCodeLoginData): Result<SessionId> { | ||
reset() | ||
|
||
return authenticationService.loginWithQrCode(qrCodeLoginData) { step -> | ||
_currentLoginStep.value = step | ||
}.onFailure { throwable -> | ||
if (throwable is QrLoginException) { | ||
_currentLoginStep.value = QrCodeLoginStep.Failed(throwable) | ||
Check warning on line 46 in features/login/impl/src/main/kotlin/io/element/android/features/login/impl/qrcode/DefaultQrCodeLoginManager.kt
|
||
} | ||
} | ||
} | ||
|
||
override fun reset() { | ||
_currentLoginStep.value = QrCodeLoginStep.Uninitialized | ||
} | ||
} |
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.
Do we really need a separate component and scope for this? This is just to keep the
StateFlow<QrCodeLoginStep>
?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.
The problem here is
QrCodeLoginManager
had to be shared by several components (QrCodeLofingFlowNode
,QrCodeScanPresenter
) and for that I needed a singleton if I'm not mistaken. But having a singleton can be troublesome if you aren't super careful with cleaning up its state once you're done working with it, so I created a new component to hold it that will be created when the QR code flow starts and discarded once it's finished.This should ensure the object is shared but can't be leaked in any way, although it's more complex than I intended it to be.