Skip to content
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

fix the sign in with deleted passkey crash issue #12710

Merged
merged 1 commit into from
Apr 5, 2024
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
1 change: 1 addition & 0 deletions FirebaseAuth/Sources/Auth/FIRAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,7 @@ - (void)finalizePasskeySignInWithPlatformCredential:
NSError *_Nullable error) {
if (error) {
decoratedCallback(nil, error);
return;
}
[self completeSignInWithAccessToken:response.idToken
accessTokenExpirationDate:nil
Expand Down
13 changes: 11 additions & 2 deletions FirebaseAuth/Sources/Backend/FIRAuthBackend.m
Original file line number Diff line number Diff line change
Expand Up @@ -561,10 +561,16 @@

/** @var kInvalidLoginCredentials
@brief This is the error message the server will respond with if the login credentials is
invalid. in the request.
invalid in the request.
*/
static NSString *const kInvalidLoginCredentials = @"INVALID_LOGIN_CREDENTIALS";

/** @var kPasskeyEnrollmentNotFound
@brief This is the error message the server will respond with if the passkey credentials is
invalid in the request.
*/
static NSString *const kPasskeyEnrollmentNotFound = @"PASSKEY_ENROLLMENT_NOT_FOUND";

/** @var gBackendImplementation
@brief The singleton FIRAuthBackendImplementation instance to use.
*/
Expand Down Expand Up @@ -1400,7 +1406,6 @@ - (void)callWithRequest:(id<FIRAuthRPCRequest>)request
underlyingError:error]);
return;
}

// Finally, we try to populate the response object with the JSON
// values.
if (![response setWithDictionary:dictionary error:&error]) {
Expand Down Expand Up @@ -1475,6 +1480,10 @@ + (nullable NSError *)clientErrorWithServerErrorMessage:(NSString *)serverErrorM
return [FIRAuthErrorUtils userNotFoundErrorWithMessage:serverDetailErrorMessage];
}

if ([shortErrorMessage isEqualToString:kPasskeyEnrollmentNotFound]) {
return [FIRAuthErrorUtils passkeyEnrollmentNotFoundError];
}

if ([shortErrorMessage isEqualToString:kUserDeletedErrorMessage]) {
return [FIRAuthErrorUtils userNotFoundErrorWithMessage:serverDetailErrorMessage];
}
Expand Down
4 changes: 4 additions & 0 deletions FirebaseAuth/Sources/Public/FirebaseAuth/FIRAuthErrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,10 @@ typedef NS_ERROR_ENUM(FIRAuthErrorDomain, FIRAuthErrorCode){
*/
FIRAuthErrorCodeRecaptchaSDKNotLinked = 17208,

/** Indicates the user account was not found.
*/
FIRAuthErrorCodePasskeyEnrollmentNotFound = 17209,

/** Indicates an error occurred while attempting to access the keychain.
*/
FIRAuthErrorCodeKeychainError = 17995,
Expand Down
1 change: 1 addition & 0 deletions FirebaseAuth/Sources/User/FIRUser.m
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ - (void)finalizePasskeyEnrollmentWithPlatformCredential:
NSError *_Nullable error) {
if (error) {
decoratedCallback(nil, error);
return;
} else {
[FIRAuth.auth
completeSignInWithAccessToken:response.idToken
Expand Down
6 changes: 6 additions & 0 deletions FirebaseAuth/Sources/Utilities/FIRAuthErrorUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,12 @@ static NSString *const kMissingRecaptchaTokenErrorPrefix = @"MISSING_RECAPTCHA_T
*/
+ (NSError *)notificationNotForwardedError;

/** @fn passkeyEnrollmentNotFoundError
@brief Constructs an @c NSError with the @c FIRAuthErrorCodeNotificationNotForwarded code.
@return The NSError instance associated with the given FIRAuthError.
*/
+ (NSError *)passkeyEnrollmentNotFoundError;

#if TARGET_OS_IOS
/** @fn secondFactorRequiredError
@brief Constructs an @c NSError with the @c FIRAuthErrorCodeSecondFactorRequired code.
Expand Down
11 changes: 11 additions & 0 deletions FirebaseAuth/Sources/Utilities/FIRAuthErrorUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,9 @@
@"Login credentials invalid. It is possible that the email/password combination does not "
@"exist.";

static NSString *const kFIRAuthErrorMessageMissingPasskeyEnrollment =
@"Cannot find the passkey linked to the current account.";

/** @var FIRAuthErrorDescription
@brief The error descrioption, based on the error code.
@remarks No default case so that we get a compiler warning if a new value was added to the enum.
Expand Down Expand Up @@ -814,6 +817,8 @@
return kFIRAuthErrorMessageInvalidReqType;
case FIRAuthErrorCodeRecaptchaSDKNotLinked:
return kFIRAuthErrorMessageRecaptchaSDKNotLinked;
case FIRAuthErrorCodePasskeyEnrollmentNotFound:
return kFIRAuthErrorMessageMissingPasskeyEnrollment;
}
}

Expand Down Expand Up @@ -1001,6 +1006,8 @@
return @"ERROR_INVALID_REQ_TYPE";
case FIRAuthErrorCodeRecaptchaSDKNotLinked:
return @"ERROR_RECAPTCHA_SDK_NOT_LINKED";
case FIRAuthErrorCodePasskeyEnrollmentNotFound:
return @"ERROR_PASSKEY_ENROLLMENT_NOT_FOUND";
}
}

Expand Down Expand Up @@ -1239,6 +1246,10 @@ + (NSError *)userNotFoundErrorWithMessage:(nullable NSString *)message {
return [self errorWithCode:FIRAuthInternalErrorCodeUserNotFound message:message];
}

+ (NSError *)passkeyEnrollmentNotFoundError {
return [self errorWithCode:FIRAuthInternalPasskeyEnrollmentNotFound];
}

+ (NSError *)invalidAPIKeyError {
return [self errorWithCode:FIRAuthInternalErrorCodeInvalidAPIKey];
}
Expand Down
6 changes: 6 additions & 0 deletions FirebaseAuth/Sources/Utilities/FIRAuthInternalErrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ typedef NS_ENUM(NSInteger, FIRAuthInternalErrorCode) {
*/
FIRAuthInternalErrorCodeUserNotFound = FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeUserNotFound,

/** @var FIRAuthInternalPasskeyEnrollmentNotFound
@brief Indicates the given credential ID doesn't exist for passkey withdrawal.
*/
FIRAuthInternalPasskeyEnrollmentNotFound = FIRAuthPublicErrorCodeFlag |
FIRAuthErrorCodePasskeyEnrollmentNotFound,

/** @var FIRAuthInternalErrorCodeInvalidAPIKey
@brief Indicates an invalid API Key was supplied in the request.
*/
Expand Down
Loading