Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Review [Draft]
  • Loading branch information
ncooke3 committed May 5, 2021
commit eefcbbc0537862867ce3ebddb8b9aea84d992d1e
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ - (instancetype)initWithAPIService:(id<FIRAppCheckAPIServiceProtocol>)APIService
});
}

#pragma mark - Helpers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: Seems we can be more specific here, e.g. #pragma mark - Challenge response parsing


- (FBLPromise<NSData *> *)randomChallengeWithAPIResponse:(GULURLSessionDataResponse *)response {
return [FBLPromise onQueue:[self defaultQueue] do:^id _Nullable{
NSError *error;
Expand Down Expand Up @@ -112,25 +114,7 @@ - (NSData *)randomChallengeFromResponseBody:(NSData *)response
return nil;
}

NSString *timeToLiveString = responseDict[@"ttl"];
if (![challenge isKindOfClass:[NSString class]] || challenge.length <= 0) {
FIRAppCheckSetErrorToPointer(
[FIRAppCheckErrorUtil appCheckTokenResponseErrorWithMissingField:@"ttl"], outError);
return nil;
}

// Expect a string like "3600s" representing a time interval in seconds.
NSString *timeToLiveValueString = [timeToLiveString stringByReplacingOccurrencesOfString:@"s"
withString:@""];
NSTimeInterval secondsToLive = timeToLiveValueString.doubleValue;

if (secondsToLive == 0) {
FIRAppCheckSetErrorToPointer(
[FIRAppCheckErrorUtil appCheckTokenResponseErrorWithMissingField:@"ttl"], outError);
return nil;
}

NSData *randomChallenge = [challenge dataUsingEncoding:NSUTF8StringEncoding];
NSData *randomChallenge = [[NSData alloc] initWithBase64EncodedString:challenge options:0];
return randomChallenge;
}

Expand Down