separating the SSO redirection from the login activities

- adds a dedicated routing activity to proxy the uri to the login selected by the feature flags
This commit is contained in:
Adam Brown 2021-12-03 14:51:20 +00:00
parent 9e367a8535
commit 54c45d3e71
6 changed files with 82 additions and 30 deletions

View file

@ -113,45 +113,35 @@
<activity android:name=".features.home.HomeActivity" />
<!-- exported="true" is required to handle android.intent.action.VIEW for URL redirection-->
<activity
android:name=".features.login.SSORedirectRouterActivity"
android:exported="true"
android:theme="@style/Theme.Vector.Black.Transparent">
<!-- Add intent filter to handle redirection URL after SSO login in external browser -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="connect"
android:scheme="element" />
</intent-filter>
</activity>
<activity
android:name=".features.login.LoginActivity"
android:enabled="@bool/useLoginV1"
android:exported="true"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<!-- Add intent filter to handle redirection URL after SSO login in external browser -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
android:windowSoftInputMode="adjustResize" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="connect"
android:scheme="element" />
</intent-filter>
</activity>
<!-- exported="true" is required to handle android.intent.action.VIEW for URL redirection-->
<activity
android:name=".features.login2.LoginActivity2"
android:enabled="@bool/useLoginV2"
android:exported="true"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<!-- Add intent filter to handle redirection URL after SSO login in external browser -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="connect"
android:scheme="element" />
</intent-filter>
</activity>
android:windowSoftInputMode="adjustResize" />
<!-- Add tools:ignore="Instantiatable" for the error reported only by Buildkite :/ -->
<activity

View file

@ -18,6 +18,7 @@ package im.vector.app.features.login
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.view.View
import android.view.ViewGroup
import androidx.core.view.ViewCompat
@ -363,5 +364,11 @@ open class LoginActivity : VectorBaseActivity<ActivityLoginBinding>(), ToolbarCo
putExtra(EXTRA_CONFIG, loginConfig)
}
}
fun redirectIntent(context: Context, data: Uri?): Intent {
return Intent(context, LoginActivity::class.java).apply {
setData(data)
}
}
}
}

View file

@ -0,0 +1,35 @@
/*
* Copyright (c) 2021 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 im.vector.app.features.login
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.features.navigation.Navigator
import javax.inject.Inject
@AndroidEntryPoint
class SSORedirectRouterActivity : AppCompatActivity() {
@Inject lateinit var navigator: Navigator
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
navigator.loginSSORedirect(this, intent.data)
finish()
}
}

View file

@ -18,6 +18,7 @@ package im.vector.app.features.login2
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.view.View
import android.view.ViewGroup
import androidx.core.view.ViewCompat
@ -40,6 +41,7 @@ import im.vector.app.core.platform.ToolbarConfigurable
import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.databinding.ActivityLoginBinding
import im.vector.app.features.home.HomeActivity
import im.vector.app.features.login.LoginActivity
import im.vector.app.features.login.LoginCaptchaFragmentArgument
import im.vector.app.features.login.LoginConfig
import im.vector.app.features.login.LoginGenericTextInputFormFragmentArgument
@ -396,5 +398,11 @@ open class LoginActivity2 : VectorBaseActivity<ActivityLoginBinding>(), ToolbarC
putExtra(EXTRA_CONFIG, loginConfig)
}
}
fun redirectIntent(context: Context, data: Uri?): Intent {
return Intent(context, LoginActivity2::class.java).apply {
setData(data)
}
}
}
}

View file

@ -19,6 +19,7 @@ package im.vector.app.features.navigation
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.view.View
import android.view.Window
@ -118,6 +119,14 @@ class DefaultNavigator @Inject constructor(
context.startActivity(intent)
}
override fun loginSSORedirect(context: Context, data: Uri?) {
val intent = when (features.loginType()) {
VectorFeatures.LoginType.V1 -> LoginActivity.redirectIntent(context, data)
VectorFeatures.LoginType.V2 -> LoginActivity2.redirectIntent(context, data)
}
context.startActivity(intent)
}
override fun softLogout(context: Context) {
val intent = when (features.loginType()) {
VectorFeatures.LoginType.V1 -> SoftLogoutActivity.newIntent(context)

View file

@ -19,6 +19,7 @@ package im.vector.app.features.navigation
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.view.View
import androidx.activity.result.ActivityResultLauncher
import androidx.core.util.Pair
@ -41,6 +42,8 @@ interface Navigator {
fun openLogin(context: Context, loginConfig: LoginConfig? = null, flags: Int = 0)
fun loginSSORedirect(context: Context, data: Uri?)
fun softLogout(context: Context)
fun openRoom(context: Context, roomId: String, eventId: String? = null, buildTask: Boolean = false)