aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firebase
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:57:55 -0700
commitc875e432836de36483e2dca9a8a85bfd90bc6f52 (patch)
treef8a9036044f18291ef41f34cef65c018c904f2b8 /Firebase
parente29010caf2478c7b6d4cbb4a3fe8238f36b4fe22 (diff)
Fixes typo that causes token parsing to break (#1076)
Diffstat (limited to 'Firebase')
-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 =