aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firebase/Auth
diff options
context:
space:
mode:
authorGravatar Zsika Phillip <protocol86@users.noreply.github.com>2018-04-12 16:54:22 -0700
committerGravatar Paul Beusterien <paulbeusterien@google.com>2018-04-12 16:54:22 -0700
commitac969c721a129e888177756fa2a6ae52af0dd04a (patch)
treefa5fab58038bc0e2a9f9927b905bff38e4fac480 /Firebase/Auth
parent8876622b6fcebc21672bc263666b858b7e152b45 (diff)
Fixes typo that causes token parsing to break (#1076)
Diffstat (limited to 'Firebase/Auth')
-rw-r--r--Firebase/Auth/Source/FIRUser.m18
1 files changed, 12 insertions, 6 deletions
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 =