Skip to content

Commit a15117c

Browse files
author
renkelvin
authored
Revert "Use sign up endpoint for link with email password" (#11957)
1 parent 85cfe57 commit a15117c

File tree

11 files changed

+77
-223
lines changed

11 files changed

+77
-223
lines changed

FirebaseAuth/CHANGELOG.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# 10.17.0
2-
- [fixed] Fix a bug where anonymous account can't be linked with email password credential. (#11911)
3-
41
# 10.16.0
52
- [added] Added custom auth domain support in recaptcha v2 authentication flows. (#7553)
63

FirebaseAuth/Sources/Auth/FIRAuth.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#import "FirebaseAuth/Sources/AuthProvider/FIRAuthCredential_Internal.h"
3636
#import "FirebaseAuth/Sources/AuthProvider/GameCenter/FIRGameCenterAuthCredential.h"
3737
#import "FirebaseAuth/Sources/AuthProvider/OAuth/FIROAuthCredential_Internal.h"
38+
#import "FirebaseAuth/Sources/Backend/FIRAuthBackend.h"
3839
#import "FirebaseAuth/Sources/Backend/FIRAuthRequestConfiguration.h"
3940
#import "FirebaseAuth/Sources/Backend/RPC/FIRCreateAuthURIRequest.h"
4041
#import "FirebaseAuth/Sources/Backend/RPC/FIRCreateAuthURIResponse.h"
@@ -164,6 +165,11 @@
164165
*/
165166
static NSString *const kRevertSecondFactorAdditionRequestType = @"REVERT_SECOND_FACTOR_ADDITION";
166167

168+
/** @var kMissingRecaptchaTokenErrorPrefix
169+
@brief The prefix of the error message of missing recaptcha token during authenticating.
170+
*/
171+
static NSString *const kMissingRecaptchaTokenErrorPrefix = @"MISSING_RECAPTCHA_TOKEN";
172+
167173
/** @var kMissingPasswordReason
168174
@brief The reason why the @c FIRAuthErrorCodeWeakPassword error is thrown.
169175
@remarks This error message will be localized in the future.
@@ -1988,7 +1994,6 @@ - (void)internalCreateUserWithEmail:(NSString *)email
19881994
[[FIRSignUpNewUserRequest alloc] initWithEmail:email
19891995
password:password
19901996
displayName:nil
1991-
idToken:nil
19921997
requestConfiguration:_requestConfiguration];
19931998
if (![request.password length]) {
19941999
completion(

FirebaseAuth/Sources/Auth/FIRAuth_Internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#import <Foundation/Foundation.h>
1818
#import "FirebaseAuth/Interop/FIRAuthInterop.h"
19-
#import "FirebaseAuth/Sources/Backend/FIRAuthBackend.h"
2019
#import "FirebaseAuth/Sources/Public/FirebaseAuth/FIRAuth.h"
2120
#import "FirebaseCore/Extension/FIRLogger.h"
2221

FirebaseAuth/Sources/Backend/RPC/FIRSignUpNewUserRequest.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ NS_ASSUME_NONNULL_BEGIN
3838
*/
3939
@property(nonatomic, copy, nullable) NSString *displayName;
4040

41-
/** @property idToken
42-
@brief The idToken of the user.
43-
*/
44-
@property(nonatomic, copy, nullable) NSString *idToken;
45-
4641
/** @property captchaResponse
4742
@brief Response to the captcha.
4843
*/
@@ -79,7 +74,6 @@ NS_ASSUME_NONNULL_BEGIN
7974
- (nullable instancetype)initWithEmail:(nullable NSString *)email
8075
password:(nullable NSString *)password
8176
displayName:(nullable NSString *)displayName
82-
idToken:(nullable NSString *)idToken
8377
requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration
8478
NS_DESIGNATED_INITIALIZER;
8579

FirebaseAuth/Sources/Backend/RPC/FIRSignUpNewUserRequest.m

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@
3838
*/
3939
static NSString *const kDisplayNameKey = @"displayName";
4040

41-
/** @var kIDToken
42-
@brief The key for the "kIDToken" value in the request.
43-
*/
44-
static NSString *const kIDToken = @"idToken";
45-
4641
/** @var kCaptchaResponseKey
4742
@brief The key for the "captchaResponse" value in the request.
4843
*/
@@ -73,14 +68,12 @@ @implementation FIRSignUpNewUserRequest
7368
- (nullable instancetype)initWithEmail:(nullable NSString *)email
7469
password:(nullable NSString *)password
7570
displayName:(nullable NSString *)displayName
76-
idToken:(nullable NSString *)idToken
7771
requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
7872
self = [super initWithEndpoint:kSignupNewUserEndpoint requestConfiguration:requestConfiguration];
7973
if (self) {
8074
_email = [email copy];
8175
_password = [password copy];
8276
_displayName = [displayName copy];
83-
_idToken = [idToken copy];
8477
_returnSecureToken = YES;
8578
}
8679
return self;
@@ -91,7 +84,6 @@ - (nullable instancetype)initWithRequestConfiguration:
9184
self = [self initWithEmail:nil
9285
password:nil
9386
displayName:nil
94-
idToken:nil
9587
requestConfiguration:requestConfiguration];
9688
return self;
9789
}
@@ -107,9 +99,6 @@ - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *_Nullable *_Nullable)
10799
if (_displayName) {
108100
postBody[kDisplayNameKey] = _displayName;
109101
}
110-
if (_idToken) {
111-
postBody[kIDToken] = _idToken;
112-
}
113102
if (_captchaResponse) {
114103
postBody[kCaptchaResponseKey] = _captchaResponse;
115104
}

FirebaseAuth/Sources/User/FIRUser.m

Lines changed: 12 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
#import "FirebaseAuth/Sources/Backend/RPC/FIRSetAccountInfoResponse.h"
4444
#import "FirebaseAuth/Sources/Backend/RPC/FIRSignInWithGameCenterRequest.h"
4545
#import "FirebaseAuth/Sources/Backend/RPC/FIRSignInWithGameCenterResponse.h"
46-
#import "FirebaseAuth/Sources/Backend/RPC/FIRSignUpNewUserRequest.h"
47-
#import "FirebaseAuth/Sources/Backend/RPC/FIRSignUpNewUserResponse.h"
4846
#import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyAssertionRequest.h"
4947
#import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyAssertionResponse.h"
5048
#import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyCustomTokenRequest.h"
@@ -63,9 +61,9 @@
6361
#import "FirebaseAuth/Sources/Utilities/FIRAuthWebUtils.h"
6462

6563
#if TARGET_OS_IOS
66-
#import "FirebaseAuth/Sources/AuthProvider/Phone/FIRPhoneAuthCredential_Internal.h"
6764
#import "FirebaseAuth/Sources/Public/FirebaseAuth/FIRPhoneAuthProvider.h"
68-
#import "FirebaseAuth/Sources/Utilities/FIRAuthRecaptchaVerifier.h"
65+
66+
#import "FirebaseAuth/Sources/AuthProvider/Phone/FIRPhoneAuthCredential_Internal.h"
6967
#endif
7068

7169
NS_ASSUME_NONNULL_BEGIN
@@ -584,6 +582,7 @@ - (void)setTokenService:(FIRSecureTokenService *)tokenService
584582
}
585583

586584
#pragma mark -
585+
587586
/** @fn updateEmail:password:callback:
588587
@brief Updates email address and/or password for the current user.
589588
@remarks May fail if there is already an email/password-based account for the same email
@@ -1080,109 +1079,6 @@ - (void)internalVerifyBeforeUpdateEmailWithNewEmail:(NSString *)newEmail
10801079
});
10811080
}
10821081

1083-
- (void)linkWithEmailPassword:(FIREmailPasswordAuthCredential *)credential
1084-
authResult:(FIRAuthDataResult *)authResult
1085-
completion:(nullable FIRAuthDataResultCallback)completion {
1086-
[self internalGetTokenWithCallback:^(NSString *_Nullable accessToken, NSError *_Nullable error) {
1087-
FIRAuthRequestConfiguration *requestConfiguration = self.auth.requestConfiguration;
1088-
FIRSignUpNewUserRequest *request =
1089-
[[FIRSignUpNewUserRequest alloc] initWithEmail:credential.email
1090-
password:credential.password
1091-
displayName:nil
1092-
idToken:accessToken
1093-
requestConfiguration:requestConfiguration];
1094-
FIRSignupNewUserCallback signUpNewUserCallback = ^(FIRSignUpNewUserResponse *_Nullable response,
1095-
NSError *_Nullable error) {
1096-
if (error) {
1097-
[self signOutIfTokenIsInvalidWithError:error];
1098-
callInMainThreadWithAuthDataResultAndError(completion, nil, error);
1099-
} else {
1100-
// Update the new token and refresh user info again.
1101-
self->_tokenService = [[FIRSecureTokenService alloc]
1102-
initWithRequestConfiguration:requestConfiguration
1103-
accessToken:response.IDToken
1104-
accessTokenExpirationDate:response.approximateExpirationDate
1105-
refreshToken:response.refreshToken];
1106-
1107-
[self internalGetTokenWithCallback:^(NSString *_Nullable accessToken,
1108-
NSError *_Nullable error) {
1109-
if (error) {
1110-
callInMainThreadWithAuthDataResultAndError(completion, nil, error);
1111-
return;
1112-
}
1113-
FIRGetAccountInfoRequest *getAccountInfoRequest =
1114-
[[FIRGetAccountInfoRequest alloc] initWithAccessToken:accessToken
1115-
requestConfiguration:requestConfiguration];
1116-
[FIRAuthBackend
1117-
getAccountInfo:getAccountInfoRequest
1118-
callback:^(FIRGetAccountInfoResponse *_Nullable response,
1119-
NSError *_Nullable error) {
1120-
if (error) {
1121-
[self signOutIfTokenIsInvalidWithError:error];
1122-
callInMainThreadWithAuthDataResultAndError(completion, nil, error);
1123-
return;
1124-
}
1125-
self.anonymous = NO;
1126-
[self updateWithGetAccountInfoResponse:response];
1127-
NSError *keychainError;
1128-
if (![self updateKeychain:&keychainError]) {
1129-
callInMainThreadWithAuthDataResultAndError(completion, nil, keychainError);
1130-
return;
1131-
}
1132-
[self signOutIfTokenIsInvalidWithError:error];
1133-
callInMainThreadWithAuthDataResultAndError(completion, authResult, nil);
1134-
}];
1135-
}];
1136-
}
1137-
};
1138-
1139-
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST && (!defined(TARGET_OS_VISION) || !TARGET_OS_VISION)
1140-
if ([[FIRAuthRecaptchaVerifier sharedRecaptchaVerifier:self.auth]
1141-
enablementStatusForProvider:FIRAuthRecaptchaProviderPassword]) {
1142-
[[FIRAuthRecaptchaVerifier sharedRecaptchaVerifier:self.auth]
1143-
injectRecaptchaFields:request
1144-
provider:FIRAuthRecaptchaProviderPassword
1145-
action:FIRAuthRecaptchaActionSignUpPassword
1146-
completion:^(
1147-
FIRIdentityToolkitRequest<FIRAuthRPCRequest> *requestWithRecaptchaToken) {
1148-
[FIRAuthBackend
1149-
signUpNewUser:(FIRSignUpNewUserRequest *)requestWithRecaptchaToken
1150-
callback:signUpNewUserCallback];
1151-
}];
1152-
} else {
1153-
[FIRAuthBackend
1154-
signUpNewUser:request
1155-
callback:^(FIRSignUpNewUserResponse *_Nullable response, NSError *_Nullable error) {
1156-
if (!error) {
1157-
signUpNewUserCallback(response, nil);
1158-
return;
1159-
}
1160-
NSError *underlyingError = [error.userInfo objectForKey:NSUnderlyingErrorKey];
1161-
if (error.code == FIRAuthErrorCodeInternalError &&
1162-
[[underlyingError.userInfo
1163-
objectForKey:FIRAuthErrorUserInfoDeserializedResponseKey][@"message"]
1164-
hasPrefix:kMissingRecaptchaTokenErrorPrefix]) {
1165-
[[FIRAuthRecaptchaVerifier sharedRecaptchaVerifier:self.auth]
1166-
injectRecaptchaFields:request
1167-
provider:FIRAuthRecaptchaProviderPassword
1168-
action:FIRAuthRecaptchaActionSignUpPassword
1169-
completion:^(FIRIdentityToolkitRequest<FIRAuthRPCRequest>
1170-
*requestWithRecaptchaToken) {
1171-
[FIRAuthBackend signUpNewUser:(FIRSignUpNewUserRequest *)
1172-
requestWithRecaptchaToken
1173-
callback:signUpNewUserCallback];
1174-
}];
1175-
} else {
1176-
signUpNewUserCallback(nil, error);
1177-
}
1178-
}];
1179-
}
1180-
#else
1181-
[FIRAuthBackend signUpNewUser:request callback:signUpNewUserCallback];
1182-
#endif
1183-
}];
1184-
}
1185-
11861082
- (void)linkWithCredential:(FIRAuthCredential *)credential
11871083
completion:(nullable FIRAuthDataResultCallback)completion {
11881084
dispatch_async(FIRAuthGlobalWorkQueue(), ^{
@@ -1202,9 +1098,15 @@ - (void)linkWithCredential:(FIRAuthCredential *)credential
12021098
FIREmailPasswordAuthCredential *emailPasswordCredential =
12031099
(FIREmailPasswordAuthCredential *)credential;
12041100
if (emailPasswordCredential.password) {
1205-
[self linkWithEmailPassword:emailPasswordCredential
1206-
authResult:result
1207-
completion:completion];
1101+
[self updateEmail:emailPasswordCredential.email
1102+
password:emailPasswordCredential.password
1103+
callback:^(NSError *error) {
1104+
if (error) {
1105+
callInMainThreadWithAuthDataResultAndError(completion, nil, error);
1106+
} else {
1107+
callInMainThreadWithAuthDataResultAndError(completion, result, nil);
1108+
}
1109+
}];
12081110
} else {
12091111
[self internalGetTokenWithCallback:^(NSString *_Nullable accessToken,
12101112
NSError *_Nullable error) {

FirebaseAuth/Sources/Utilities/FIRAuthErrorUtils.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@
2323

2424
NS_ASSUME_NONNULL_BEGIN
2525

26-
/** @var kMissingRecaptchaTokenErrorPrefix
27-
@brief The prefix of the error message of missing recaptcha token during authenticating.
28-
*/
29-
static NSString *const kMissingRecaptchaTokenErrorPrefix = @"MISSING_RECAPTCHA_TOKEN";
30-
3126
/** @class FIRAuthErrorUtils
3227
@brief Utility class used to construct @c NSError instances.
3328
*/

FirebaseAuth/Tests/Unit/FIRAuthTests.m

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,6 @@
138138
*/
139139
static NSString *const kDisplayName = @"User Doe";
140140

141-
/** @var kIDToken
142-
@brief The fake id token.
143-
*/
144-
static NSString *const kIDToken = @"IDToken";
145-
146141
/** @var kFakeGivenName
147142
@brief The fake user given name.
148143
*/
@@ -1823,7 +1818,6 @@ - (void)testCreateUserWithEmailPasswordWithRecaptchaVerificationSuccess {
18231818
[[FIRSignUpNewUserRequest alloc] initWithEmail:kEmail
18241819
password:kFakePassword
18251820
displayName:kDisplayName
1826-
idToken:kIDToken
18271821
requestConfiguration:[FIRAuth auth].requestConfiguration];
18281822
[constRequestWithRecaptchaToken injectRecaptchaFields:kFakeRecaptchaResponse
18291823
recaptchaVersion:kFakeRecaptchaVersion];
@@ -1873,7 +1867,6 @@ - (void)testCreateUserWithEmailPasswordWithRecaptchaFallbackSuccess {
18731867
[[FIRSignUpNewUserRequest alloc] initWithEmail:kEmail
18741868
password:kFakePassword
18751869
displayName:kDisplayName
1876-
idToken:kIDToken
18771870
requestConfiguration:[FIRAuth auth].requestConfiguration];
18781871
[constRequestWithRecaptchaToken injectRecaptchaFields:kFakeRecaptchaResponse
18791872
recaptchaVersion:kFakeRecaptchaVersion];

FirebaseAuth/Tests/Unit/FIRSignUpNewUserRequestTests.m

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,6 @@
6060
*/
6161
static NSString *const kTestDisplayName = @"DisplayName";
6262

63-
/** @var kIDTokenKey
64-
@brief the name of the "kIDTokenKey" property in the request.
65-
*/
66-
static NSString *const kIDTokenKey = @"idToken";
67-
68-
/** @var kTestIDToken
69-
@brief Testing id token.
70-
*/
71-
static NSString *const kTestIDToken = @"testIDToken";
72-
7363
/** @var kPasswordKey
7464
@brief the name of the "password" property in the request.
7565
*/
@@ -177,7 +167,6 @@ - (void)testSignUpNewUserRequestNotAnonymous {
177167
[[FIRSignUpNewUserRequest alloc] initWithEmail:kTestEmail
178168
password:kTestPassword
179169
displayName:kTestDisplayName
180-
idToken:kTestIDToken
181170
requestConfiguration:_requestConfiguration];
182171
[FIRAuthBackend
183172
signUpNewUser:request
@@ -201,7 +190,6 @@ - (void)testSignUpNewUserRequestOptionalFields {
201190
[[FIRSignUpNewUserRequest alloc] initWithEmail:kTestEmail
202191
password:kTestPassword
203192
displayName:kTestDisplayName
204-
idToken:kTestIDToken
205193
requestConfiguration:_requestConfiguration];
206194
request.captchaResponse = kTestCaptchaResponse;
207195
request.clientType = kTestClientType;

FirebaseAuth/Tests/Unit/FIRSignUpNewUserResponseTests.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ - (void)testSuccessfulSignUp {
159159
[[FIRSignUpNewUserRequest alloc] initWithEmail:kTestEmail
160160
password:kTestPassword
161161
displayName:kTestDisplayName
162-
idToken:kTestIDToken
163162
requestConfiguration:_requestConfiguration];
164163

165164
__block BOOL callbackInvoked;

0 commit comments

Comments
 (0)