From ea6fde3ed0fd0a04abc36fa94196615b209533ec Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 15 Dec 2020 11:42:53 -0700 Subject: [PATCH 1/4] Make MSC2858 implementation match the unstable policy of the spec See https://github.com/matrix-org/matrix-doc/pull/2858/files#r543567196 --- .../main/java/org/matrix/android/sdk/api/auth/Constants.kt | 1 + .../android/sdk/internal/auth/data/LoginFlowResponse.kt | 2 +- .../main/java/im/vector/app/features/login/LoginViewState.kt | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/Constants.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/Constants.kt index 871c2559f8..7d18aba627 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/Constants.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/Constants.kt @@ -33,5 +33,6 @@ const val REGISTER_FALLBACK_PATH = "/_matrix/static/client/register/" * Ref: https://matrix.org/docs/spec/client_server/latest#sso-client-login */ const val SSO_REDIRECT_PATH = "/_matrix/client/r0/login/sso/redirect" +const val MSC2858_SSO_REDIRECT_PATH = "/_matrix/client/unstable/org.matrix.msc2858/login/sso/redirect" const val SSO_REDIRECT_URL_PARAM = "redirectUrl" diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/data/LoginFlowResponse.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/data/LoginFlowResponse.kt index c333b3524e..2b26115f30 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/data/LoginFlowResponse.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/data/LoginFlowResponse.kt @@ -42,6 +42,6 @@ internal data class LoginFlow( * the client can show a button for each of the supported providers * See MSC #2858 */ - @Json(name = "identity_providers") + @Json(name = "org.matrix.msc2858.identity_providers") val ssoIdentityProvider: List? ) diff --git a/vector/src/main/java/im/vector/app/features/login/LoginViewState.kt b/vector/src/main/java/im/vector/app/features/login/LoginViewState.kt index 383fd4a54e..606bd7dc21 100644 --- a/vector/src/main/java/im/vector/app/features/login/LoginViewState.kt +++ b/vector/src/main/java/im/vector/app/features/login/LoginViewState.kt @@ -72,9 +72,11 @@ data class LoginViewState( fun getSsoUrl(providerId: String?): String { return buildString { append(homeServerUrl?.trim { it == '/' }) - append(SSO_REDIRECT_PATH) if (providerId != null) { + append(MSC2858_SSO_REDIRECT_PATH) append("/$providerId") + } else { + append(SSO_REDIRECT_PATH) } // Set a redirect url we will intercept later appendParamToUrl(SSO_REDIRECT_URL_PARAM, VECTOR_REDIRECT_URL) From 3491774e7b9da2b22269b5738062587b37d28a20 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 15 Dec 2020 11:45:06 -0700 Subject: [PATCH 2/4] Add changelog --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index a2029b9901..f1e1061c49 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,7 +8,7 @@ Improvements 🙌: - Bugfix 🐛: - - + - Fix MSC2858 implementation details (#2540) Translations 🗣: - From c7afcf4ff2504589c01ccce796942eb98e43e73c Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 17 Dec 2020 12:10:55 +0100 Subject: [PATCH 3/4] Fix compilation issue --- .../src/main/java/im/vector/app/features/login/LoginViewState.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/vector/src/main/java/im/vector/app/features/login/LoginViewState.kt b/vector/src/main/java/im/vector/app/features/login/LoginViewState.kt index 606bd7dc21..e444844022 100644 --- a/vector/src/main/java/im/vector/app/features/login/LoginViewState.kt +++ b/vector/src/main/java/im/vector/app/features/login/LoginViewState.kt @@ -23,6 +23,7 @@ import com.airbnb.mvrx.PersistState import com.airbnb.mvrx.Success import com.airbnb.mvrx.Uninitialized import im.vector.app.core.extensions.appendParamToUrl +import org.matrix.android.sdk.api.auth.MSC2858_SSO_REDIRECT_PATH import org.matrix.android.sdk.api.auth.SSO_REDIRECT_PATH import org.matrix.android.sdk.api.auth.SSO_REDIRECT_URL_PARAM From 68cd06f1fb84217d04efcd4885456aedeeda4c9b Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 17 Dec 2020 11:15:19 +0100 Subject: [PATCH 4/4] Improve redirect url, which can be visible to the user: "element://element" -> "element://connect" --- docs/signin.md | 4 ++-- vector/src/main/AndroidManifest.xml | 5 +++-- .../main/java/im/vector/app/features/login/LoginViewState.kt | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/signin.md b/docs/signin.md index 06f715c46b..0a234d2a20 100644 --- a/docs/signin.md +++ b/docs/signin.md @@ -165,7 +165,7 @@ In this case, the user can click on "Sign in with SSO" and the native web browse > https://homeserver.with.sso/_matrix/client/r0/login/sso/redirect?redirectUrl=element%3A%2F%element -The parameter `redirectUrl` is set to `element://element`. +The parameter `redirectUrl` is set to `element://connect`. ChromeCustomTabs are an intermediate way to display a WebPage, between a WebView and using the external browser. More info can be found [here](https://developer.chrome.com/multidevice/android/customtabs) @@ -175,7 +175,7 @@ During the process, user may be asked to validate an email by clicking on a link Once the process is finished, the web page will call the `redirectUrl` with an extra parameter `loginToken` -> element://element?loginToken=MDAxOWxvY2F0aW9uIG1vemlsbGEub3JnCjAwMTNpZGVudGlmaWVy +> element://connect?loginToken=MDAxOWxvY2F0aW9uIG1vemlsbGEub3JnCjAwMTNpZGVudGlmaWVy This navigation is intercepted by Element by the `LoginActivity`, which will then ask the homeserver to convert this `loginToken` to an access token diff --git a/vector/src/main/AndroidManifest.xml b/vector/src/main/AndroidManifest.xml index bf839b807c..4ad51fdea7 100644 --- a/vector/src/main/AndroidManifest.xml +++ b/vector/src/main/AndroidManifest.xml @@ -95,8 +95,9 @@ - - + diff --git a/vector/src/main/java/im/vector/app/features/login/LoginViewState.kt b/vector/src/main/java/im/vector/app/features/login/LoginViewState.kt index e444844022..5254abf1d9 100644 --- a/vector/src/main/java/im/vector/app/features/login/LoginViewState.kt +++ b/vector/src/main/java/im/vector/app/features/login/LoginViewState.kt @@ -90,6 +90,6 @@ data class LoginViewState( companion object { // Note that the domain can be displayed to the user for confirmation that he trusts it. So use a human readable string - private const val VECTOR_REDIRECT_URL = "element://element" + private const val VECTOR_REDIRECT_URL = "element://connect" } }