Skip to content

Commit

Permalink
fix(auth): ensure PigeonAuthCredential is passed back to Dart side …
Browse files Browse the repository at this point in the history
…within try/catch (#11683)
  • Loading branch information
russellwheatley committed Oct 12, 2023
1 parent a48a707 commit d42c339
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
Expand Up @@ -187,8 +187,7 @@ + (FlutterError *)convertToFlutterError:(NSError *)error {
// additionalData.authCredential
if ([error userInfo][FIRAuthErrorUserInfoUpdatedCredentialKey] != nil) {
FIRAuthCredential *authCredential = [error userInfo][FIRAuthErrorUserInfoUpdatedCredentialKey];
additionalData[@"authCredential"] =
[FLTFirebaseAuthPlugin getNSDictionaryFromAuthCredential:authCredential];
additionalData[@"authCredential"] = [PigeonParser getPigeonAuthCredential:authCredential];
}

// Manual message overrides to ensure messages/codes matches other platforms.
Expand Down Expand Up @@ -576,9 +575,7 @@ static void handleAppleAuthResult(FLTFirebaseAuthPlugin *object, PigeonFirebaseA
if (error.code == FIRAuthErrorCodeSecondFactorRequired) {
[object handleMultiFactorError:app completion:completion withError:error];
} else {
completion(nil, [FlutterError errorWithCode:@"sign-in-failed"
message:error.localizedDescription
details:error.userInfo]);
completion(nil, [FLTFirebaseAuthPlugin convertToFlutterError:error]);
}
return;
}
Expand Down Expand Up @@ -1227,9 +1224,13 @@ - (void)signInWithCredentialApp:(nonnull PigeonFirebaseApp *)app
if (firebaseDictionary != nil && firebaseDictionary[@"message"] != nil) {
// error from firebase-ios-sdk is buried in underlying
// error.
completion(nil, [FlutterError errorWithCode:firebaseDictionary[@"code"]
message:firebaseDictionary[@"message"]
details:nil]);
if ([firebaseDictionary[@"code"] isKindOfClass:[NSNumber class]]) {
[self handleInternalError:completion withError:error];
} else {
completion(nil, [FlutterError errorWithCode:firebaseDictionary[@"code"]
message:firebaseDictionary[@"message"]
details:nil]);
}
} else {
if (error.code == FIRAuthErrorCodeSecondFactorRequired) {
[self handleMultiFactorError:app completion:completion withError:error];
Expand Down
Expand Up @@ -19,7 +19,8 @@
+ (FIRActionCodeSettings *_Nullable)parseActionCodeSettings:
(nullable PigeonActionCodeSettings *)settings;
+ (PigeonUserCredential *_Nullable)getPigeonUserCredentialFromFIRUser:(nonnull FIRUser *)user;
+ (PigeonIdTokenResult *)parseIdTokenResult:(FIRAuthTokenResult *)tokenResult;
+ (PigeonIdTokenResult *_Nonnull)parseIdTokenResult:(nonnull FIRAuthTokenResult *)tokenResult;
+ (PigeonTotpSecret *_Nonnull)getPigeonTotpSecret:(nonnull FIRTOTPSecret *)secret;

+ (PigeonAuthCredential *_Nullable)getPigeonAuthCredential:
(FIRAuthCredential *_Nullable)authCredential;
@end
Expand Up @@ -58,9 +58,26 @@ FirebaseException platformExceptionToFirebaseAuthException(
}
}

AuthCredential? credential;

if (platformException.details != null &&
platformException.details['authCredential'] != null &&
platformException.details['authCredential'] is PigeonAuthCredential) {
PigeonAuthCredential pigeonAuthCredential =
platformException.details['authCredential'];

credential = AuthCredential(
providerId: pigeonAuthCredential.providerId,
signInMethod: pigeonAuthCredential.signInMethod,
token: pigeonAuthCredential.nativeId,
accessToken: pigeonAuthCredential.accessToken,
);
}

return FirebaseAuthException(
code: code,
message: platformException.message?.split(': ').last,
credential: credential,
);
}

Expand Down

0 comments on commit d42c339

Please sign in to comment.