Skip to content

Expose iOS MultiFactorResolver to FirebaseAuthMultiFactorException #727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RaphaelHx
Copy link

When a user has been enrolled into multifactor, on sign in, a FirebaseAuthMultiFactorException is thrown, and should contain a MultiFactorResolver. This has a function resolveSignIn to handle entering the code.

On Android for example, the exception contains the resolver, and can be extracted and used successfully.

import com.google.firebase.auth.FirebaseAuthMultiFactorException
import dev.gitlive.firebase.auth.MultiFactorResolver

actual fun extractMultiFactorResolver(e: FirebaseAuthMultiFactorException): MultiFactorResolver? {
    return MultiFactorResolver(e.resolver)
}

https://firebase.google.com/docs/auth/android/totp-mfa#sign_in_users_with_a_second_factor

However, on iOS, the resolver isn't included in the exception, and so the code below wouldn't work.

import dev.gitlive.firebase.auth.FirebaseAuthMultiFactorException
import dev.gitlive.firebase.auth.MultiFactorResolver
import kotlinx.cinterop.ExperimentalForeignApi

@OptIn(ExperimentalForeignApi::class)
actual fun extractMultiFactorResolver(e: FirebaseAuthMultiFactorException): MultiFactorResolver? {
    val resolver = e.resolver ?: return null
    return MultiFactorResolver(resolver)
}

https://firebase.google.com/docs/auth/ios/totp-mfa#sign_in_users_with_a_second_factor

This is because NSError.toException() function throws a new error without exposing the required resolver.

17087L, // AuthErrorCode.secondFactorAlreadyEnrolled
17078L, // AuthErrorCode.secondFactorRequired
17088L, // AuthErrorCode.maximumSecondFactorCountExceeded
17084L, // AuthErrorCode.multiFactorInfoNotFound
-> FirebaseAuthMultiFactorException(toString())

Adding the resolver in the exception allows iOS to complete sign in for users with multi factor enrolled.

@RaphaelHx
Copy link
Author

Fixes #727

}

17052L, // AuthErrorCode.quotaExceeded
-> FirebaseTooManyRequestsException(toString())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matches the behaviour of android

@RaphaelHx
Copy link
Author

@nbransby @Daeda88 tagging to put this on your radar, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant