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 @@ -83,5 +83,4 @@ public object Auth0UniversalComponents {
throw IllegalStateException("Auth0UniversalComponents must be initialized first.")
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import com.auth0.universalcomponents.BuildConfig
/**
* Provider class that creates and provides instances of MyAccount from the Auth0 Android SDK.
*/
class MyAccountProvider(
) {
class MyAccountProvider() {

/**
* Creates and returns a MyAccountAPIClient instance configured with the current access token.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class TokenManager private constructor() {
* If not found or expired, fetches a new token and caches it
*/
suspend fun fetchToken(audience: String, scope: String): String {

val cachedCredentials = tokenMap[cacheKey(audience, scope)]
if (cachedCredentials != null) {
if (!willTokenExpire(cachedCredentials.expiresAt.time)) {
Expand Down Expand Up @@ -90,4 +89,4 @@ class TokenManager private constructor() {
val currentTimeInMillis = System.currentTimeMillis()
return expiresAt <= currentTimeInMillis
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ fun SdkMfaEnrollmentChallenge.toDomainModel(): MfaEnrollmentChallenge {
)
}


fun SdkTotpEnrollmentChallenge.toDomainModel(): TotpEnrollmentChallenge {
return TotpEnrollmentChallenge(
id = this.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ internal object ErrorMapper {
message = exception.message ?: "Unknown error occurred",
cause = exception
)

}
}

Expand Down Expand Up @@ -101,7 +100,6 @@ internal object ErrorMapper {
}
}


private fun mapCredentialsManagerException(
exception: CredentialsManagerException,
scope: String?
Expand Down Expand Up @@ -165,4 +163,4 @@ internal object ErrorMapper {
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.auth0.universalcomponents.data.network
import com.auth0.universalcomponents.data.mapper.ErrorMapper
import kotlin.coroutines.cancellation.CancellationException


/**
* Executes a suspend request and maps exceptions to Auth0Error.
* Rethrows [CancellationException] to preserve structured concurrency.
Expand All @@ -23,4 +22,4 @@ internal suspend inline fun <reified T> withErrorMapping(
} catch (e: Throwable) {
throw ErrorMapper.mapToAuth0Error(e, scope)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class MyAccountRepositoryImpl(
val client = myAccountProvider.getMyAccount(accessToken)
client.deleteAuthenticationMethod(authenticationMethodId).await()
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import com.auth0.universalcomponents.domain.usecase.VerifyAuthenticatorUseCase

object UniversalComponentsModule {


//Viewmodel factories
// Viewmodel factories
fun provideAuthenticatorMethodViewModelFactory(): AuthenticatorMethodViewModelFactory {
return AuthenticatorMethodViewModelFactory(
getEnabledAuthenticatorMethodsUseCase = provideEnabledAuthenticatorMethodsUseCase()
Expand Down Expand Up @@ -57,7 +56,7 @@ object UniversalComponentsModule {
)
}

//Use cases
// Use cases
private fun provideEnabledAuthenticatorMethodsUseCase(): GetEnabledAuthenticatorMethodsUseCase {
return GetEnabledAuthenticatorMethodsUseCase(
repository = provideMyAccountRepository(),
Expand All @@ -76,7 +75,6 @@ object UniversalComponentsModule {
)
}


private fun provideEnrollAuthenticatorUseCase(): EnrollAuthenticatorUseCase {
return EnrollAuthenticatorUseCase(
repository = provideMyAccountRepository()
Expand Down Expand Up @@ -106,5 +104,4 @@ object UniversalComponentsModule {
private fun provideTokenManager(): TokenManager {
return TokenManager.getInstance()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ class AuthenticatorMethodViewModelFactory(private val getEnabledAuthenticatorMet
else -> throw IllegalArgumentException("Unknown ViewModel class: ${modelClass.name}")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package com.auth0.universalcomponents.domain

import kotlinx.coroutines.CoroutineDispatcher


interface DispatcherProvider {
val main: CoroutineDispatcher
val io: CoroutineDispatcher
val default: CoroutineDispatcher
val unconfined: CoroutineDispatcher
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ package com.auth0.universalcomponents.domain.error
* These are mapped from infrastructure exceptions (AuthenticationException, MyAccountException, etc.)
*/
sealed class Auth0Error(
override val message: String, override val cause: Throwable
override val message: String,
override val cause: Throwable
) : Throwable(message, cause) {

data class AccessDenied(
Expand Down Expand Up @@ -63,7 +64,6 @@ sealed class Auth0Error(
override val cause: Throwable
) : Auth0Error(message, cause)


// Validation Errors
data class ValidationError(
override val message: String = "Validation failed",
Expand Down Expand Up @@ -97,7 +97,6 @@ sealed class Auth0Error(
val shouldRetry: Boolean = false
) : Auth0Error(message, cause)


// Generic/Unknown Errors
data class Unknown(
override val message: String = "An unknown error occurred",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ data class AuthenticatorMethod(
val secondaryAuthenticators: List<SecondaryAuthenticator>
)


data class PrimaryAuthenticator(
val id: String,
val type: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,3 @@ data class PasskeyAuthenticationMethod(
val credentialBackedUp: Boolean,
val publicKey: String?
) : Parcelable

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.auth0.universalcomponents.domain.model


sealed class EnrollmentInput {

object None : EnrollmentInput()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.auth0.universalcomponents.domain.model
import android.os.Parcelable
import kotlinx.parcelize.Parcelize


/**
* Wrapper for different enrollment challenge types
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ sealed interface Result<out D, out E : Auth0Error> {
data class Error<out E : Auth0Error>(val error: E) : Result<Nothing, E>
}


inline fun <T, E : Auth0Error> Result<T, E>.onSuccess(action: (T) -> Unit): Result<T, E> {
return when (this) {
is Result.Error -> this
Expand All @@ -32,4 +31,4 @@ inline fun <T, E : Auth0Error> Result<T, E>.onError(action: (E) -> Unit): Result
}
}

typealias EmptyResult<E> = Result<Unit, E>
typealias EmptyResult<E> = Result<Unit, E>
Original file line number Diff line number Diff line change
Expand Up @@ -29,66 +29,66 @@ class EnrollAuthenticatorUseCase(
authenticatorType: AuthenticatorType,
input: EnrollmentInput = EnrollmentInput.None
): Result<EnrollmentResult, Auth0Error> = safeCall {
val result = when (authenticatorType) {
AuthenticatorType.TOTP -> {
val challenge = repository.enrollTotp(REQUIRED_SCOPES)
EnrollmentResult.TotpEnrollment(
challenge = challenge,
authenticationMethodId = challenge.id,
authSession = challenge.authSession
)
}
val result = when (authenticatorType) {
AuthenticatorType.TOTP -> {
val challenge = repository.enrollTotp(REQUIRED_SCOPES)
EnrollmentResult.TotpEnrollment(
challenge = challenge,
authenticationMethodId = challenge.id,
authSession = challenge.authSession
)
}

AuthenticatorType.PUSH -> {
val challenge = repository.enrollPushNotification(REQUIRED_SCOPES)
EnrollmentResult.TotpEnrollment(
challenge = challenge,
authenticationMethodId = challenge.id,
authSession = challenge.authSession
)
}
AuthenticatorType.PUSH -> {
val challenge = repository.enrollPushNotification(REQUIRED_SCOPES)
EnrollmentResult.TotpEnrollment(
challenge = challenge,
authenticationMethodId = challenge.id,
authSession = challenge.authSession
)
}

AuthenticatorType.RECOVERY_CODE -> {
val challenge = repository.enrollRecoveryCode(REQUIRED_SCOPES)
EnrollmentResult.RecoveryCodeEnrollment(
challenge = challenge,
authenticationMethodId = challenge.id,
authSession = challenge.authSession
)
}
AuthenticatorType.RECOVERY_CODE -> {
val challenge = repository.enrollRecoveryCode(REQUIRED_SCOPES)
EnrollmentResult.RecoveryCodeEnrollment(
challenge = challenge,
authenticationMethodId = challenge.id,
authSession = challenge.authSession
)
}

AuthenticatorType.EMAIL -> {
require(input is EnrollmentInput.Email) {
"Email enrollment requires EnrollmentInput.Email"
}
val challenge =
repository.enrollEmail(input.email, REQUIRED_SCOPES)
EnrollmentResult.DefaultEnrollment(
challenge = challenge,
authenticationMethodId = challenge.id,
authSession = challenge.authSession
)
AuthenticatorType.EMAIL -> {
require(input is EnrollmentInput.Email) {
"Email enrollment requires EnrollmentInput.Email"
}
val challenge =
repository.enrollEmail(input.email, REQUIRED_SCOPES)
EnrollmentResult.DefaultEnrollment(
challenge = challenge,
authenticationMethodId = challenge.id,
authSession = challenge.authSession
)
}

AuthenticatorType.PHONE -> {
require(input is EnrollmentInput.Phone) {
"Phone enrollment requires EnrollmentInput.Phone"
}
val challenge = repository.enrollPhone(
phoneNumber = input.phoneNumber,
scope = REQUIRED_SCOPES
)
EnrollmentResult.DefaultEnrollment(
challenge = challenge,
authenticationMethodId = challenge.id,
authSession = challenge.authSession
)
AuthenticatorType.PHONE -> {
require(input is EnrollmentInput.Phone) {
"Phone enrollment requires EnrollmentInput.Phone"
}
val challenge = repository.enrollPhone(
phoneNumber = input.phoneNumber,
scope = REQUIRED_SCOPES
)
EnrollmentResult.DefaultEnrollment(
challenge = challenge,
authenticationMethodId = challenge.id,
authSession = challenge.authSession
)
}

else -> {
throw UnsupportedOperationException("Unsupported enrollment type: $authenticatorType")
}
else -> {
throw UnsupportedOperationException("Unsupported enrollment type: $authenticatorType")
}
result
}
result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,24 @@ class VerifyAuthenticatorUseCase(
suspend operator fun invoke(
input: VerificationInput
): Result<AuthenticationMethod, Auth0Error> = safeCall {
val authMethod = when (input) {
is VerificationInput.WithOtp -> {
repository.verifyOtp(
authenticationMethodId = input.authenticationMethodId,
otpCode = input.otpCode,
authSession = input.authSession,
REQUIRED_SCOPES
)
}

val authMethod = when (input) {
is VerificationInput.WithOtp -> {
repository.verifyOtp(
authenticationMethodId = input.authenticationMethodId,
otpCode = input.otpCode,
authSession = input.authSession,
REQUIRED_SCOPES
)
}

is VerificationInput.WithoutOtp -> {
repository.verifyWithoutOtp(
authenticationMethodId = input.authenticationMethodId,
authSession = input.authSession,
REQUIRED_SCOPES
)
}
is VerificationInput.WithoutOtp -> {
repository.verifyWithoutOtp(
authenticationMethodId = input.authenticationMethodId,
authSession = input.authSession,
REQUIRED_SCOPES
)
}
authMethod
}
authMethod
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class DispatcherProviderImpl : DispatcherProvider {
get() = Dispatchers.Default
override val unconfined: CoroutineDispatcher
get() = Dispatchers.Unconfined
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.auth0.universalcomponents.domain.error.Auth0Error
import com.auth0.universalcomponents.domain.network.Result
import com.auth0.universalcomponents.domain.network.safeCall


suspend fun mfaRecoveryHandler(
context: Context,
scope: String,
Expand All @@ -27,4 +26,4 @@ suspend fun mfaRecoveryHandler(
credentials.scope ?: "",
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ sealed interface AuthenticatorRoute {
@Serializable
object PasskeyEnable
}


Loading
Loading