diff --git a/Source/ARTTokenParams.m b/Source/ARTTokenParams.m index de4e73019..4f59bb772 100644 --- a/Source/ARTTokenParams.m +++ b/Source/ARTTokenParams.m @@ -153,8 +153,9 @@ - (ARTTokenRequest *)sign:(NSString *)key withNonce:(NSString *)nonce { NSString *keyName = keyComponents[0]; NSString *keySecret = keyComponents[1]; NSString *clientId = self.clientId ? self.clientId : @""; + NSTimeInterval ttl = self.ttl ? self.ttl : [ARTDefault ttl]; - NSString *signText = [NSString stringWithFormat:@"%@\n%lld\n%@\n%@\n%lld\n%@\n", keyName, timeIntervalToMilliseconds(self.ttl), self.capability, clientId, dateToMilliseconds(self.timestamp), nonce]; + NSString *signText = [NSString stringWithFormat:@"%@\n%lld\n%@\n%@\n%lld\n%@\n", keyName, timeIntervalToMilliseconds(ttl), self.capability, clientId, dateToMilliseconds(self.timestamp), nonce]; NSString *mac = hmacForDataAndKey([signText dataUsingEncoding:NSUTF8StringEncoding], [keySecret dataUsingEncoding:NSUTF8StringEncoding]); return [[ARTTokenRequest alloc] initWithTokenParams:self keyName:keyName nonce:nonce mac:mac]; diff --git a/Source/ARTTokenRequest.m b/Source/ARTTokenRequest.m index 999170ce5..e82f45374 100644 --- a/Source/ARTTokenRequest.m +++ b/Source/ARTTokenRequest.m @@ -9,12 +9,13 @@ #import "ARTTokenRequest.h" #import "ARTTokenParams.h" #import "ARTAuth+Private.h" +#import "ARTDefault.h" @implementation ARTTokenRequest - (instancetype)initWithTokenParams:(ARTTokenParams *)tokenParams keyName:(NSString *)keyName nonce:(NSString *)nonce mac:(NSString *)mac { if (self = [super init]) { - self.ttl = tokenParams.ttl; + self.ttl = tokenParams.ttl ? tokenParams.ttl : [ARTDefault ttl]; self.capability = tokenParams.capability; self.clientId = tokenParams.clientId; self.timestamp = tokenParams.timestamp;