Skip to content

Commit

Permalink
The AWS Mobile SDK for iOS 2.0.12.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yosuke Matsuda committed Nov 6, 2014
1 parent 3ec23f9 commit 7e9bcb9
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 45 deletions.
3 changes: 2 additions & 1 deletion AWSCore/Authentication/AWSCredentialsProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ typedef NS_ENUM(NSInteger, AWSCognitoCredentialsProviderErrorType) {
@property (nonatomic, strong, readonly) NSString *secretKey;
@property (nonatomic, strong, readonly) NSString *sessionKey;
@property (nonatomic, strong, readonly) NSDate *expiration;
@property (nonatomic, strong, readonly) id<AWSCognitoIdentityProvider> identityProvider;

@property (nonatomic, strong) id<AWSCognitoIdentityProvider> identityProvider;

@property (nonatomic, strong, readonly) NSString *identityId;
@property (nonatomic, strong, readonly) NSString *identityPoolId;
Expand Down
39 changes: 24 additions & 15 deletions AWSCore/Authentication/AWSCredentialsProvider.m
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,6 @@ - (instancetype)initWithRegionType:(AWSRegionType)regionType
authRoleArn:(NSString *)authRoleArn
logins:(NSDictionary *)logins {

// check for a stored identity if one isn't explicitly set
if (!identityId) {
UICKeyChainStore *keychain = [UICKeyChainStore keyChainStoreWithService:[NSString stringWithFormat:@"%@.%@.%@", [NSBundle mainBundle].bundleIdentifier, [AWSCognitoCredentialsProvider class], identityPoolId]];
identityId = keychain[AWSCredentialsProviderKeychainIdentityId];
}

AWSBasicCognitoIdentityProvider *identityProvider = [[AWSBasicCognitoIdentityProvider alloc]
initWithRegionType:regionType
identityId:identityId
Expand Down Expand Up @@ -362,10 +356,16 @@ - (instancetype)initWithRegionType:(AWSRegionType)regionType

// initialize keychain - name spaced by app bundle and identity pool id
_keychain = [UICKeyChainStore keyChainStoreWithService:[NSString stringWithFormat:@"%@.%@.%@", [NSBundle mainBundle].bundleIdentifier, [AWSCognitoCredentialsProvider class], identityProvider.identityPoolId]];

// If the identity provider has an identity id, use it
if (identityProvider.identityId) {
_keychain[AWSCredentialsProviderKeychainIdentityId] = identityProvider.identityId;
[_keychain synchronize];
}
// Otherwise push whatever is in the keychain down to the identity provider
else {
identityProvider.identityId = _keychain[AWSCredentialsProviderKeychainIdentityId];
}

AWSAnonymousCredentialsProvider *credentialsProvider = [AWSAnonymousCredentialsProvider new];
AWSServiceConfiguration *configuration = [AWSServiceConfiguration configurationWithRegion:regionType
Expand All @@ -378,30 +378,33 @@ - (instancetype)initWithRegionType:(AWSRegionType)regionType
}

- (BFTask *)refresh {
// Grab a reference to our provider in case it changes out from under us
id<AWSCognitoIdentityProvider> providerRef = self.identityProvider;

return [[[BFTask taskWithResult:nil] continueWithExecutor:self.refreshExecutor withSuccessBlock:^id(BFTask *task) {
self.count++;
if (self.count <= 1) {
return [[self.identityProvider refresh] continueWithSuccessBlock:^id(BFTask *task) {
return [[providerRef refresh] continueWithSuccessBlock:^id(BFTask *task) {
// This should never happen, but just in case
if (!self.identityProvider.identityId) {
if (!providerRef.identityId) {
AWSLogError(@"In refresh, but identityId is nil.");
return [BFTask taskWithError:[NSError errorWithDomain:AWSCognitoCredentialsProviderErrorDomain
code:AWSCognitoCredentialsProviderIdentityIdIsNil
userInfo:@{NSLocalizedDescriptionKey: @"identityId shouldn't be nil"}]
];
}
self.identityId = self.identityProvider.identityId;

self.identityId = providerRef.identityId;
[self.keychain synchronize];

NSString *roleArn = self.unAuthRoleArn;
if ([self.identityProvider isAuthenticated]) {
if ([providerRef isAuthenticated]) {
roleArn = self.authRoleArn;
}

AWSSTSAssumeRoleWithWebIdentityRequest *webIdentityRequest = [AWSSTSAssumeRoleWithWebIdentityRequest new];
webIdentityRequest.roleArn = roleArn;
webIdentityRequest.webIdentityToken = self.identityProvider.token;
webIdentityRequest.webIdentityToken = providerRef.token;
webIdentityRequest.roleSessionName = @"iOS-Provider";
return [[self.sts assumeRoleWithWebIdentity:webIdentityRequest] continueWithBlock:^id(BFTask *task) {
if (task.result) {
Expand Down Expand Up @@ -429,6 +432,9 @@ - (BFTask *)refresh {
if (task.error) {
AWSLogError(@"Unable to refresh. Error is [%@]", task.error);
}
if (task.exception) {
AWSLogError(@"Unable to refresh. Exception is [%@]", task.exception);
}

self.count--;
dispatch_semaphore_signal(self.semaphore);
Expand All @@ -438,17 +444,20 @@ - (BFTask *)refresh {
}

- (BFTask *)getIdentityId {
return [[self.identityProvider getIdentityId] continueWithSuccessBlock:^id(BFTask *task) {
// Grab a reference to our provider in case it changes out from under us
id<AWSCognitoIdentityProvider> providerRef = self.identityProvider;

return [[providerRef getIdentityId] continueWithSuccessBlock:^id(BFTask *task) {
// This should never happen, but just in case
if (!self.identityProvider.identityId) {
if (!providerRef.identityId) {
AWSLogError(@"In refresh, but identityId is nil.");
AWSLogError(@"Result from getIdentityId is %@", task.result);
return [BFTask taskWithError:[NSError errorWithDomain:AWSCognitoCredentialsProviderErrorDomain
code:AWSCognitoCredentialsProviderIdentityIdIsNil
userInfo:@{NSLocalizedDescriptionKey: @"identityId shouldn't be nil"}]
];
}
self.identityId = self.identityProvider.identityId;
self.identityId = providerRef.identityId;
[self.keychain synchronize];
return task;
}];
Expand Down
2 changes: 1 addition & 1 deletion AWSCore/Authentication/AWSIdentityProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ typedef NS_ENUM(NSInteger, AWSCognitoIdentityProviderErrorType) {
@protocol AWSCognitoIdentityProvider <AWSIdentityProvider>

@property (nonatomic, strong, readonly) NSString *identityPoolId;
@property (nonatomic, strong, readonly) NSString *identityId;
@property (nonatomic, strong) NSString *identityId;
@property (nonatomic, strong) NSDictionary *logins;

- (BFTask *)getIdentityId;
Expand Down
50 changes: 27 additions & 23 deletions AWSCore/Authentication/AWSIdentityProvider.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

@interface AWSAbstractIdentityProvider()
@property (nonatomic, strong) NSString *identityPoolId;
@property (nonatomic, strong) NSString *identityId;
@property (nonatomic, strong) NSString *token;
@end

Expand Down Expand Up @@ -72,7 +71,7 @@ - (NSDictionary *)updateKeysForLogins:(NSDictionary *)logins {
if (logins == nil) {
return nil;
}

NSMutableDictionary *mutableLogin = [NSMutableDictionary new];
for (id key in logins) {
NSString *updatedKey = key;
Expand All @@ -94,11 +93,11 @@ - (NSDictionary *)updateKeysForLogins:(NSDictionary *)logins {
}
mutableLogin[updatedKey] = logins[key];
}

if ([mutableLogin count] == 0) {
return nil;
}

return mutableLogin;
}

Expand All @@ -108,7 +107,7 @@ - (void)postIdentityIdChangedNotification:(NSString *)newId {
[userInfo setObject:self.identityId forKey:AWSCognitoNotificationPreviousId];
}
[userInfo setObject:newId forKey:AWSCognitoNotificationNewId];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:AWSCognitoIdentityIdChangedNotification
object:self
Expand All @@ -134,7 +133,7 @@ - (instancetype)initWithRegionType:(AWSRegionType)regionType
accountId:(NSString *)accountId
identityPoolId:(NSString *)identityPoolId
logins:(NSDictionary *)logins {

if (self = [super init]) {
_accountId = accountId;
_executor = [BFExecutor executorWithOperationQueue:[NSOperationQueue new]];
Expand All @@ -143,14 +142,14 @@ - (instancetype)initWithRegionType:(AWSRegionType)regionType
self.identityPoolId = identityPoolId;
self.identityId = identityId;
self.logins = [self updateKeysForLogins:logins];

AWSAnonymousCredentialsProvider *credentialsProvider = [AWSAnonymousCredentialsProvider new];
AWSServiceConfiguration *configuration = [AWSServiceConfiguration configurationWithRegion:regionType
credentialsProvider:credentialsProvider];

_cib = [[AWSCognitoIdentity new] initWithConfiguration:configuration];
}

return self;
}

Expand All @@ -165,7 +164,7 @@ - (BFTask *)getIdentityId {
getIdInput.accountId = self.accountId;
getIdInput.identityPoolId = self.identityPoolId;
getIdInput.logins = self.logins;

return [self.cib getId:getIdInput];
}
else {
Expand All @@ -178,6 +177,9 @@ - (BFTask *)getIdentityId {
if (task.error) {
AWSLogError(@"GetId failed. Error is [%@]", task.error);
return task;
} else if (task.exception) {
AWSLogError(@"GetId failed. Exception is [%@]", task.exception);
return task;
} else if (task.result) {
AWSCognitoIdentityGetIdResponse *getIdResponse = task.result;
self.identityId = getIdResponse.identityId;
Expand All @@ -195,26 +197,25 @@ - (BFTask *)refresh {
AWSLogError(@"Result from getIdentityId is %@", task.result);
return [BFTask taskWithError:[NSError errorWithDomain:AWSCognitoIdentityProviderErrorDomain
code:AWSCognitoIdentityProviderErrorIdentityIsNil
userInfo:@{NSLocalizedDescriptionKey: @"identityId shouldn't be nil"}]
];
userInfo:@{NSLocalizedDescriptionKey: @"identityId shouldn't be nil"}]];
}

AWSCognitoIdentityGetOpenIdTokenInput *getTokenInput = [AWSCognitoIdentityGetOpenIdTokenInput new];
getTokenInput.identityId = self.identityId;
getTokenInput.logins = self.logins;


return [[self.cib getOpenIdToken:getTokenInput] continueWithBlock:^id(BFTask *task) {
// When an invalid identityId is cached in the keychain for auth,
// we will refresh the identityId and try to get OpenID token again.
if (task.error) {
AWSLogError(@"GetOpenIdToken failed. Error is [%@]", task.error);

// if it's unauth, just fail out
if (![self isAuthenticated]) {
return task;
}

AWSLogVerbose(@"Resetting identity Id and calling getIdentityId");
// if it's auth, reset id and refetch
self.identityId = nil;
Expand All @@ -228,24 +229,27 @@ - (BFTask *)refresh {
userInfo:@{NSLocalizedDescriptionKey: @"identityId shouldn't be nil"}]
];
}

AWSLogVerbose(@"Retrying GetOpenIdToken");

// retry get token
AWSCognitoIdentityGetOpenIdTokenInput *tokenRetry = [AWSCognitoIdentityGetOpenIdTokenInput new];
tokenRetry.identityId = self.identityId;
tokenRetry.logins = self.logins;

return [self.cib getOpenIdToken:tokenRetry];
}];
}
if (task.exception) {
AWSLogError(@"GetOpenIdToken failed. Exception is [%@]", task.exception);
}
return task;
}];
}] continueWithSuccessBlock:^id(BFTask *task) {
AWSCognitoIdentityGetOpenIdTokenResponse *getTokenResponse = task.result;
self.token = getTokenResponse.token;
NSString *identityIdFromToken = getTokenResponse.identityId;

// This should never happen, but just in case
if (!identityIdFromToken) {
AWSLogError(@"identityId from getOpenIdToken is nil");
Expand All @@ -254,11 +258,11 @@ - (BFTask *)refresh {
userInfo:@{NSLocalizedDescriptionKey: @"identityId shouldn't be nil"}]
];
}

if (![self.identityId isEqualToString:identityIdFromToken]) {
self.identityId = identityIdFromToken;
}

return nil;
}];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ - (void)notify:(id<AWSMobileAnalyticsInternalEvent>)event {
[self enqueueEventForDelivery:event];
}

/*
- (BOOL)validateEvent:(id<AWSMobileAnalyticsInternalEvent>)event {
if (![event attributeForKey:AWSSessionIDAttributeKey]) {
AWSLogError(@"Event: '%@' Validation Error: %@ is nil", event.eventType, AWSSessionIDAttributeKey);
Expand All @@ -139,18 +140,19 @@ - (BOOL)validateEvent:(id<AWSMobileAnalyticsInternalEvent>)event {
return YES;
}
*/

- (void)enqueueEventForDelivery:(id<AWSMobileAnalyticsInternalEvent>) event {
if(self.operationQueue.operationCount >= AWSMobileAnalyticsDefaultDeliveryClientMaxOperations) {
AWSLogError(@"The event: '%@' is being dropped because too many operations enqueued.", event.eventType);
return;
}

/*
if (![self validateEvent:event]) {
AWSLogError(@"The event '%@'is being dropped because internal validation failed.", event.eventType);
return;
}

*/
[self.operationQueue addOperationWithBlock:^(void) {
NSData* serializedEventData = [self.serializer writeObject:event];
NSString* serializedEvent = [[NSString alloc] initWithData:serializedEventData encoding:NSUTF8StringEncoding];
Expand Down
2 changes: 1 addition & 1 deletion AWSCore/Networking/AWSNetworking.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#import "AWSURLSessionManager.h"

NSString *const AWSNetworkingErrorDomain = @"com.amazonaws.AWSNetworkingErrorDomain";
NSString *const AWSiOSSDKVersion = @"2.0.11";
NSString *const AWSiOSSDKVersion = @"2.0.12";

#pragma mark - AWSHTTPMethod

Expand Down
2 changes: 1 addition & 1 deletion AWSiOSSDKv2.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = 'AWSiOSSDKv2'
s.version = '2.0.11'
s.version = '2.0.12'
s.summary = 'Amazon Web Services SDK for iOS.'

s.description = 'The AWS SDK for iOS provides a library, code samples, and documentation for developers to build connected mobile applications using AWS.'
Expand Down
2 changes: 1 addition & 1 deletion Scripts/GenerateAppleDocs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function cleanup
}


VERSION="2.0.11"
VERSION="2.0.12"
if [ -n $1 ] && [ "$1" == "clean" ];
then
cleanup
Expand Down

0 comments on commit 7e9bcb9

Please sign in to comment.