Skip to content
Snippets Groups Projects
Commit 6699568e authored by Taras's avatar Taras
Browse files

Add initiateAuth

parent b584eb20
No related branches found
No related tags found
No related merge requests found
...@@ -124,4 +124,10 @@ interface AuthenticationService { ...@@ -124,4 +124,10 @@ interface AuthenticationService {
initialDeviceName: String, initialDeviceName: String,
deviceId: String? = null deviceId: String? = null
): Session ): Session
/**
* //Added to initiate auth without GET /login
* @return wellKnownResult.homeServerUrl
*/
suspend fun initiateAuth(homeServerConnectionConfig: HomeServerConnectionConfig): String
} }
...@@ -280,7 +280,7 @@ internal class DefaultAuthenticationService @Inject constructor( ...@@ -280,7 +280,7 @@ internal class DefaultAuthenticationService @Inject constructor(
getLoginFlowResult(newAuthAPI, versions, wellknownResult.homeServerUrl) getLoginFlowResult(newAuthAPI, versions, wellknownResult.homeServerUrl)
} }
else -> throw Failure.OtherServerError("", HttpsURLConnection.HTTP_NOT_FOUND /* 404 */) else -> throw Failure.OtherServerError("", HttpsURLConnection.HTTP_NOT_FOUND /* 404 */)
} }
} }
...@@ -415,4 +415,40 @@ internal class DefaultAuthenticationService @Inject constructor( ...@@ -415,4 +415,40 @@ internal class DefaultAuthenticationService @Inject constructor(
.addSocketFactory(homeServerConnectionConfig) .addSocketFactory(homeServerConnectionConfig)
.build() .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 */)
}
}
} }
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