Skip to content
Snippets Groups Projects
Commit 0fe8ad27 authored by Taras's avatar Taras
Browse files

Implement in DefaultAuthService

parent ec316d59
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,7 @@ import org.matrix.android.sdk.api.auth.data.Credentials
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
import org.matrix.android.sdk.api.auth.data.LoginFlowResult
import org.matrix.android.sdk.api.auth.data.LoginFlowTypes
import org.matrix.android.sdk.api.auth.data.SessionParams
import org.matrix.android.sdk.api.auth.login.LoginWizard
import org.matrix.android.sdk.api.auth.registration.RegistrationWizard
import org.matrix.android.sdk.api.auth.wellknown.WellknownResult
......@@ -448,4 +449,56 @@ internal class DefaultAuthenticationService @Inject constructor(
.addSocketFactory(homeServerConnectionConfig)
.build()
}
//Added to initiate auth without GET /login
override suspend fun initiateAuth(homeServerConnectionConfig: HomeServerConnectionConfig): String {
val result = runCatching {
getHomeServerUserFromWellKnown(homeServerConnectionConfig)
}
return result.fold(
{
val alteredHomeServerConnectionConfig = homeServerConnectionConfig.copy(
homeServerUriBase = Uri.parse(it)
)
pendingSessionData = PendingSessionData(alteredHomeServerConnectionConfig)
.also { data -> pendingSessionStore.savePendingSessionData(data) }
it
},
{
if (it is UnrecognizedCertificateException) {
throw Failure.UnrecognizedCertificateFailure(homeServerConnectionConfig.homeServerUriBase.toString(), it.fingerprint)
} else {
throw it
}
}
)
}
//Added to initiate auth without GET /login
private suspend fun getHomeServerUserFromWellKnown(homeServerConnectionConfig: HomeServerConnectionConfig): String {
val domain = homeServerConnectionConfig.homeServerUri.host
?: throw Failure.OtherServerError("", HttpsURLConnection.HTTP_NOT_FOUND /* 404 */)
return when (val wellKnownResult = getWellknownTask.execute(GetWellknownTask.Params(domain, homeServerConnectionConfig))) {
is WellknownResult.Prompt -> wellKnownResult.homeServerUrl
else -> throw Failure.OtherServerError("", HttpsURLConnection.HTTP_NOT_FOUND /* 404 */)
}
}
//Added for switch user
override suspend fun switchToSessionWithId(id: String) {
sessionManager.setActiveSessionAsLast(id)
}
//Added for switch user
override fun getAllAuthSessionsParams(): List<SessionParams> = sessionManager.getAllSessionParams()
//Added for switch user
override fun createSessionFromParams(params: SessionParams): Session = sessionManager.getOrCreateSession(params)
//Added for switch user
override suspend fun removeSession(sessionId: String) {
sessionManager.removeSession(sessionId)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment