Test for Oidc
This commit is contained in:
parent
9551a5e6f8
commit
f8dbd31c11
9 changed files with 365 additions and 24 deletions
|
|
@ -51,25 +51,27 @@ class OidcPresenter @AssistedInject constructor(
|
|||
fun handleCancel() {
|
||||
requestState = Async.Loading()
|
||||
localCoroutineScope.launch {
|
||||
requestState = try {
|
||||
authenticationService.cancelOidcLogin()
|
||||
// Then go back
|
||||
Async.Success(Unit)
|
||||
} catch (throwable: Throwable) {
|
||||
Async.Failure(throwable)
|
||||
}
|
||||
authenticationService.cancelOidcLogin()
|
||||
.fold(
|
||||
onSuccess = {
|
||||
// Then go back
|
||||
requestState = Async.Success(Unit)
|
||||
},
|
||||
onFailure = {
|
||||
requestState = Async.Failure(it)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun handleSuccess(url: String) {
|
||||
requestState = Async.Loading()
|
||||
localCoroutineScope.launch {
|
||||
try {
|
||||
authenticationService.loginWithOidc(url)
|
||||
// Then the node tree will be updated, there is nothing to do
|
||||
} catch (throwable: Throwable) {
|
||||
requestState = Async.Failure(throwable)
|
||||
}
|
||||
authenticationService.loginWithOidc(url)
|
||||
.onFailure {
|
||||
requestState = Async.Failure(it)
|
||||
}
|
||||
// On success, the node tree will be updated, there is nothing to do
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class OidcUrlParser {
|
|||
* Return a OidcAction, or null if the url is not a OidcUrl
|
||||
*/
|
||||
fun parse(url: String): OidcAction? {
|
||||
if (!url.startsWith(OidcConfig.redirectUri)) return null
|
||||
if (url.startsWith(OidcConfig.redirectUri).not()) return null
|
||||
if (url.contains("error=access_denied")) return OidcAction.GoBack
|
||||
if (url.contains("code=")) return OidcAction.Success(url)
|
||||
|
||||
|
|
|
|||
|
|
@ -97,10 +97,12 @@ class LoginRootPresenter @Inject constructor(
|
|||
homeserver: String,
|
||||
state: MutableState<Async<MatrixHomeServerDetails>>,
|
||||
) = launch {
|
||||
state.value = Async.Loading()
|
||||
suspend {
|
||||
authenticationService.setHomeserver(homeserver)
|
||||
authenticationService.getHomeserverDetails().value!!
|
||||
.map {
|
||||
authenticationService.getHomeserverDetails().value!!
|
||||
}
|
||||
.getOrThrow()
|
||||
}.execute(state)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue