-
Notifications
You must be signed in to change notification settings - Fork 767
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
QR Code Login UI #7338
QR Code Login UI #7338
Changes from 37 commits
06c0d61
6fbdd87
4fdb4e8
9859dab
5f6c8ee
5dfaa25
9b7f6c9
945fa0a
a66b183
a00afa7
1932eda
04fb316
2527cab
2b452d6
236b303
ad208a0
aacf2ba
5566300
f272e56
d8ea9c8
87956e9
1235db7
4b14ee4
1e1affb
6e58f2f
fb2776d
e554b43
90fa5d5
e305478
489dfd7
9429a4f
343cf74
4c7c861
5953346
b04ad49
e83bdc3
6c10a9b
8547fee
91bb86d
d3a24fe
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
Implement QR Code Login UI |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<declare-styleable name="QrCodeLoginInstructionsView"> | ||
<attr name="qrCodeLoginInstruction1" format="string" /> | ||
<attr name="qrCodeLoginInstruction2" format="string" /> | ||
<attr name="qrCodeLoginInstruction3" format="string" /> | ||
<attr name="qrCodeLoginInstruction4" format="string" /> | ||
</declare-styleable> | ||
|
||
</resources> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<declare-styleable name="QrCodeLoginHeaderView"> | ||
<attr name="qrCodeLoginHeaderTitle" format="string" /> | ||
<attr name="qrCodeLoginHeaderDescription" format="string" /> | ||
<attr name="qrCodeLoginHeaderImageResource" format="reference" /> | ||
<attr name="qrCodeLoginHeaderImageBackgroundTint" format="color" /> | ||
</declare-styleable> | ||
|
||
</resources> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ import org.matrix.android.sdk.api.auth.data.LoginFlowTypes | |
import org.matrix.android.sdk.api.auth.login.LoginWizard | ||
import org.matrix.android.sdk.api.auth.registration.RegistrationWizard | ||
import org.matrix.android.sdk.api.auth.wellknown.WellknownResult | ||
import org.matrix.android.sdk.api.extensions.orFalse | ||
import org.matrix.android.sdk.api.failure.Failure | ||
import org.matrix.android.sdk.api.failure.MatrixIdFailure | ||
import org.matrix.android.sdk.api.session.Session | ||
|
@@ -43,6 +44,7 @@ import org.matrix.android.sdk.internal.auth.login.QrLoginTokenTask | |
import org.matrix.android.sdk.internal.auth.registration.DefaultRegistrationWizard | ||
import org.matrix.android.sdk.internal.auth.version.Versions | ||
import org.matrix.android.sdk.internal.auth.version.doesServerSupportLogoutDevices | ||
import org.matrix.android.sdk.internal.auth.version.doesServerSupportQrCodeLogin | ||
import org.matrix.android.sdk.internal.auth.version.isLoginAndRegistrationSupportedBySdk | ||
import org.matrix.android.sdk.internal.auth.version.isSupportedBySdk | ||
import org.matrix.android.sdk.internal.di.Unauthenticated | ||
|
@@ -406,6 +408,20 @@ internal class DefaultAuthenticationService @Inject constructor( | |
) | ||
} | ||
|
||
override suspend fun isQrLoginSupported(homeServerConnectionConfig: HomeServerConnectionConfig): Boolean { | ||
val authAPI = buildAuthAPI(homeServerConnectionConfig) | ||
val versions = runCatching { | ||
executeRequest(null) { | ||
authAPI.versions() | ||
} | ||
} | ||
return if (versions.isSuccess) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there is a network error the client will consider that the feature is not supported (which is maybe acceptable here). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is ok to silently hide it on network problems. |
||
versions.getOrNull()?.doesServerSupportQrCodeLogin().orFalse() | ||
} else { | ||
false | ||
} | ||
} | ||
|
||
override suspend fun loginUsingQrLoginToken( | ||
homeServerConnectionConfig: HomeServerConnectionConfig, | ||
loginToken: String, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2022 The Matrix.org Foundation C.I.C. | ||
* | ||
* 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 org.matrix.android.sdk.internal.database.migration | ||
|
||
import io.realm.DynamicRealm | ||
import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEntityFields | ||
import org.matrix.android.sdk.internal.extensions.forceRefreshOfHomeServerCapabilities | ||
import org.matrix.android.sdk.internal.util.database.RealmMigrator | ||
|
||
internal class MigrateSessionTo039(realm: DynamicRealm) : RealmMigrator(realm, 39) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This migration is not called in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh nice catch. Thank you. |
||
|
||
override fun doMigrate(realm: DynamicRealm) { | ||
realm.schema.get("HomeServerCapabilitiesEntity") | ||
?.addField(HomeServerCapabilitiesEntityFields.CAN_LOGIN_WITH_QR_CODE, Boolean::class.java) | ||
?.transform { obj -> | ||
obj.set(HomeServerCapabilitiesEntityFields.CAN_LOGIN_WITH_QR_CODE, false) | ||
} | ||
?.forceRefreshOfHomeServerCapabilities() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ import org.matrix.android.sdk.api.extensions.orTrue | |
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities | ||
import org.matrix.android.sdk.internal.auth.version.Versions | ||
import org.matrix.android.sdk.internal.auth.version.doesServerSupportLogoutDevices | ||
import org.matrix.android.sdk.internal.auth.version.doesServerSupportQrCodeLogin | ||
import org.matrix.android.sdk.internal.auth.version.doesServerSupportThreads | ||
import org.matrix.android.sdk.internal.auth.version.isLoginAndRegistrationSupportedBySdk | ||
import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEntity | ||
|
@@ -132,8 +133,6 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor( | |
homeServerCapabilitiesEntity.roomVersionsJson = capabilities?.roomVersions?.let { | ||
MoshiProvider.providesMoshi().adapter(RoomVersions::class.java).toJson(it) | ||
} | ||
homeServerCapabilitiesEntity.canUseThreading = /* capabilities?.threads?.enabled.orFalse() || */ | ||
getVersionResult?.doesServerSupportThreads().orFalse() | ||
} | ||
|
||
if (getMediaConfigResult != null) { | ||
|
@@ -144,6 +143,9 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor( | |
if (getVersionResult != null) { | ||
homeServerCapabilitiesEntity.lastVersionIdentityServerSupported = getVersionResult.isLoginAndRegistrationSupportedBySdk() | ||
homeServerCapabilitiesEntity.canControlLogoutDevices = getVersionResult.doesServerSupportLogoutDevices() | ||
homeServerCapabilitiesEntity.canUseThreading = /* capabilities?.threads?.enabled.orFalse() || */ | ||
getVersionResult.doesServerSupportThreads().orFalse() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, done. |
||
homeServerCapabilitiesEntity.canLoginWithQrCode = getVersionResult.doesServerSupportQrCodeLogin().orFalse() | ||
} | ||
|
||
if (getWellknownResult != null && getWellknownResult is WellknownResult.Prompt) { | ||
|
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.
Maybe to avoid translation mistake, change to
and inject at runtime the wording of the button.
Which is the key
qr_code_login_show_qr_code_button
IIUC which contains the text...Show QR code in this device
.