Skip to content

Commit c1bec38

Browse files
extract errorMessage directly from response in case of returnIDPCredential=YES
Fix #2522. In this case, the server returns an 200 without an error like the following: ``` [response data:] { "error": { "code": 400, "message": "FEDERATED_USER_ID_ALREADY_LINKED", "errors": [ { "message": "FEDERATED_USER_ID_ALREADY_LINKED", "domain": "global", "reason": "invalid" } ] } } ``` Rather, it is directly enclosed in the response with an errorMessage without a structure: ``` [response data:] { key: value ... "errorMessage": "FEDERATED_USER_ID_ALREADY_LINKED", "kind": "identitytoolkit#VerifyAssertionResponse" } ```
1 parent ee8d90a commit c1bec38

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

Firebase/Auth/Source/RPCs/FIRAuthBackend.m

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@
128128
*/
129129
static NSString *const kErrorMessageKey = @"message";
130130

131+
/** @var kReturnIDPCredentialErrorMessageKey
132+
@brief The key for "errorMessage" value in JSON responses from the server, In case
133+
returnIDPCredential of a verifyAssertion request is set to @YES.
134+
*/
135+
static NSString *const kReturnIDPCredentialErrorMessageKey = @"errorMessage";
136+
131137
/** @var kUserNotFoundErrorMessage
132138
@brief This is the error message returned when the user is not found, which means the user
133139
account has been deleted given the token was once valid.
@@ -925,18 +931,15 @@ - (void)postWithRequest:(id<FIRAuthRPCRequest>)request
925931
if ([request isKindOfClass:[FIRVerifyAssertionRequest class]]) {
926932
FIRVerifyAssertionRequest *verifyAssertionRequest = (FIRVerifyAssertionRequest *)request;
927933
if (verifyAssertionRequest.returnIDPCredential) {
928-
NSDictionary *errorDictionary = dictionary[kErrorKey];
929-
if ([errorDictionary isKindOfClass:[NSDictionary class]]) {
930-
id<NSObject> errorMessage = errorDictionary[kErrorMessageKey];
931-
if ([errorMessage isKindOfClass:[NSString class]]) {
932-
NSString *errorString = (NSString *)errorMessage;
933-
NSError *clientError = [[self class] clientErrorWithServerErrorMessage:errorString
934-
errorDictionary:errorDictionary
935-
response:response];
936-
if (clientError) {
937-
callback(clientError);
938-
return;
939-
}
934+
NSString *errorMessage = dictionary[kReturnIDPCredentialErrorMessageKey];
935+
if ([errorMessage isKindOfClass:[NSString class]]) {
936+
NSString *errorString = (NSString *)errorMessage;
937+
NSError *clientError = [[self class] clientErrorWithServerErrorMessage:errorString
938+
errorDictionary:@{}
939+
response:response];
940+
if (clientError) {
941+
callback(clientError);
942+
return;
940943
}
941944
}
942945
}

0 commit comments

Comments
 (0)