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(auth): ensure PigeonAuthCredential is passed back to Dart side within try/catch #11683

Merged
merged 3 commits into from
Oct 12, 2023
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 @@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading