Skip to content

Commit 4dabdc8

Browse files
author
Yosuke Matsuda
committed
The AWS Mobile SDK for iOS 2.0.14.
1 parent a65c741 commit 4dabdc8

File tree

384 files changed

+8926
-1683
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

384 files changed

+8926
-1683
lines changed

AWSCore/AWSCore.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
2121
#import "AWSValidation.h"
2222
#import "AWSURLRequestSerialization.h"
2323
#import "AWSURLResponseSerialization.h"
24-
#import "AWSClientContext.h"
2524
#import "AWSCategory.h"
2625
#import "AWSLogging.h"
2726

AWSCore/Authentication/AWSCredentialsProvider.h

Lines changed: 217 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.
@@ -21,25 +21,65 @@ FOUNDATION_EXPORT NSString *const AWSCognitoCredentialsProviderErrorDomain;
2121
typedef NS_ENUM(NSInteger, AWSCognitoCredentialsProviderErrorType) {
2222
AWSCognitoCredentialsProviderErrorUnknown,
2323
AWSCognitoCredentialsProviderIdentityIdIsNil,
24+
AWSCognitoCredentialsProviderInvalidConfiguration,
2425
};
2526

2627
@class BFTask;
2728

29+
/**
30+
* The AWS credentials provider protocol used to provide credentials
31+
* to the SDK in order to make calls to the AWS services.
32+
*/
2833
@protocol AWSCredentialsProvider <NSObject>
2934

3035
@optional
36+
37+
/**
38+
* Access Key component of credentials.
39+
*/
3140
@property (nonatomic, strong, readonly) NSString *accessKey;
41+
42+
/**
43+
* Secret Access Key component of credentials.
44+
*/
3245
@property (nonatomic, strong, readonly) NSString *secretKey;
46+
47+
/**
48+
* Session Token component of credentials.
49+
*/
3350
@property (nonatomic, strong, readonly) NSString *sessionKey;
51+
52+
/**
53+
* Date at which these credentials will expire.
54+
*/
3455
@property (nonatomic, strong, readonly) NSDate *expiration;
3556

57+
/**
58+
* Refresh the token associated with this provider.
59+
*
60+
* *Note* This method is automatically called by the AWS Mobile SDK for iOS,
61+
* and you do not need to call this method in general.
62+
*
63+
* @return BFTask.
64+
*/
3665
- (BFTask *)refresh;
3766

3867
@end
3968

69+
/**
70+
* @warning This credentials provider is intended only for testing purposes.
71+
* We strongly discourage embedding AWS credentials in your production apps because they can be easily extracted and abused.
72+
*/
4073
@interface AWSStaticCredentialsProvider : NSObject <AWSCredentialsProvider>
4174

75+
/**
76+
* Access Key component of credentials.
77+
*/
4278
@property (nonatomic, readonly) NSString *accessKey;
79+
80+
/**
81+
* Secret Access Key component of credentials.
82+
*/
4383
@property (nonatomic, readonly) NSString *secretKey;
4484

4585
+ (instancetype)credentialsWithAccessKey:(NSString *)accessKey
@@ -85,70 +125,235 @@ typedef NS_ENUM(NSInteger, AWSCognitoCredentialsProviderErrorType) {
85125
@end
86126

87127

128+
/**
129+
* An AWSCredentialsProvider that uses Amazon Cognito to fetch temporary credentials tied to an identity.
130+
*
131+
* To learn more about Amazon Cognito, please visit <a href="https://aws.amazon.com/cognito">https://aws.amazon.com/cognito</a>.
132+
*
133+
* There are 3 different flows supported by this credentials provider, see factory and init methods for
134+
* choosing the right one for your use case:
135+
*
136+
* 1. Enhanced flow: Uses Cognito for all operations and only requires an identity pool id to initialize.
137+
* 2. Basic flow: Uses Cognito + STS and requires identity pool plus IAM roles
138+
* 3. Developer authenticated identities: Uses your own AWSCognitoIdentityProvider to establish identity +
139+
* Cognito (and optionally STS) to establish credentials.
140+
*/
88141
@interface AWSCognitoCredentialsProvider : NSObject <AWSCredentialsProvider>
89142

143+
/**
144+
* Access Key component of credentials
145+
*/
90146
@property (nonatomic, strong, readonly) NSString *accessKey;
147+
148+
/**
149+
* Secret Access Key component of credentials
150+
*/
91151
@property (nonatomic, strong, readonly) NSString *secretKey;
152+
153+
/**
154+
* Session Token component of credentials
155+
*/
92156
@property (nonatomic, strong, readonly) NSString *sessionKey;
157+
158+
/**
159+
* Date at which these credentials will expire
160+
*/
93161
@property (nonatomic, strong, readonly) NSDate *expiration;
94162

163+
/**
164+
* The identityProvider which is responsible for establishing the identity id and
165+
* (optionally) the open id token for use in the Amazon Cognito authflow.
166+
*/
95167
@property (nonatomic, strong) id<AWSCognitoIdentityProvider> identityProvider;
96168

169+
/**
170+
* The identity id associated with this provider. This value will be fetched from the keychain
171+
* at startup. If you do not want to reuse the existing identity id, you must call the clearKeychain method.
172+
*/
97173
@property (nonatomic, strong, readonly) NSString *identityId;
174+
175+
/**
176+
* The identity pool id associated with this provider. Also used to create a namedspaced
177+
* keychain area to store identity id and credentials.
178+
*/
98179
@property (nonatomic, strong, readonly) NSString *identityPoolId;
99180

181+
/**
182+
* Each entry in logins represents a single login with an identity provider.
183+
* The key is the domain of the login provider (e.g. 'graph.facebook.com') and the value is the
184+
* OAuth/OpenId Connect token that results from an authentication with that login provider.
185+
*/
100186
@property (nonatomic, strong) NSDictionary *logins;
101187

188+
/**
189+
* Factory method for credentials provider with enhanced authentication flow. This is the recommended
190+
* constructor for first time Amazon Cognito developers. Will create an instance of AWSEnhancedCognitoIdentityProvider.
191+
*
192+
* @param regionType The region in which your identity pool exists.
193+
* @param identityPoolId The identity pool id for this provider. Value is used to communicate with
194+
* Amazon Cognito as well as namespace values stored in the keychain.
195+
*/
196+
+ (instancetype)credentialsWithRegionType:(AWSRegionType)regionType
197+
identityPoolId:(NSString *)identityPoolId;
198+
199+
/**
200+
* Factory method for credentials provider with pre-created AWSCognitoIdentityProvider. Use this
201+
* method when using developer authenticated identities.
202+
*
203+
* @param regionType The region in which your identity pool exists.
204+
* @param identityProvider Implementation of AWSCognitoIdentityProvider which is responsible for
205+
* acquirind identity id and (optionally) OpenId Connect token.
206+
* @param unauthRoleArn The role ARN to use when getting credentials for unauthenticated identities.
207+
* Provider will check the <code>isAuthenticated</code> property of the identity provider to
208+
* determine which role to use. Can be nil if unauthenticated identities are not supported or
209+
* if using enhanced authentication flow.
210+
* @param authRoleArn The role ARN to use when getting credentials for authenticated identities.
211+
* Provider will check the <code>isAuthenticated</code> property of the identity provider to
212+
* determine which role to use. Can be nil if authenticated identities are not supported or
213+
* if using enhanced authentication flow.
214+
*/
102215
+ (instancetype)credentialsWithRegionType:(AWSRegionType)regionType
103-
accountId:(NSString *)accountId
104-
identityPoolId:(NSString *)identityPoolId
216+
identityProvider:(id<AWSCognitoIdentityProvider>)identityProvider
105217
unauthRoleArn:(NSString *)unauthRoleArn
106218
authRoleArn:(NSString *)authRoleArn;
107219

220+
/**
221+
* Factory method for credentials provider with basic auth flow. Only use this method if you still
222+
* need to set your IAM roles client side. This method will create an instance of AWSBasicCognitoIdentityProvider.
223+
*
224+
* @param regionType The region in which your identity pool exists.
225+
* @param identityId The identity id to initialize this provider. If nil, the provider will attempt
226+
* to read from the keychain
227+
* @param accountId The AWS account id for the owner of the identity pool. Can be nil as this value
228+
* is no longer required
229+
* @param identityPoolId The identity pool id for this provider. Value is used to communicate with
230+
* Amazon Cognito as well as namespace values stored in the keychain.
231+
* @param unauthRoleArn The role ARN to use when getting credentials for unauthenticated identities.
232+
* Provider will check the <code>isAuthenticated</code> property of the identity provider to
233+
* determine which role to use. Can be nil if unauthenticated identities are not supported.
234+
* @param authRoleArn The role ARN to use when getting credentials for authenticated identities.
235+
* Provider will check the <code>isAuthenticated</code> property of the identity provider to
236+
* determine which role to use. Can be nil if authenticated identities are not supported.
237+
*/
238+
108239
+ (instancetype)credentialsWithRegionType:(AWSRegionType)regionType
109240
accountId:(NSString *)accountId
110241
identityPoolId:(NSString *)identityPoolId
111242
unauthRoleArn:(NSString *)unauthRoleArn
112-
authRoleArn:(NSString *)authRoleArn
113-
logins:(NSDictionary *)logins;
243+
authRoleArn:(NSString *)authRoleArn;
114244

115245
+ (instancetype)credentialsWithRegionType:(AWSRegionType)regionType
116246
identityId:(NSString *)identityId
117247
accountId:(NSString *)accountId
118248
identityPoolId:(NSString *)identityPoolId
119249
unauthRoleArn:(NSString *)unauthRoleArn
120250
authRoleArn:(NSString *)authRoleArn
121-
logins:(NSDictionary *)logins;
251+
logins:(NSDictionary *)logins __deprecated;
252+
122253

123254
+ (instancetype)credentialsWithRegionType:(AWSRegionType)regionType
124-
identityProvider:(id<AWSCognitoIdentityProvider>)identityProvider
255+
accountId:(NSString *)accountId
256+
identityPoolId:(NSString *)identityPoolId
125257
unauthRoleArn:(NSString *)unauthRoleArn
126-
authRoleArn:(NSString *)authRoleArn;
258+
authRoleArn:(NSString *)authRoleArn
259+
logins:(NSDictionary *)logins __deprecated;
127260

261+
/**
262+
* Initializer for credentials provider with enhanced authentication flow. This is the recommended
263+
* method for first time Amazon Cognito developers. Will create an instance of AWSEnhancedCognitoIdentityProvider.
264+
*
265+
* @param regionType The region in which your identity pool exists.
266+
* @param identityId The identity id to initialize this provider. If nil, the provider will attempt
267+
* to read from the keychain.
268+
* @param identityPoolId The identity pool id for this provider. Value is used to communicate with
269+
* Amazon Cognito as well as namespace values stored in the keychain.
270+
* @param logins The map of logins to link to this identity. Can be nil if identity is unauthenticated.
271+
*/
128272
- (instancetype)initWithRegionType:(AWSRegionType)regionType
129273
identityId:(NSString *)identityId
130-
accountId:(NSString *)accountId
131274
identityPoolId:(NSString *)identityPoolId
132-
unauthRoleArn:(NSString *)unauthRoleArn
133-
authRoleArn:(NSString *)authRoleArn
134275
logins:(NSDictionary *)logins;
135276

277+
/**
278+
* Initializer for credentials provider with pre-created AWSCognitoIdentityProvider. Use this
279+
* method when using developer authenticated identities.
280+
*
281+
* @param regionType The region in which your identity pool exists.
282+
* @param identityProvider Implementation of AWSCognitoIdentityProvider which is responsible for
283+
* acquirind identity id and (optionally) OpenId Connect token.
284+
* @param unauthRoleArn The role ARN to use when getting credentials for unauthenticated identities.
285+
* Provider will check the <code>isAuthenticated</code> property of the identity provider to
286+
* determine which role to use. Can be nil if unauthenticated identities are not supported or
287+
* if using enhanced authentication flow.
288+
* @param unauthRoleArn The role ARN to use when getting credentials for authenticated identities.
289+
* Provider will check the <code>isAuthenticated</code> property of the identity provider to
290+
* determine which role to use. Can be nil if authenticated identities are not supported or
291+
* if using enhanced authentication flow.
292+
*/
136293
- (instancetype)initWithRegionType:(AWSRegionType)regionType
137294
identityProvider:(id<AWSCognitoIdentityProvider>) identityProvider
138295
unauthRoleArn:(NSString *)unauthRoleArn
139296
authRoleArn:(NSString *)authRoleArn;
140297

141298
/**
142-
* Refreshes the locally stored credentials. The SDK automatically calls this method when necessary, and you do not need to call this method manually.
299+
* Initializer for credentials provider with basic auth flow. Only use this method if you still
300+
* need to set your IAM roles client side. This method will create an instance of AWSBasicCognitoIdentityProvider.
301+
*
302+
* @param regionType The region in which your identity pool exists.
303+
* @param identityId The identity id to initialize this provider. If nil, the provider will attempt
304+
* to read from the keychain
305+
* @param accountId The AWS account id for the owner of the identity pool. Can be nil as this value
306+
* is no longer required
307+
* @param identityPoolId The identity pool id for this provider. Value is used to communicate with
308+
* Amazon Cognito as well as namespace values stored in the keychain.
309+
* @param unauthRoleArn The role ARN to use when getting credentials for unauthenticated identities.
310+
* Provider will check the <code>isAuthenticated</code> property of the identity provider to
311+
* determine which role to use. Can be nil if unauthenticated identities are not supported.
312+
* @param unauthRoleArn The role ARN to use when getting credentials for authenticated identities.
313+
* Provider will check the <code>isAuthenticated</code> property of the identity provider to
314+
* determine which role to use. Can be nil if authenticated identities are not supported.
315+
* @param logins The map of logins to link to this identity. Can be nil if identity is unauthenticated.
316+
*/
317+
- (instancetype)initWithRegionType:(AWSRegionType)regionType
318+
identityId:(NSString *)identityId
319+
accountId:(NSString *)accountId
320+
identityPoolId:(NSString *)identityPoolId
321+
unauthRoleArn:(NSString *)unauthRoleArn
322+
authRoleArn:(NSString *)authRoleArn
323+
logins:(NSDictionary *)logins;
324+
325+
326+
/**
327+
* Refreshes the locally stored credentials. The SDK automatically calls this method when necessary,
328+
* and you do not need to call this method manually.
143329
*
144330
* @return BFTask
145331
*/
146332
- (BFTask *)refresh;
147333

334+
/**
335+
* Get/retrieve the identity id for this provider. If an identity id is already set on this
336+
* provider, no remote call is made and the identity will be returned as a result of the BFTask
337+
* (the identityId is also available as a property).
338+
* If no identityId is set on this provider, one will be retrieved from the service.
339+
*
340+
* @return BFTask
341+
*/
148342
- (BFTask *)getIdentityId;
149343

344+
/**
345+
* Clear ALL saved values for this provider (identityId, credentials, logins)
346+
*/
150347
- (void)clearKeychain;
151348

349+
/**
350+
* Clear the cached AWS credentials for this provider.
351+
*/
152352
- (void)clearCredentials;
153353

354+
/**
355+
* Internal method used to determine if the identityId should be reset on a provider
356+
*/
357+
+ (BOOL)shouldResetIdentityId:(NSError *)error;
358+
154359
@end

0 commit comments

Comments
 (0)