瀏覽代碼

Bug fix in account linking flows (#8196)

* Fix bug where stored ID token is not updated after linking account with email link.

* Update changelog.

* Fix the Game Center and phone auth flows as well.

* Update upcoming release version number in changelog.
Rosalyn Tan 4 年之前
父節點
當前提交
cb0bde5b4c
共有 3 個文件被更改,包括 27 次插入1 次删除
  1. 2 1
      FirebaseAuth/CHANGELOG.md
  2. 21 0
      FirebaseAuth/Sources/User/FIRUser.m
  3. 4 0
      FirebaseAuth/Tests/Unit/FIRUserTests.m

+ 2 - 1
FirebaseAuth/CHANGELOG.md

@@ -1,8 +1,9 @@
 # 8.2.0
 - [fixed] Fixed analyze issues introduced in Xcode 12.5. (#8210)
+- [fixed] Fixed a bug in the link with email link, Game Center, and phone auth flows. (#8196)
 
 # 8.0.0
-- [fixed] Fixed a crash that occurred when assigning auth settings (#7670).
+- [fixed] Fixed a crash that occurred when assigning auth settings. (#7670)
 
 # 7.8.0
 - [fixed] Fixed auth state sharing during first app launch. (#7472)

+ 21 - 0
FirebaseAuth/Sources/User/FIRUser.m

@@ -34,6 +34,7 @@
 #import "FirebaseAuth/Sources/Backend/RPC/FIRDeleteAccountRequest.h"
 #import "FirebaseAuth/Sources/Backend/RPC/FIRDeleteAccountResponse.h"
 #import "FirebaseAuth/Sources/Backend/RPC/FIREmailLinkSignInRequest.h"
+#import "FirebaseAuth/Sources/Backend/RPC/FIREmailLinkSignInResponse.h"
 #import "FirebaseAuth/Sources/Backend/RPC/FIRGetAccountInfoRequest.h"
 #import "FirebaseAuth/Sources/Backend/RPC/FIRGetAccountInfoResponse.h"
 #import "FirebaseAuth/Sources/Backend/RPC/FIRGetOOBConfirmationCodeRequest.h"
@@ -718,6 +719,14 @@ static void callInMainThreadWithAuthDataResultAndError(
                                  completion(error);
                                  return;
                                }
+                               FIRAuthRequestConfiguration *requestConfiguration =
+                                   self.auth.requestConfiguration;
+                               // Update the new token and refresh user info again.
+                               self->_tokenService = [[FIRSecureTokenService alloc]
+                                   initWithRequestConfiguration:requestConfiguration
+                                                    accessToken:response.IDToken
+                                      accessTokenExpirationDate:response.approximateExpirationDate
+                                                   refreshToken:response.refreshToken];
                                // Get account info to update cached user info.
                                [self getAccountInfoRefreshingCache:^(
                                          FIRGetAccountInfoResponseUser *_Nullable user,
@@ -1104,6 +1113,12 @@ static void callInMainThreadWithAuthDataResultAndError(
                        if (error) {
                          callInMainThreadWithAuthDataResultAndError(completion, nil, error);
                        } else {
+                         // Update the new token and refresh user info again.
+                         self->_tokenService = [[FIRSecureTokenService alloc]
+                             initWithRequestConfiguration:requestConfiguration
+                                              accessToken:response.IDToken
+                                accessTokenExpirationDate:response.approximateExpirationDate
+                                             refreshToken:response.refreshToken];
                          [self internalGetTokenWithCallback:^(NSString *_Nullable accessToken,
                                                               NSError *_Nullable error) {
                            if (error) {
@@ -1165,6 +1180,12 @@ static void callInMainThreadWithAuthDataResultAndError(
                           if (error) {
                             callInMainThreadWithAuthDataResultAndError(completion, nil, error);
                           } else {
+                            // Update the new token and refresh user info again.
+                            self->_tokenService = [[FIRSecureTokenService alloc]
+                                initWithRequestConfiguration:requestConfiguration
+                                                 accessToken:response.IDToken
+                                   accessTokenExpirationDate:response.approximateExpirationDate
+                                                refreshToken:response.refreshToken];
                             [self internalGetTokenWithCallback:^(NSString *_Nullable accessToken,
                                                                  NSError *_Nullable error) {
                               if (error) {

+ 4 - 0
FirebaseAuth/Tests/Unit/FIRUserTests.m

@@ -3126,6 +3126,10 @@ static const NSTimeInterval kExpectationTimeout = 2;
           }
           id mockVerifyPhoneNumberResponse = OCMClassMock([FIRVerifyPhoneNumberResponse class]);
           OCMStub([mockVerifyPhoneNumberResponse phoneNumber]).andReturn(phoneNumber);
+          OCMStub([mockVerifyPhoneNumberResponse IDToken]).andReturn(kAccessToken);
+          OCMStub([mockVerifyPhoneNumberResponse approximateExpirationDate])
+              .andReturn([NSDate dateWithTimeIntervalSinceNow:kAccessTokenTimeToLive]);
+          OCMStub([mockVerifyPhoneNumberResponse refreshToken]).andReturn(kRefreshToken);
           callback(mockVerifyPhoneNumberResponse, nil);
         });
       });