Skip to content
This repository has been archived by the owner on Oct 12, 2018. It is now read-only.

Commit

Permalink
fix (AWSRNCognitoCredentials.m) transport dates as ISO 8601 strings
Browse files Browse the repository at this point in the history
  • Loading branch information
pentateu committed Sep 20, 2016
1 parent 236d990 commit 152deb6
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion Core/ios/Core/AWSRNCognitoCredentials.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ @implementation AWSRNCognitoCredentials{
NSMutableDictionary *options;
AWSCognitoCredentialsProvider *credentialProvider;
AWSRNHelper *helper;
NSDateFormatter* _dateFormatterISO8601;
}

@synthesize bridge = _bridge;
@synthesize methodQueue = _methodQueue;
//@synthesize methodQueue = _methodQueue;

typedef void (^ Block)(id, int);

Expand Down Expand Up @@ -56,6 +58,16 @@ -(instancetype)init{
[credentialProvider clearKeychain];
}

-(NSDateFormatter*) dateFormatterISO8601 {
if(! _dateFormatterISO8601){
_dateFormatterISO8601 = [[NSDateFormatter alloc] init];
[_dateFormatterISO8601 setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]];
[_dateFormatterISO8601 setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];
}
return _dateFormatterISO8601;
}


RCT_EXPORT_METHOD(getCredentialsAsync:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject){

//start a separate thread for this to avoid blocking the component queue, since
Expand All @@ -79,7 +91,17 @@ -(instancetype)init{
}
else {
AWSCredentials *cred = (AWSCredentials*) task.result;
NSDictionary *dict = @{@"AccessKey":cred.accessKey,@"SecretKey":cred.secretKey,@"SessionKey":cred.sessionKey,@"Expiration":cred.expiration};

//using ISO 8601 to transport the dates over the wire.
//easier to debug then passing the data as a number
//javascript new Date(dateAsString) function takes an ISO 8601 string :)
NSString* dateAsISO8601String = [self.dateFormatterISO8601 stringFromDate:cred.expiration];

NSDictionary *dict = @{
@"AccessKey":cred.accessKey,
@"SecretKey":cred.secretKey,
@"SessionKey":cred.sessionKey,
@"Expiration":dateAsISO8601String};
resolve(dict);
}
return nil;
Expand Down

0 comments on commit 152deb6

Please sign in to comment.