@@ -139,7 +139,6 @@ - (BFTask *)refresh {
139
139
self.secretKey = wifResponse.credentials .secretAccessKey ;
140
140
self.sessionKey = wifResponse.credentials .sessionToken ;
141
141
self.expiration = wifResponse.credentials .expiration ;
142
- [self .keychain synchronize ];
143
142
}
144
143
} else {
145
144
// reset the values for the credentials
@@ -148,7 +147,6 @@ - (BFTask *)refresh {
148
147
self.secretKey = nil ;
149
148
self.sessionKey = nil ;
150
149
self.expiration = nil ;
151
- [self .keychain synchronize ];
152
150
}
153
151
}
154
152
@@ -320,7 +318,7 @@ + (instancetype)credentialsWithRegionType:(AWSRegionType)regionType
320
318
321
319
+ (instancetype )credentialsWithRegionType : (AWSRegionType)regionType
322
320
identityPoolId : (NSString *)identityPoolId {
323
-
321
+
324
322
return [AWSCognitoCredentialsProvider credentialsWithRegionType: regionType
325
323
identityId: nil
326
324
identityPoolId: identityPoolId
@@ -331,35 +329,35 @@ + (instancetype)credentialsWithRegionType:(AWSRegionType)regionType
331
329
identityId : (NSString *)identityId
332
330
identityPoolId : (NSString *)identityPoolId
333
331
logins : (NSDictionary *)logins {
334
-
332
+
335
333
AWSCognitoCredentialsProvider *credentials = [[AWSCognitoCredentialsProvider alloc ] initWithRegionType: regionType
336
334
identityId: identityId
337
335
identityPoolId: identityPoolId
338
336
logins: logins];
339
337
return credentials;
340
-
338
+
341
339
}
342
340
343
341
344
342
- (instancetype )initWithRegionType : (AWSRegionType)regionType
345
343
identityId : (NSString *)identityId
346
344
identityPoolId : (NSString *)identityPoolId
347
345
logins : (NSDictionary *)logins {
348
-
346
+
349
347
AWSEnhancedCognitoIdentityProvider *identityProvider = [[AWSEnhancedCognitoIdentityProvider alloc ]
350
- initWithRegionType: regionType
351
- identityId: identityId
352
- identityPoolId: identityPoolId
353
- logins: logins];
354
-
355
-
348
+ initWithRegionType: regionType
349
+ identityId: identityId
350
+ identityPoolId: identityPoolId
351
+ logins: logins];
352
+
353
+
356
354
AWSCognitoCredentialsProvider *credentials = [[AWSCognitoCredentialsProvider alloc ] initWithRegionType: regionType
357
355
identityProvider: identityProvider
358
356
unauthRoleArn: nil
359
357
authRoleArn: nil ];
360
-
358
+
361
359
credentials.useEnhancedFlow = YES ;
362
-
360
+
363
361
return credentials;
364
362
}
365
363
@@ -407,7 +405,6 @@ - (instancetype)initWithRegionType:(AWSRegionType)regionType
407
405
// If the identity provider has an identity id, use it
408
406
if (identityProvider.identityId ) {
409
407
_keychain[AWSCredentialsProviderKeychainIdentityId] = identityProvider.identityId ;
410
- [_keychain synchronize ];
411
408
}
412
409
// Otherwise push whatever is in the keychain down to the identity provider
413
410
else {
@@ -418,9 +415,9 @@ - (instancetype)initWithRegionType:(AWSRegionType)regionType
418
415
AWSServiceConfiguration *configuration = [AWSServiceConfiguration configurationWithRegion: regionType
419
416
credentialsProvider: credentialsProvider];
420
417
421
- _sts = [[AWSSTS new ] initWithConfiguration: configuration];
418
+ _sts = [[AWSSTS alloc ] initWithConfiguration: configuration];
422
419
_cib = [[AWSCognitoIdentity new ] initWithConfiguration: configuration];
423
-
420
+
424
421
// Use the new flow if we explictly created an ehancedProvider
425
422
// or if the roles are both nil (developer authenticated identities flow)
426
423
_useEnhancedFlow = [identityProvider isKindOfClass: [AWSEnhancedCognitoIdentityProvider class ]] || ((unauthRoleArn == nil ) && (authRoleArn == nil ));
@@ -434,14 +431,14 @@ - (BFTask *)getCredentialsWithSTS:(NSString *)token authenticated:(BOOL)auth {
434
431
if (auth) {
435
432
roleArn = self.authRoleArn ;
436
433
}
437
-
434
+
438
435
if (roleArn == nil ) {
439
436
return [BFTask taskWithError: [NSError errorWithDomain: AWSCognitoCredentialsProviderErrorDomain
440
437
code: AWSCognitoCredentialsProviderInvalidConfiguration
441
438
userInfo: @{NSLocalizedDescriptionKey : @" Required role ARN is nil" }]
442
439
];
443
440
}
444
-
441
+
445
442
AWSSTSAssumeRoleWithWebIdentityRequest *webIdentityRequest = [AWSSTSAssumeRoleWithWebIdentityRequest new ];
446
443
webIdentityRequest.roleArn = roleArn;
447
444
webIdentityRequest.webIdentityToken = token;
@@ -454,21 +451,20 @@ - (BFTask *)getCredentialsWithSTS:(NSString *)token authenticated:(BOOL)auth {
454
451
self.secretKey = webIdentityResponse.credentials .secretAccessKey ;
455
452
self.sessionKey = webIdentityResponse.credentials .sessionToken ;
456
453
self.expiration = webIdentityResponse.credentials .expiration ;
457
- [self .keychain synchronize ];
458
454
}
459
455
} else {
460
456
// reset the values for the credentials
461
457
[self clearCredentials ];
462
458
}
463
-
459
+
464
460
return task;
465
461
}];
466
462
}
467
463
468
464
- (BFTask *)getCredentialsWithCognito : (NSString *)token authenticated : (BOOL )auth {
469
465
// Grab a reference to our provider in case it changes out from under us
470
466
id <AWSCognitoIdentityProvider> providerRef = self.identityProvider ;
471
-
467
+
472
468
AWSCognitoIdentityGetCredentialsForIdentityInput *getCredentialsInput = [AWSCognitoIdentityGetCredentialsForIdentityInput new ];
473
469
getCredentialsInput.identityId = self.identityId ;
474
470
if (token) {
@@ -477,26 +473,26 @@ - (BFTask *)getCredentialsWithCognito:(NSString *)token authenticated:(BOOL)auth
477
473
else {
478
474
getCredentialsInput.logins = self.logins ;
479
475
}
480
-
481
-
476
+
477
+
482
478
return [[[self .cib getCredentialsForIdentity: getCredentialsInput] continueWithBlock: ^id (BFTask *task) {
483
479
// When an invalid identityId is cached in the keychain for auth,
484
480
// we will refresh the identityId and try to get credentials token again.
485
481
if (task.error ) {
486
482
AWSLogError (@" GetCredentialsForIdentity failed. Error is [%@ ]" , task.error );
487
-
483
+
488
484
// If it's auth or we caught a not found or validation error
489
485
// we want to reset the identity id, otherwise, just return
490
486
// the error to our caller
491
487
if (!(auth || [AWSCognitoCredentialsProvider shouldResetIdentityId: task.error])) {
492
488
return task;
493
489
}
494
-
490
+
495
491
AWSLogVerbose (@" Resetting identity Id and calling getIdentityId" );
496
492
// if it's auth, reset id and refetch
497
493
self.identityId = nil ;
498
494
providerRef.identityId = nil ;
499
-
495
+
500
496
return [[providerRef getIdentityId ] continueWithSuccessBlock: ^id (BFTask *task) {
501
497
// This should never happen, but just in case
502
498
if (!providerRef.identityId ) {
@@ -508,14 +504,14 @@ - (BFTask *)getCredentialsWithCognito:(NSString *)token authenticated:(BOOL)auth
508
504
];
509
505
}
510
506
self.identityId = providerRef.identityId ;
511
-
507
+
512
508
AWSLogVerbose (@" Retrying GetCredentialsForIdentity" );
513
-
509
+
514
510
// retry get credentials
515
511
AWSCognitoIdentityGetCredentialsForIdentityInput *getCredentialsRetry = [AWSCognitoIdentityGetCredentialsForIdentityInput new ];
516
512
getCredentialsRetry.identityId = self.identityId ;
517
513
getCredentialsRetry.logins = self.logins ;
518
-
514
+
519
515
return [self .cib getCredentialsForIdentity: getCredentialsRetry];
520
516
}];
521
517
}
@@ -529,10 +525,9 @@ - (BFTask *)getCredentialsWithCognito:(NSString *)token authenticated:(BOOL)auth
529
525
self.secretKey = getCredentialsResponse.credentials .secretKey ;
530
526
self.sessionKey = getCredentialsResponse.credentials .sessionToken ;
531
527
self.expiration = getCredentialsResponse.credentials .expiration ;
532
- [self .keychain synchronize ];
533
-
528
+
534
529
NSString *identityIdFromResponse = getCredentialsResponse.identityId ;
535
-
530
+
536
531
// This should never happen, but just in case
537
532
if (!identityIdFromResponse) {
538
533
AWSLogError (@" identityId from getCredentialsForIdentity is nil" );
@@ -541,12 +536,12 @@ - (BFTask *)getCredentialsWithCognito:(NSString *)token authenticated:(BOOL)auth
541
536
userInfo: @{NSLocalizedDescriptionKey : @" identityId shouldn't be nil" }]
542
537
];
543
538
}
544
-
539
+
545
540
if (![self .identityId isEqualToString: identityIdFromResponse]) {
546
541
self.identityId = identityIdFromResponse;
547
542
providerRef.identityId = identityIdFromResponse;
548
543
}
549
-
544
+
550
545
return [BFTask taskWithResult: self .identityId];
551
546
}];
552
547
}
@@ -569,8 +564,7 @@ - (BFTask *)refresh {
569
564
}
570
565
571
566
self.identityId = providerRef.identityId ;
572
- [self .keychain synchronize ];
573
-
567
+
574
568
if (self.useEnhancedFlow ) {
575
569
return [self getCredentialsWithCognito: providerRef.token authenticated: [providerRef isAuthenticated ]];
576
570
}
@@ -612,7 +606,6 @@ - (BFTask *)getIdentityId {
612
606
];
613
607
}
614
608
self.identityId = providerRef.identityId ;
615
- [self .keychain synchronize ];
616
609
return task;
617
610
}];
618
611
}
@@ -631,7 +624,6 @@ - (void)clearCredentials {
631
624
self.secretKey = nil ;
632
625
self.sessionKey = nil ;
633
626
self.expiration = nil ;
634
- [self .keychain synchronize ];
635
627
}
636
628
}
637
629
0 commit comments