Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -232,28 +232,28 @@ class AWSCognitoAuthPlugin : AuthPlugin<AWSCognitoAuthService>() {
password: String?,
onSuccess: Consumer<AuthSignInResult>,
onError: Consumer<AuthException>
) = enqueue(onSuccess, onError) { queueFacade.signIn(username, password) }
) = enqueue(onSuccess, onError) { useCaseFactory.signIn().execute(username, password) }

override fun signIn(
username: String?,
password: String?,
options: AuthSignInOptions,
onSuccess: Consumer<AuthSignInResult>,
onError: Consumer<AuthException>
) = enqueue(onSuccess, onError) { queueFacade.signIn(username, password, options) }
) = enqueue(onSuccess, onError) { useCaseFactory.signIn().execute(username, password, options) }

override fun confirmSignIn(
challengeResponse: String,
onSuccess: Consumer<AuthSignInResult>,
onError: Consumer<AuthException>
) = enqueue(onSuccess, onError) { queueFacade.confirmSignIn(challengeResponse) }
) = enqueue(onSuccess, onError) { useCaseFactory.confirmSignIn().execute(challengeResponse) }

override fun confirmSignIn(
challengeResponse: String,
options: AuthConfirmSignInOptions,
onSuccess: Consumer<AuthSignInResult>,
onError: Consumer<AuthException>
) = enqueue(onSuccess, onError) { queueFacade.confirmSignIn(challengeResponse, options) }
) = enqueue(onSuccess, onError) { useCaseFactory.confirmSignIn().execute(challengeResponse, options) }

override fun signInWithSocialWebUI(
provider: AuthProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,11 @@ internal class AuthStateMachine(
}

// This function throws if the state machine is *not* in the required state
internal suspend inline fun <reified T : AuthenticationState> AuthStateMachine.requireAuthenticationState() {
if (getCurrentState().authNState !is T) {
throw InvalidStateException(
"Auth State Machine is not in the required authentication state: ${T::class.simpleName}"
)
}
internal suspend inline fun <reified T : AuthenticationState> AuthStateMachine.requireAuthenticationState(): T {
val currentState = getCurrentState()
return currentState.authNState as? T ?: throw InvalidStateException(
"Auth State Machine is not in the required authentication state: ${T::class.simpleName}"
)
}

// Returns the SignedInState or throws SignedOutException or InvalidStateException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,7 @@ internal class CognitoAuthExceptionConverter {
)
else -> UnknownException(fallbackMessage, error)
}

fun Exception.toAuthException(fallbackMessage: String) = lookup(this, fallbackMessage)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import com.amplifyframework.auth.AuthProvider
import com.amplifyframework.auth.AuthSession
import com.amplifyframework.auth.cognito.options.FederateToIdentityPoolOptions
import com.amplifyframework.auth.cognito.result.FederateToIdentityPoolResult
import com.amplifyframework.auth.options.AuthConfirmSignInOptions
import com.amplifyframework.auth.options.AuthFetchSessionOptions
import com.amplifyframework.auth.options.AuthSignInOptions
import com.amplifyframework.auth.options.AuthSignOutOptions
import com.amplifyframework.auth.options.AuthWebUISignInOptions
import com.amplifyframework.auth.result.AuthSignInResult
Expand All @@ -34,44 +32,6 @@ import kotlin.coroutines.suspendCoroutine

internal class KotlinAuthFacadeInternal(private val delegate: RealAWSCognitoAuthPlugin) {

suspend fun signIn(username: String?, password: String?): AuthSignInResult = suspendCoroutine { continuation ->
delegate.signIn(
username,
password,
{ continuation.resume(it) },
{ continuation.resumeWithException(it) }
)
}

suspend fun signIn(username: String?, password: String?, options: AuthSignInOptions): AuthSignInResult =
suspendCoroutine { continuation ->
delegate.signIn(
username,
password,
options,
{ continuation.resume(it) },
{ continuation.resumeWithException(it) }
)
}

suspend fun confirmSignIn(challengeResponse: String): AuthSignInResult = suspendCoroutine { continuation ->
delegate.confirmSignIn(
challengeResponse,
{ continuation.resume(it) },
{ continuation.resumeWithException(it) }
)
}

suspend fun confirmSignIn(challengeResponse: String, options: AuthConfirmSignInOptions): AuthSignInResult =
suspendCoroutine { continuation ->
delegate.confirmSignIn(
challengeResponse,
options,
{ continuation.resume(it) },
{ continuation.resumeWithException(it) }
)
}

suspend fun signInWithSocialWebUI(provider: AuthProvider, callingActivity: Activity): AuthSignInResult =
suspendCoroutine { continuation ->
delegate.signInWithSocialWebUI(
Expand Down
Loading