Add generation of limited-use tokens with a TTL of 5 mins (#11)

This commit is contained in:
Andrew Heard authored and GitHub committed 2023-08-22 12:56:00 -04:00
1 parent 2b623874c9
commit 8d0bdd3f24
20 files changed
+482 -144

No files matched your search

@@ -36,6 +36,7 @@ NS_ASSUME_NONNULL_BEGIN
static NSString *const kContentTypeKey = @"Content-Type";
static NSString *const kJSONContentType = @"application/json";
static NSString *const kDebugTokenField = @"debug_token";
static NSString *const kLimitedUseField = @"limited_use";
@interface GACAppCheckDebugProviderAPIService ()
@@ -59,12 +60,13 @@ static NSString *const kDebugTokenField = @"debug_token";
#pragma mark - Public API
- (FBLPromise<GACAppCheckToken *> *)appCheckTokenWithDebugToken:(NSString *)debugToken {
- (FBLPromise<GACAppCheckToken *> *)appCheckTokenWithDebugToken:(NSString *)debugToken
limitedUse:(BOOL)limitedUse {
NSString *URLString = [NSString
stringWithFormat:@"%@/%@:exchangeDebugToken", self.APIService.baseURL, self.resourceName];
NSURL *URL = [NSURL URLWithString:URLString];
return [self HTTPBodyWithDebugToken:debugToken]
return [self HTTPBodyWithDebugToken:debugToken limitedUse:limitedUse]
.then(^FBLPromise<GULURLSessionDataResponse *> *(NSData *HTTPBody) {
return [self.APIService sendRequestWithURL:URL
HTTPMethod:@"POST"
@@ -78,7 +80,8 @@ static NSString *const kDebugTokenField = @"debug_token";
#pragma mark - Helpers
- (FBLPromise<NSData *> *)HTTPBodyWithDebugToken:(NSString *)debugToken {
- (FBLPromise<NSData *> *)HTTPBodyWithDebugToken:(NSString *)debugToken
limitedUse:(BOOL)limitedUse {
if (debugToken.length <= 0) {
FBLPromise *rejectedPromise = [FBLPromise pendingPromise];
[rejectedPromise
@@ -89,10 +92,13 @@ static NSString *const kDebugTokenField = @"debug_token";
return [FBLPromise onQueue:[self backgroundQueue]
do:^id _Nullable {
NSError *encodingError;
NSData *payloadJSON = [NSJSONSerialization
dataWithJSONObject:@{kDebugTokenField : debugToken}
options:0
error:&encodingError];
NSData *payloadJSON =
[NSJSONSerialization dataWithJSONObject:@{
kDebugTokenField : debugToken,
kLimitedUseField : @(limitedUse)
}
options:0
error:&encodingError];
if (payloadJSON != nil) {
return payloadJSON;