From ac969c721a129e888177756fa2a6ae52af0dd04a Mon Sep 17 00:00:00 2001 From: Zsika Phillip Date: Thu, 12 Apr 2018 16:54:22 -0700 Subject: Fixes typo that causes token parsing to break (#1076) --- Firebase/Auth/Source/FIRUser.m | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'Firebase/Auth') diff --git a/Firebase/Auth/Source/FIRUser.m b/Firebase/Auth/Source/FIRUser.m index 1b10976..0a0a664 100644 --- a/Firebase/Auth/Source/FIRUser.m +++ b/Firebase/Auth/Source/FIRUser.m @@ -836,23 +836,29 @@ static void callInMainThreadWithAuthDataResultAndError( NSMutableString *tokenPayload = [[NSMutableString alloc] initWithString:tokenStringArray[1]]; // Pad the token payload with "=" signs if the payload's length is not a multple of 4. - int remainder = tokenPayload.length % 4 != 0; - if (remainder) { - while (remainder --) { - [tokenPayload appendString:@"="]; - } + while ((tokenPayload.length % 4) != 0) { + [tokenPayload appendFormat:@"="]; } NSData *decodedTokenPayloadData = [[NSData alloc] initWithBase64EncodedString:tokenPayload options:NSDataBase64DecodingIgnoreUnknownCharacters]; + if (!decodedTokenPayloadData) { + *error = [FIRAuthErrorUtils unexpectedResponseWithDeserializedResponse:token]; + return nil; + } NSDictionary *tokenPayloadDictionary = [NSJSONSerialization JSONObjectWithData:decodedTokenPayloadData - options:kNilOptions + options:NSJSONReadingMutableContainers|NSJSONReadingAllowFragments error:error]; if (error) { return nil; } + if (!tokenPayloadDictionary) { + *error = [FIRAuthErrorUtils unexpectedResponseWithDeserializedResponse:token]; + return nil; + } + NSDate *expDate = [NSDate dateWithTimeIntervalSinceNow:[tokenPayloadDictionary[@"exp"] doubleValue]]; NSDate *authDate = -- cgit v1.2.3