From 8daf72a4b0c2f711095b63b91d7e7a93d27881f0 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 24 Apr 2020 15:54:02 +0200 Subject: [PATCH] Use correct URL for SSO connection (#1178) --- CHANGES.md | 1 + .../vector/matrix/android/api/auth/Constants.kt | 8 ++++++++ .../riotx/features/login/LoginWebFragment.kt | 17 +++++++++++++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 550d013ba3..1c35e70cd8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -43,6 +43,7 @@ Bugfix 🐛: - RiotX now uses as many threads as it needs to do work and send messages (#1221) - Fix issue with media path (#1227) - Add user to direct chat by user id (#1065) + - Use correct URL for SSO connection (#1178) Translations 🗣: - diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/Constants.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/Constants.kt index 27569bd90e..af6e2277f4 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/Constants.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/Constants.kt @@ -27,3 +27,11 @@ const val LOGIN_FALLBACK_PATH = "/_matrix/static/client/login/" * Not documented */ const val REGISTER_FALLBACK_PATH = "/_matrix/static/client/register/" + +/** + * Path to use when the client want to connect using SSO + * Ref: https://matrix.org/docs/spec/client_server/latest#sso-client-login + */ +const val SSO_FALLBACK_PATH = "/_matrix/client/r0/login/sso/redirect" + +const val SSO_REDIRECT_URL_PARAM = "redirectUrl" diff --git a/vector/src/main/java/im/vector/riotx/features/login/LoginWebFragment.kt b/vector/src/main/java/im/vector/riotx/features/login/LoginWebFragment.kt index 84bac99e11..f9b0b98f29 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/LoginWebFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/LoginWebFragment.kt @@ -33,9 +33,12 @@ import androidx.appcompat.app.AlertDialog import com.airbnb.mvrx.activityViewModel import im.vector.matrix.android.api.auth.LOGIN_FALLBACK_PATH import im.vector.matrix.android.api.auth.REGISTER_FALLBACK_PATH +import im.vector.matrix.android.api.auth.SSO_FALLBACK_PATH +import im.vector.matrix.android.api.auth.SSO_REDIRECT_URL_PARAM import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.internal.di.MoshiProvider import im.vector.riotx.R +import im.vector.riotx.core.extensions.appendParamToUrl import im.vector.riotx.core.utils.AssetReader import im.vector.riotx.features.signout.soft.SoftLogoutAction import im.vector.riotx.features.signout.soft.SoftLogoutViewModel @@ -125,10 +128,20 @@ class LoginWebFragment @Inject constructor( val url = buildString { append(state.homeServerUrl?.trim { it == '/' }) if (state.signMode == SignMode.SignIn) { - append(LOGIN_FALLBACK_PATH) + if (state.loginMode == LoginMode.Sso) { + append(SSO_FALLBACK_PATH) + // We do not want to deal with the result, so let the fallback login page to handle it for us + appendParamToUrl(SSO_REDIRECT_URL_PARAM, + buildString { + append(state.homeServerUrl?.trim { it == '/' }) + append(LOGIN_FALLBACK_PATH) + }) + } else { + append(LOGIN_FALLBACK_PATH) + } state.deviceId?.takeIf { it.isNotBlank() }?.let { // But https://github.com/matrix-org/synapse/issues/5755 - append("?device_id=$it") + appendParamToUrl("device_id", it) } } else { // MODE_REGISTER