Skip to content

Commit

Permalink
Merge pull request #1838 from ably/fix/1837-token-request-from-json-fix
Browse files Browse the repository at this point in the history
[SDK-3948] Use safe json dictionary value extraction.
  • Loading branch information
maratal authored Nov 25, 2023
2 parents c10bcc0 + b0fd1b4 commit 775330e
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions Source/ARTTokenRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import "ARTTokenParams.h"
#import "ARTAuth+Private.h"
#import "ARTDefault.h"
#import "ARTNSDictionary+ARTDictionaryUtil.h"

@implementation ARTTokenRequest

Expand Down Expand Up @@ -37,17 +38,19 @@ + (ARTTokenRequest *_Nullable)fromJson:(id<ARTJsonCompatible>)json error:(NSErro
return nil;
}

ARTTokenParams *tokenParams = [[ARTTokenParams alloc] initWithClientId:dict[@"clientId"]];
ARTTokenParams *tokenParams = [[ARTTokenParams alloc] initWithClientId:[dict artString:@"clientId"]];

ARTTokenRequest *tokenRequest = [[ARTTokenRequest alloc] initWithTokenParams:tokenParams
keyName:dict[@"keyName"]
nonce:dict[@"nonce"]
mac:dict[@"mac"]];
tokenRequest.clientId = dict[@"clientId"];
tokenRequest.ttl = dict[@"ttl"] ? [NSNumber numberWithDouble:millisecondsToTimeInterval([dict[@"ttl"] unsignedLongLongValue])] : nil;
tokenRequest.capability = dict[@"capability"];
tokenRequest.timestamp = [NSDate dateWithTimeIntervalSince1970:[dict[@"timestamp"] doubleValue] / 1000];
keyName:[dict artString:@"keyName"]
nonce:[dict artString:@"nonce"]
mac:[dict artString:@"mac"]];
tokenRequest.clientId = [dict artString:@"clientId"];
tokenRequest.capability = [dict artString:@"capability"];
tokenRequest.timestamp = [NSDate dateWithTimeIntervalSince1970:[[dict artNumber:@"timestamp"] doubleValue] / 1000];

NSNumber *ttlNumber = [dict artNumber:@"ttl"];
tokenRequest.ttl = ttlNumber != nil ? [NSNumber numberWithDouble:millisecondsToTimeInterval([ttlNumber unsignedLongLongValue])] : nil;

return tokenRequest;
}

Expand Down

0 comments on commit 775330e

Please sign in to comment.