Skip to content

Commit

Permalink
Migrate AuthenticationService API to coroutines (#2449)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed Feb 17, 2021
1 parent 7115676 commit 6aa5dc9
Show file tree
Hide file tree
Showing 9 changed files with 462 additions and 602 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Translations 🗣:
-

SDK API changes ⚠️:
-
- Migrate AuthenticationService API to coroutines (#2449)

Build 🧱:
-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@

package org.matrix.android.sdk.api.auth

import org.matrix.android.sdk.api.MatrixCallback
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.login.LoginWizard
import org.matrix.android.sdk.api.auth.registration.RegistrationWizard
import org.matrix.android.sdk.api.auth.wellknown.WellknownResult
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.util.Cancelable

/**
* This interface defines methods to authenticate or to create an account to a matrix server.
Expand All @@ -34,12 +32,12 @@ interface AuthenticationService {
* Request the supported login flows for this homeserver.
* This is the first method to call to be able to get a wizard to login or the create an account
*/
fun getLoginFlow(homeServerConnectionConfig: HomeServerConnectionConfig, callback: MatrixCallback<LoginFlowResult>): Cancelable
suspend fun getLoginFlow(homeServerConnectionConfig: HomeServerConnectionConfig): LoginFlowResult

/**
* Request the supported login flows for the corresponding sessionId.
*/
fun getLoginFlowOfSession(sessionId: String, callback: MatrixCallback<LoginFlowResult>): Cancelable
suspend fun getLoginFlowOfSession(sessionId: String): LoginFlowResult

/**
* Get a SSO url
Expand Down Expand Up @@ -69,12 +67,12 @@ interface AuthenticationService {
/**
* Cancel pending login or pending registration
*/
fun cancelPendingLoginOrRegistration()
suspend fun cancelPendingLoginOrRegistration()

/**
* Reset all pending settings, including current HomeServerConnectionConfig
*/
fun reset()
suspend fun reset()

/**
* Check if there is an authenticated [Session].
Expand All @@ -91,24 +89,21 @@ interface AuthenticationService {
/**
* Create a session after a SSO successful login
*/
fun createSessionFromSso(homeServerConnectionConfig: HomeServerConnectionConfig,
credentials: Credentials,
callback: MatrixCallback<Session>): Cancelable
suspend fun createSessionFromSso(homeServerConnectionConfig: HomeServerConnectionConfig,
credentials: Credentials): Session

/**
* Perform a wellknown request, using the domain from the matrixId
*/
fun getWellKnownData(matrixId: String,
homeServerConnectionConfig: HomeServerConnectionConfig?,
callback: MatrixCallback<WellknownResult>): Cancelable
suspend fun getWellKnownData(matrixId: String,
homeServerConnectionConfig: HomeServerConnectionConfig?): WellknownResult

/**
* Authenticate with a matrixId and a password
* Usually call this after a successful call to getWellKnownData()
*/
fun directAuthentication(homeServerConnectionConfig: HomeServerConnectionConfig,
matrixId: String,
password: String,
initialDeviceName: String,
callback: MatrixCallback<Session>): Cancelable
suspend fun directAuthentication(homeServerConnectionConfig: HomeServerConnectionConfig,
matrixId: String,
password: String,
initialDeviceName: String): Session
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.matrix.android.sdk.api.auth.login

import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.util.Cancelable

Expand All @@ -29,26 +28,23 @@ interface LoginWizard {
* @param callback the matrix callback on which you'll receive the result of authentication.
* @return a [Cancelable]
*/
fun login(login: String,
password: String,
deviceName: String,
callback: MatrixCallback<Session>): Cancelable
suspend fun login(login: String,
password: String,
deviceName: String): Session

/**
* Exchange a login token to an access token
*/
fun loginWithToken(loginToken: String,
callback: MatrixCallback<Session>): Cancelable
suspend fun loginWithToken(loginToken: String): Session

/**
* Reset user password
*/
fun resetPassword(email: String,
newPassword: String,
callback: MatrixCallback<Unit>): Cancelable
suspend fun resetPassword(email: String,
newPassword: String)

/**
* Confirm the new password, once the user has checked his email
* Confirm the new password, once the user has checked their email
*/
fun resetPasswordMailConfirmed(callback: MatrixCallback<Unit>): Cancelable
suspend fun resetPasswordMailConfirmed()
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,25 @@

package org.matrix.android.sdk.api.auth.registration

import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.util.Cancelable

interface RegistrationWizard {

fun getRegistrationFlow(callback: MatrixCallback<RegistrationResult>): Cancelable
suspend fun getRegistrationFlow(): RegistrationResult

fun createAccount(userName: String, password: String, initialDeviceDisplayName: String?, callback: MatrixCallback<RegistrationResult>): Cancelable
suspend fun createAccount(userName: String, password: String, initialDeviceDisplayName: String?): RegistrationResult

fun performReCaptcha(response: String, callback: MatrixCallback<RegistrationResult>): Cancelable
suspend fun performReCaptcha(response: String): RegistrationResult

fun acceptTerms(callback: MatrixCallback<RegistrationResult>): Cancelable
suspend fun acceptTerms(): RegistrationResult

fun dummy(callback: MatrixCallback<RegistrationResult>): Cancelable
suspend fun dummy(): RegistrationResult

fun addThreePid(threePid: RegisterThreePid, callback: MatrixCallback<RegistrationResult>): Cancelable
suspend fun addThreePid(threePid: RegisterThreePid): RegistrationResult

fun sendAgainThreePid(callback: MatrixCallback<RegistrationResult>): Cancelable
suspend fun sendAgainThreePid(): RegistrationResult

fun handleValidateThreePid(code: String, callback: MatrixCallback<RegistrationResult>): Cancelable
suspend fun handleValidateThreePid(code: String): RegistrationResult

fun checkIfEmailHasBeenValidated(delayMillis: Long, callback: MatrixCallback<RegistrationResult>): Cancelable
suspend fun checkIfEmailHasBeenValidated(delayMillis: Long): RegistrationResult

val currentThreePid: String?

Expand Down
Loading

0 comments on commit 6aa5dc9

Please sign in to comment.