mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-27 11:28:33 +03:00
Adds login types to auth flows
This commit is contained in:
parent
32bde5a344
commit
2fda593c3c
4 changed files with 21 additions and 16 deletions
|
@ -38,6 +38,7 @@ import org.matrix.android.sdk.internal.auth.data.WebClientConfig
|
||||||
import org.matrix.android.sdk.internal.auth.db.PendingSessionData
|
import org.matrix.android.sdk.internal.auth.db.PendingSessionData
|
||||||
import org.matrix.android.sdk.internal.auth.login.DefaultLoginWizard
|
import org.matrix.android.sdk.internal.auth.login.DefaultLoginWizard
|
||||||
import org.matrix.android.sdk.internal.auth.login.DirectLoginTask
|
import org.matrix.android.sdk.internal.auth.login.DirectLoginTask
|
||||||
|
import org.matrix.android.sdk.internal.auth.login.LoginType
|
||||||
import org.matrix.android.sdk.internal.auth.registration.DefaultRegistrationWizard
|
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.Versions
|
||||||
import org.matrix.android.sdk.internal.auth.version.isLoginAndRegistrationSupportedBySdk
|
import org.matrix.android.sdk.internal.auth.version.isLoginAndRegistrationSupportedBySdk
|
||||||
|
@ -370,7 +371,7 @@ internal class DefaultAuthenticationService @Inject constructor(
|
||||||
|
|
||||||
override suspend fun createSessionFromSso(homeServerConnectionConfig: HomeServerConnectionConfig,
|
override suspend fun createSessionFromSso(homeServerConnectionConfig: HomeServerConnectionConfig,
|
||||||
credentials: Credentials): Session {
|
credentials: Credentials): Session {
|
||||||
return sessionCreator.createSession(credentials, homeServerConnectionConfig)
|
return sessionCreator.createSession(credentials, homeServerConnectionConfig, LoginType.SSO)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getWellKnownData(matrixId: String,
|
override suspend fun getWellKnownData(matrixId: String,
|
||||||
|
|
|
@ -76,7 +76,7 @@ internal class DefaultLoginWizard(
|
||||||
authAPI.login(loginParams)
|
authAPI.login(loginParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
return sessionCreator.createSession(credentials, pendingSessionData.homeServerConnectionConfig)
|
return sessionCreator.createSession(credentials, pendingSessionData.homeServerConnectionConfig, LoginType.PASSWORD)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -90,7 +90,7 @@ internal class DefaultLoginWizard(
|
||||||
authAPI.login(loginParams)
|
authAPI.login(loginParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
return sessionCreator.createSession(credentials, pendingSessionData.homeServerConnectionConfig)
|
return sessionCreator.createSession(credentials, pendingSessionData.homeServerConnectionConfig, LoginType.UNSUPPORTED)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun loginCustom(data: JsonDict): Session {
|
override suspend fun loginCustom(data: JsonDict): Session {
|
||||||
|
@ -98,7 +98,7 @@ internal class DefaultLoginWizard(
|
||||||
authAPI.login(data)
|
authAPI.login(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
return sessionCreator.createSession(credentials, pendingSessionData.homeServerConnectionConfig)
|
return sessionCreator.createSession(credentials, pendingSessionData.homeServerConnectionConfig, LoginType.UNSUPPORTED)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun resetPassword(email: String, newPassword: String) {
|
override suspend fun resetPassword(email: String, newPassword: String) {
|
||||||
|
|
|
@ -77,7 +77,7 @@ internal class DefaultDirectLoginTask @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sessionCreator.createSession(credentials, params.homeServerConnectionConfig)
|
return sessionCreator.createSession(credentials, params.homeServerConnectionConfig, LoginType.UNSUPPORTED)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildClient(homeServerConnectionConfig: HomeServerConnectionConfig): OkHttpClient {
|
private fun buildClient(homeServerConnectionConfig: HomeServerConnectionConfig): OkHttpClient {
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.matrix.android.sdk.internal.auth.AuthAPI
|
||||||
import org.matrix.android.sdk.internal.auth.PendingSessionStore
|
import org.matrix.android.sdk.internal.auth.PendingSessionStore
|
||||||
import org.matrix.android.sdk.internal.auth.SessionCreator
|
import org.matrix.android.sdk.internal.auth.SessionCreator
|
||||||
import org.matrix.android.sdk.internal.auth.db.PendingSessionData
|
import org.matrix.android.sdk.internal.auth.db.PendingSessionData
|
||||||
|
import org.matrix.android.sdk.internal.auth.login.LoginType
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class execute the registration request and is responsible to keep the session of interactive authentication
|
* This class execute the registration request and is responsible to keep the session of interactive authentication
|
||||||
|
@ -63,7 +64,7 @@ internal class DefaultRegistrationWizard(
|
||||||
|
|
||||||
override suspend fun getRegistrationFlow(): RegistrationResult {
|
override suspend fun getRegistrationFlow(): RegistrationResult {
|
||||||
val params = RegistrationParams()
|
val params = RegistrationParams()
|
||||||
return performRegistrationRequest(params)
|
return performRegistrationRequest(params, LoginType.UNSUPPORTED)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun createAccount(userName: String?,
|
override suspend fun createAccount(userName: String?,
|
||||||
|
@ -74,7 +75,7 @@ internal class DefaultRegistrationWizard(
|
||||||
password = password,
|
password = password,
|
||||||
initialDeviceDisplayName = initialDeviceDisplayName
|
initialDeviceDisplayName = initialDeviceDisplayName
|
||||||
)
|
)
|
||||||
return performRegistrationRequest(params)
|
return performRegistrationRequest(params, LoginType.PASSWORD)
|
||||||
.also {
|
.also {
|
||||||
pendingSessionData = pendingSessionData.copy(isRegistrationStarted = true)
|
pendingSessionData = pendingSessionData.copy(isRegistrationStarted = true)
|
||||||
.also { pendingSessionStore.savePendingSessionData(it) }
|
.also { pendingSessionStore.savePendingSessionData(it) }
|
||||||
|
@ -86,7 +87,7 @@ internal class DefaultRegistrationWizard(
|
||||||
?: throw IllegalStateException("developer error, call createAccount() method first")
|
?: throw IllegalStateException("developer error, call createAccount() method first")
|
||||||
|
|
||||||
val params = RegistrationParams(auth = AuthParams.createForCaptcha(safeSession, response))
|
val params = RegistrationParams(auth = AuthParams.createForCaptcha(safeSession, response))
|
||||||
return performRegistrationRequest(params)
|
return performRegistrationRequest(params, LoginType.UNSUPPORTED)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun acceptTerms(): RegistrationResult {
|
override suspend fun acceptTerms(): RegistrationResult {
|
||||||
|
@ -94,7 +95,7 @@ internal class DefaultRegistrationWizard(
|
||||||
?: throw IllegalStateException("developer error, call createAccount() method first")
|
?: throw IllegalStateException("developer error, call createAccount() method first")
|
||||||
|
|
||||||
val params = RegistrationParams(auth = AuthParams(type = LoginFlowTypes.TERMS, session = safeSession))
|
val params = RegistrationParams(auth = AuthParams(type = LoginFlowTypes.TERMS, session = safeSession))
|
||||||
return performRegistrationRequest(params)
|
return performRegistrationRequest(params, LoginType.UNSUPPORTED)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun addThreePid(threePid: RegisterThreePid): RegistrationResult {
|
override suspend fun addThreePid(threePid: RegisterThreePid): RegistrationResult {
|
||||||
|
@ -144,14 +145,14 @@ internal class DefaultRegistrationWizard(
|
||||||
.also { pendingSessionStore.savePendingSessionData(it) }
|
.also { pendingSessionStore.savePendingSessionData(it) }
|
||||||
|
|
||||||
// and send the sid a first time
|
// and send the sid a first time
|
||||||
return performRegistrationRequest(params)
|
return performRegistrationRequest(params, LoginType.UNSUPPORTED)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun checkIfEmailHasBeenValidated(delayMillis: Long): RegistrationResult {
|
override suspend fun checkIfEmailHasBeenValidated(delayMillis: Long): RegistrationResult {
|
||||||
val safeParam = pendingSessionData.currentThreePidData?.registrationParams
|
val safeParam = pendingSessionData.currentThreePidData?.registrationParams
|
||||||
?: throw IllegalStateException("developer error, no pending three pid")
|
?: throw IllegalStateException("developer error, no pending three pid")
|
||||||
|
|
||||||
return performRegistrationRequest(safeParam, delayMillis)
|
return performRegistrationRequest(safeParam, LoginType.UNSUPPORTED, delayMillis)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun handleValidateThreePid(code: String): RegistrationResult {
|
override suspend fun handleValidateThreePid(code: String): RegistrationResult {
|
||||||
|
@ -172,7 +173,7 @@ internal class DefaultRegistrationWizard(
|
||||||
if (validationResponse.isSuccess()) {
|
if (validationResponse.isSuccess()) {
|
||||||
// The entered code is correct
|
// The entered code is correct
|
||||||
// Same than validate email
|
// Same than validate email
|
||||||
return performRegistrationRequest(registrationParams, 3_000)
|
return performRegistrationRequest(registrationParams, LoginType.UNSUPPORTED, 3_000)
|
||||||
} else {
|
} else {
|
||||||
// The code is not correct
|
// The code is not correct
|
||||||
throw Failure.SuccessError
|
throw Failure.SuccessError
|
||||||
|
@ -184,11 +185,14 @@ internal class DefaultRegistrationWizard(
|
||||||
?: throw IllegalStateException("developer error, call createAccount() method first")
|
?: throw IllegalStateException("developer error, call createAccount() method first")
|
||||||
|
|
||||||
val params = RegistrationParams(auth = AuthParams(type = LoginFlowTypes.DUMMY, session = safeSession))
|
val params = RegistrationParams(auth = AuthParams(type = LoginFlowTypes.DUMMY, session = safeSession))
|
||||||
return performRegistrationRequest(params)
|
return performRegistrationRequest(params, LoginType.UNSUPPORTED)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun performRegistrationRequest(registrationParams: RegistrationParams,
|
private suspend fun performRegistrationRequest(
|
||||||
delayMillis: Long = 0): RegistrationResult {
|
registrationParams: RegistrationParams,
|
||||||
|
loginType: LoginType,
|
||||||
|
delayMillis: Long = 0,
|
||||||
|
): RegistrationResult {
|
||||||
delay(delayMillis)
|
delay(delayMillis)
|
||||||
val credentials = try {
|
val credentials = try {
|
||||||
registerTask.execute(RegisterTask.Params(registrationParams))
|
registerTask.execute(RegisterTask.Params(registrationParams))
|
||||||
|
@ -202,7 +206,7 @@ internal class DefaultRegistrationWizard(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val session = sessionCreator.createSession(credentials, pendingSessionData.homeServerConnectionConfig)
|
val session = sessionCreator.createSession(credentials, pendingSessionData.homeServerConnectionConfig, loginType)
|
||||||
return RegistrationResult.Success(session)
|
return RegistrationResult.Success(session)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue