IdentityProvider -> SsoIdentityProvider

This commit is contained in:
Benoit Marty 2020-12-14 14:26:51 +01:00 committed by Benoit Marty
parent bba2daf0fc
commit b31dfcfe4f
12 changed files with 36 additions and 34 deletions

View file

@ -19,7 +19,7 @@ package org.matrix.android.sdk.api.auth.data
sealed class LoginFlowResult {
data class Success(
val supportedLoginTypes: List<String>,
val ssoIdentityProviders: List<IdentityProvider>?,
val ssoIdentityProviders: List<SsoIdentityProvider>?,
val isLoginAndRegistrationSupported: Boolean,
val homeServerUrl: String,
val isOutdatedHomeserver: Boolean

View file

@ -23,7 +23,7 @@ import kotlinx.android.parcel.Parcelize
@JsonClass(generateAdapter = true)
@Parcelize
data class IdentityProvider(
data class SsoIdentityProvider(
/**
* The id field would be opaque with the accepted characters matching unreserved URI characters as defined in RFC3986
* - this was chosen to avoid having to encode special characters in the URL. Max length 128.

View file

@ -279,7 +279,7 @@ internal class DefaultAuthenticationService @Inject constructor(
}
return LoginFlowResult.Success(
loginFlowResponse.flows.orEmpty().mapNotNull { it.type },
loginFlowResponse.flows.orEmpty().firstOrNull { it.type == LoginFlowTypes.SSO }?.identityProvider,
loginFlowResponse.flows.orEmpty().firstOrNull { it.type == LoginFlowTypes.SSO }?.ssoIdentityProvider,
versions.isLoginAndRegistrationSupportedBySdk(),
homeServerUrl,
!versions.isSupportedBySdk()

View file

@ -18,7 +18,7 @@ package org.matrix.android.sdk.internal.auth.data
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import org.matrix.android.sdk.api.auth.data.IdentityProvider
import org.matrix.android.sdk.api.auth.data.SsoIdentityProvider
@JsonClass(generateAdapter = true)
internal data class LoginFlowResponse(
@ -43,5 +43,5 @@ internal data class LoginFlow(
* See MSC #2858
*/
@Json(name = "identity_providers")
val identityProvider: List<IdentityProvider>?
val ssoIdentityProvider: List<SsoIdentityProvider>?
)

View file

@ -84,7 +84,7 @@ abstract class AbstractSSOLoginFragment : AbstractLoginFragment() {
private fun prefetchIfNeeded() {
withState(loginViewModel) { state ->
if (state.loginMode.hasSso() && state.loginMode.ssoProviders().isNullOrEmpty()) {
if (state.loginMode.hasSso() && state.loginMode.ssoIdentityProviders().isNullOrEmpty()) {
// in this case we can prefetch (not other cases for privacy concerns)
prefetchUrl(state.getSsoUrl(null))
}

View file

@ -18,7 +18,7 @@ package im.vector.app.features.login
import im.vector.app.core.platform.VectorViewModelAction
import org.matrix.android.sdk.api.auth.data.Credentials
import org.matrix.android.sdk.api.auth.data.IdentityProvider
import org.matrix.android.sdk.api.auth.data.SsoIdentityProvider
import org.matrix.android.sdk.api.auth.registration.RegisterThreePid
import org.matrix.android.sdk.internal.network.ssl.Fingerprint
@ -61,7 +61,9 @@ sealed class LoginAction : VectorViewModelAction {
object ResetResetPassword : ResetAction()
// For the soft logout case
data class SetupSsoForSessionRecovery(val homeServerUrl: String, val deviceId: String, val identityProvider: List<IdentityProvider>?) : LoginAction()
data class SetupSsoForSessionRecovery(val homeServerUrl: String,
val deviceId: String,
val ssoIdentityProvider: List<SsoIdentityProvider>?) : LoginAction()
data class PostViewEvent(val viewEvent: LoginViewEvents) : LoginAction()

View file

@ -175,7 +175,7 @@ class LoginFragment @Inject constructor() : AbstractSSOLoginFragment() {
if (state.loginMode is LoginMode.SsoAndPassword) {
loginSocialLoginContainer.isVisible = true
loginSocialLoginButtons.identityProviders = state.loginMode.identityProviders
loginSocialLoginButtons.ssoIdentityProviders = state.loginMode.ssoIdentityProviders
loginSocialLoginButtons.listener = object : SocialLoginButtonsView.InteractionListener {
override fun onProviderSelected(id: String?) {
openInCustomTab(state.getSsoUrl(id))
@ -183,7 +183,7 @@ class LoginFragment @Inject constructor() : AbstractSSOLoginFragment() {
}
} else {
loginSocialLoginContainer.isVisible = false
loginSocialLoginButtons.identityProviders = null
loginSocialLoginButtons.ssoIdentityProviders = null
}
}
}

View file

@ -18,21 +18,21 @@ package im.vector.app.features.login
import android.os.Parcelable
import kotlinx.android.parcel.Parcelize
import org.matrix.android.sdk.api.auth.data.IdentityProvider
import org.matrix.android.sdk.api.auth.data.SsoIdentityProvider
sealed class LoginMode : Parcelable
/** because persist state */ {
@Parcelize object Unknown : LoginMode()
@Parcelize object Password : LoginMode()
@Parcelize data class Sso(val identityProviders: List<IdentityProvider>?) : LoginMode()
@Parcelize data class SsoAndPassword(val identityProviders: List<IdentityProvider>?) : LoginMode()
@Parcelize data class Sso(val ssoIdentityProviders: List<SsoIdentityProvider>?) : LoginMode()
@Parcelize data class SsoAndPassword(val ssoIdentityProviders: List<SsoIdentityProvider>?) : LoginMode()
@Parcelize object Unsupported : LoginMode()
}
fun LoginMode.ssoProviders() : List<IdentityProvider>? {
fun LoginMode.ssoIdentityProviders() : List<SsoIdentityProvider>? {
return when (this) {
is LoginMode.Sso -> identityProviders
is LoginMode.SsoAndPassword -> identityProviders
is LoginMode.Sso -> ssoIdentityProviders
is LoginMode.SsoAndPassword -> ssoIdentityProviders
else -> null
}
}

View file

@ -53,11 +53,10 @@ class LoginSignUpSignInSelectionFragment @Inject constructor() : AbstractSSOLogi
ServerType.Unknown -> Unit /* Should not happen */
}
val identityProviders = state.loginMode.ssoProviders()
when (state.loginMode) {
is LoginMode.SsoAndPassword -> {
loginSignupSigninSignInSocialLoginContainer.isVisible = true
loginSignupSigninSocialLoginButtons.identityProviders = identityProviders
loginSignupSigninSocialLoginButtons.ssoIdentityProviders = state.loginMode.ssoIdentityProviders()
loginSignupSigninSocialLoginButtons.listener = object : SocialLoginButtonsView.InteractionListener {
override fun onProviderSelected(id: String?) {
val url = withState(loginViewModel) { it.getSsoUrl(id) }
@ -68,7 +67,7 @@ class LoginSignUpSignInSelectionFragment @Inject constructor() : AbstractSSOLogi
else -> {
// SSO only is managed without container as well as No sso
loginSignupSigninSignInSocialLoginContainer.isVisible = false
loginSignupSigninSocialLoginButtons.identityProviders = null
loginSignupSigninSocialLoginButtons.ssoIdentityProviders = null
}
}
}

View file

@ -205,7 +205,7 @@ class LoginViewModel @AssistedInject constructor(
setState {
copy(
signMode = SignMode.SignIn,
loginMode = LoginMode.Sso(action.identityProvider),
loginMode = LoginMode.Sso(action.ssoIdentityProvider),
homeServerUrl = action.homeServerUrl,
deviceId = action.deviceId
)

View file

@ -26,7 +26,7 @@ import android.widget.LinearLayout
import androidx.core.view.children
import com.google.android.material.button.MaterialButton
import im.vector.app.R
import org.matrix.android.sdk.api.auth.data.IdentityProvider
import org.matrix.android.sdk.api.auth.data.SsoIdentityProvider
class SocialLoginButtonsView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0)
: LinearLayout(context, attrs, defStyle) {
@ -41,9 +41,9 @@ class SocialLoginButtonsView @JvmOverloads constructor(context: Context, attrs:
MODE_CONTINUE,
}
var identityProviders: List<IdentityProvider>? = null
var ssoIdentityProviders: List<SsoIdentityProvider>? = null
set(newProviders) {
if (newProviders != identityProviders) {
if (newProviders != ssoIdentityProviders) {
field = newProviders
update()
}
@ -65,7 +65,7 @@ class SocialLoginButtonsView @JvmOverloads constructor(context: Context, attrs:
cachedViews[it.getTag(R.id.loginSignupSigninSocialLoginButtons)?.toString() ?: ""] = it
}
removeAllViews()
if (identityProviders.isNullOrEmpty()) {
if (ssoIdentityProviders.isNullOrEmpty()) {
// Put a default sign in with sso button
MaterialButton(context, null, R.attr.materialButtonOutlinedStyle).apply {
transformationMethod = null
@ -81,7 +81,7 @@ class SocialLoginButtonsView @JvmOverloads constructor(context: Context, attrs:
return
}
identityProviders?.forEach { identityProvider ->
ssoIdentityProviders?.forEach { identityProvider ->
// Use some heuristic to render buttons according to branding guidelines
val button: MaterialButton = cachedViews[identityProvider.id]
?: when (identityProvider.id) {
@ -101,6 +101,7 @@ class SocialLoginButtonsView @JvmOverloads constructor(context: Context, attrs:
MaterialButton(context, null, R.attr.vctr_social_login_button_twitter_style)
}
else -> {
// TODO Use iconUrl
MaterialButton(context, null, R.attr.materialButtonStyle).apply {
transformationMethod = null
textAlignment = View.TEXT_ALIGNMENT_CENTER
@ -131,13 +132,13 @@ class SocialLoginButtonsView @JvmOverloads constructor(context: Context, attrs:
clipChildren = false
@SuppressLint("SetTextI18n")
if (isInEditMode) {
identityProviders = listOf(
IdentityProvider("google", "Google", null),
IdentityProvider("facebook", "Facebook", null),
IdentityProvider("apple", "Apple", null),
IdentityProvider("github", "GitHub", null),
IdentityProvider("twitter", "Twitter", null),
IdentityProvider("Custom_pro", "SSO", null)
ssoIdentityProviders = listOf(
SsoIdentityProvider("google", "Google", null),
SsoIdentityProvider("facebook", "Facebook", null),
SsoIdentityProvider("apple", "Apple", null),
SsoIdentityProvider("github", "GitHub", null),
SsoIdentityProvider("twitter", "Twitter", null),
SsoIdentityProvider("Custom_pro", "SSO", null)
)
}
val typedArray = context.theme.obtainStyledAttributes(attrs, R.styleable.SocialLoginButtonsView, 0, 0)

View file

@ -59,14 +59,14 @@ class SoftLogoutFragment @Inject constructor(
loginViewModel.handle(LoginAction.SetupSsoForSessionRecovery(
softLogoutViewState.homeServerUrl,
softLogoutViewState.deviceId,
mode.identityProviders
mode.ssoIdentityProviders
))
}
is LoginMode.Sso -> {
loginViewModel.handle(LoginAction.SetupSsoForSessionRecovery(
softLogoutViewState.homeServerUrl,
softLogoutViewState.deviceId,
mode.identityProviders
mode.ssoIdentityProviders
))
}
LoginMode.Unsupported -> {