diff --git a/packages/firebase_auth/firebase_auth/ios/Classes/FLTFirebaseAuthPlugin.m b/packages/firebase_auth/firebase_auth/ios/Classes/FLTFirebaseAuthPlugin.m index b5270dea4882..a70675f5ee38 100644 --- a/packages/firebase_auth/firebase_auth/ios/Classes/FLTFirebaseAuthPlugin.m +++ b/packages/firebase_auth/firebase_auth/ios/Classes/FLTFirebaseAuthPlugin.m @@ -193,13 +193,14 @@ + (FlutterError *)convertToFlutterError:(NSError *)error { additionalData[kArgumentEmail] = [error userInfo][FIRAuthErrorUserInfoEmailKey]; } // We want to store the credential if present for future sign in if the exception contains a - // credential - [FLTFirebaseAuthPlugin storeAuthCredentialIfPresent:error]; + // credential, we pass a token back to Flutter to allow retreival of the credential. + NSNumber *token = [FLTFirebaseAuthPlugin storeAuthCredentialIfPresent:error]; // additionalData.authCredential if ([error userInfo][FIRAuthErrorUserInfoUpdatedCredentialKey] != nil) { FIRAuthCredential *authCredential = [error userInfo][FIRAuthErrorUserInfoUpdatedCredentialKey]; - additionalData[@"authCredential"] = [PigeonParser getPigeonAuthCredential:authCredential]; + additionalData[@"authCredential"] = [PigeonParser getPigeonAuthCredential:authCredential + token:token]; } // Manual message overrides to ensure messages/codes matches other platforms. @@ -641,14 +642,16 @@ static void handleAppleAuthResult(FLTFirebaseAuthPlugin *object, AuthPigeonFireb #pragma mark - Utilities -+ (void)storeAuthCredentialIfPresent:(NSError *)error { ++ (NSNumber *_Nullable)storeAuthCredentialIfPresent:(NSError *)error { if ([error userInfo][FIRAuthErrorUserInfoUpdatedCredentialKey] != nil) { FIRAuthCredential *authCredential = [error userInfo][FIRAuthErrorUserInfoUpdatedCredentialKey]; // We temporarily store the non-serializable credential so the // Dart API can consume these at a later time. NSNumber *authCredentialHash = @([authCredential hash]); credentialsMap[authCredentialHash] = authCredential; + return authCredentialHash; } + return nil; } - (FIRAuth *_Nullable)getFIRAuthFromAppNameFromPigeon:(AuthPigeonFirebaseApp *)pigeonApp { diff --git a/packages/firebase_auth/firebase_auth/ios/Classes/PigeonParser.m b/packages/firebase_auth/firebase_auth/ios/Classes/PigeonParser.m index a82a8e47d1be..c918134a358f 100644 --- a/packages/firebase_auth/firebase_auth/ios/Classes/PigeonParser.m +++ b/packages/firebase_auth/firebase_auth/ios/Classes/PigeonParser.m @@ -15,7 +15,7 @@ @implementation PigeonParser makeWithUser:[self getPigeonDetails:authResult.user] additionalUserInfo:[self getPigeonAdditionalUserInfo:authResult.additionalUserInfo authorizationCode:authorizationCode] - credential:[self getPigeonAuthCredential:authResult.credential]]; + credential:[self getPigeonAuthCredential:authResult.credential token:nil]]; } + (PigeonUserCredential *)getPigeonUserCredentialFromFIRUser:(nonnull FIRUser *)user { @@ -88,7 +88,8 @@ + (PigeonTotpSecret *)getPigeonTotpSecret:(FIRTOTPSecret *)secret { secretKey:secret.sharedSecretKey]; } -+ (PigeonAuthCredential *)getPigeonAuthCredential:(FIRAuthCredential *)authCredential { ++ (PigeonAuthCredential *)getPigeonAuthCredential:(FIRAuthCredential *)authCredential + token:(NSNumber *_Nullable)token { if (authCredential == nil) { return nil; } @@ -103,9 +104,12 @@ + (PigeonAuthCredential *)getPigeonAuthCredential:(FIRAuthCredential *)authCrede } } + NSUInteger nativeId = + token != nil ? [token unsignedLongValue] : (NSUInteger)[authCredential hash]; + return [PigeonAuthCredential makeWithProviderId:authCredential.provider signInMethod:authCredential.provider - nativeId:@([authCredential hash]) + nativeId:nativeId accessToken:accessToken ?: nil]; } diff --git a/packages/firebase_auth/firebase_auth/ios/Classes/Private/PigeonParser.h b/packages/firebase_auth/firebase_auth/ios/Classes/Private/PigeonParser.h index e5a75bf68489..c3436703b4a0 100644 --- a/packages/firebase_auth/firebase_auth/ios/Classes/Private/PigeonParser.h +++ b/packages/firebase_auth/firebase_auth/ios/Classes/Private/PigeonParser.h @@ -23,5 +23,6 @@ + (PigeonIdTokenResult *_Nonnull)parseIdTokenResult:(nonnull FIRAuthTokenResult *)tokenResult; + (PigeonTotpSecret *_Nonnull)getPigeonTotpSecret:(nonnull FIRTOTPSecret *)secret; + (PigeonAuthCredential *_Nullable)getPigeonAuthCredential: - (FIRAuthCredential *_Nullable)authCredential; + (FIRAuthCredential *_Nullable)authCredentialToken + token:(NSNumber *_Nullable)token; @end