Skip to content

Commit cb0bde5

Browse files
authored
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.
1 parent 633fa55 commit cb0bde5

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

FirebaseAuth/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# 8.2.0
22
- [fixed] Fixed analyze issues introduced in Xcode 12.5. (#8210)
3+
- [fixed] Fixed a bug in the link with email link, Game Center, and phone auth flows. (#8196)
34

45
# 8.0.0
5-
- [fixed] Fixed a crash that occurred when assigning auth settings (#7670).
6+
- [fixed] Fixed a crash that occurred when assigning auth settings. (#7670)
67

78
# 7.8.0
89
- [fixed] Fixed auth state sharing during first app launch. (#7472)

FirebaseAuth/Sources/User/FIRUser.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#import "FirebaseAuth/Sources/Backend/RPC/FIRDeleteAccountRequest.h"
3535
#import "FirebaseAuth/Sources/Backend/RPC/FIRDeleteAccountResponse.h"
3636
#import "FirebaseAuth/Sources/Backend/RPC/FIREmailLinkSignInRequest.h"
37+
#import "FirebaseAuth/Sources/Backend/RPC/FIREmailLinkSignInResponse.h"
3738
#import "FirebaseAuth/Sources/Backend/RPC/FIRGetAccountInfoRequest.h"
3839
#import "FirebaseAuth/Sources/Backend/RPC/FIRGetAccountInfoResponse.h"
3940
#import "FirebaseAuth/Sources/Backend/RPC/FIRGetOOBConfirmationCodeRequest.h"
@@ -718,6 +719,14 @@ - (void)internalUpdateOrLinkPhoneNumberCredential:(FIRPhoneAuthCredential *)phon
718719
completion(error);
719720
return;
720721
}
722+
FIRAuthRequestConfiguration *requestConfiguration =
723+
self.auth.requestConfiguration;
724+
// Update the new token and refresh user info again.
725+
self->_tokenService = [[FIRSecureTokenService alloc]
726+
initWithRequestConfiguration:requestConfiguration
727+
accessToken:response.IDToken
728+
accessTokenExpirationDate:response.approximateExpirationDate
729+
refreshToken:response.refreshToken];
721730
// Get account info to update cached user info.
722731
[self getAccountInfoRefreshingCache:^(
723732
FIRGetAccountInfoResponseUser *_Nullable user,
@@ -1104,6 +1113,12 @@ - (void)linkWithCredential:(FIRAuthCredential *)credential
11041113
if (error) {
11051114
callInMainThreadWithAuthDataResultAndError(completion, nil, error);
11061115
} else {
1116+
// Update the new token and refresh user info again.
1117+
self->_tokenService = [[FIRSecureTokenService alloc]
1118+
initWithRequestConfiguration:requestConfiguration
1119+
accessToken:response.IDToken
1120+
accessTokenExpirationDate:response.approximateExpirationDate
1121+
refreshToken:response.refreshToken];
11071122
[self internalGetTokenWithCallback:^(NSString *_Nullable accessToken,
11081123
NSError *_Nullable error) {
11091124
if (error) {
@@ -1165,6 +1180,12 @@ - (void)linkWithCredential:(FIRAuthCredential *)credential
11651180
if (error) {
11661181
callInMainThreadWithAuthDataResultAndError(completion, nil, error);
11671182
} else {
1183+
// Update the new token and refresh user info again.
1184+
self->_tokenService = [[FIRSecureTokenService alloc]
1185+
initWithRequestConfiguration:requestConfiguration
1186+
accessToken:response.IDToken
1187+
accessTokenExpirationDate:response.approximateExpirationDate
1188+
refreshToken:response.refreshToken];
11681189
[self internalGetTokenWithCallback:^(NSString *_Nullable accessToken,
11691190
NSError *_Nullable error) {
11701191
if (error) {

FirebaseAuth/Tests/Unit/FIRUserTests.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3126,6 +3126,10 @@ - (void)expectVerifyPhoneNumberRequestWithPhoneNumber:(nullable NSString *)phone
31263126
}
31273127
id mockVerifyPhoneNumberResponse = OCMClassMock([FIRVerifyPhoneNumberResponse class]);
31283128
OCMStub([mockVerifyPhoneNumberResponse phoneNumber]).andReturn(phoneNumber);
3129+
OCMStub([mockVerifyPhoneNumberResponse IDToken]).andReturn(kAccessToken);
3130+
OCMStub([mockVerifyPhoneNumberResponse approximateExpirationDate])
3131+
.andReturn([NSDate dateWithTimeIntervalSinceNow:kAccessTokenTimeToLive]);
3132+
OCMStub([mockVerifyPhoneNumberResponse refreshToken]).andReturn(kRefreshToken);
31293133
callback(mockVerifyPhoneNumberResponse, nil);
31303134
});
31313135
});

0 commit comments

Comments
 (0)