No Description

AWSCognitoIdentityUserPool.h 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. //
  2. // Copyright 2014-2017 Amazon.com,
  3. // Inc. or its affiliates. All Rights Reserved.
  4. //
  5. // Licensed under the Amazon Software License (the "License").
  6. // You may not use this file except in compliance with the
  7. // License. A copy of the License is located at
  8. //
  9. // http://aws.amazon.com/asl/
  10. //
  11. // or in the "license" file accompanying this file. This file is
  12. // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  13. // CONDITIONS OF ANY KIND, express or implied. See the License
  14. // for the specific language governing permissions and
  15. // limitations under the License.
  16. //
  17. #import <Foundation/Foundation.h>
  18. #import "AWSCognitoIdentityProviderService.h"
  19. @class AWSCognitoIdentityUser;
  20. @class AWSCognitoIdentityUserAttributeType;
  21. @class AWSCognitoIdentityPasswordAuthenticationInput;
  22. @class AWSCognitoIdentityMultifactorAuthenticationInput;
  23. @class AWSCognitoIdentityPasswordAuthenticationDetails;
  24. @class AWSCognitoIdentityCustomChallengeDetails;
  25. @class AWSCognitoIdentityUserPoolConfiguration;
  26. @class AWSCognitoIdentityUserPoolSignUpResponse;
  27. @class AWSCognitoIdentityNewPasswordRequiredDetails;
  28. @class AWSCognitoIdentitySoftwareMfaSetupRequiredDetails;
  29. @class AWSCognitoIdentitySelectMfaDetails;
  30. @protocol AWSCognitoIdentityInteractiveAuthenticationDelegate;
  31. @protocol AWSCognitoIdentityPasswordAuthentication;
  32. @protocol AWSCognitoIdentityMultiFactorAuthentication;
  33. @protocol AWSCognitoIdentityCustomAuthentication;
  34. @protocol AWSCognitoIdentityRememberDevice;
  35. @protocol AWSCognitoIdentityNewPasswordRequired;
  36. @protocol AWSCognitoIdentitySoftwareMfaSetupRequired;
  37. @protocol AWSCognitoIdentitySelectMfa;
  38. NS_ASSUME_NONNULL_BEGIN
  39. @interface AWSCognitoIdentityUserPool : NSObject <AWSIdentityProvider, AWSIdentityProviderManager>
  40. @property (nonatomic, readonly) AWSServiceConfiguration *configuration;
  41. @property (nonatomic, readonly) AWSCognitoIdentityUserPoolConfiguration *userPoolConfiguration;
  42. @property (nonatomic, readonly) NSString *identityProviderName;
  43. /**
  44. Set this delegate to interactively prompt users for authentication challenges when necessary
  45. */
  46. @property (nonatomic, strong) id <AWSCognitoIdentityInteractiveAuthenticationDelegate> delegate;
  47. /**
  48. * Fetches the Cognito User Pool instance configured in the `info.plist` under `CognitoUserPool`
  49. *
  50. * @return the default instance for Cognito User Pool
  51. */
  52. + (instancetype)defaultCognitoIdentityUserPool;
  53. + (void)registerCognitoIdentityUserPoolWithUserPoolConfiguration:(AWSCognitoIdentityUserPoolConfiguration *)userPoolConfiguration
  54. forKey:(NSString *)key;
  55. + (void)registerCognitoIdentityUserPoolWithConfiguration:(nullable AWSServiceConfiguration *)configuration
  56. userPoolConfiguration:(AWSCognitoIdentityUserPoolConfiguration *)userPoolConfiguration
  57. forKey:(NSString *)key;
  58. + (instancetype)CognitoIdentityUserPoolForKey:(NSString *)key;
  59. + (void)removeCognitoIdentityUserPoolForKey:(NSString *)key;
  60. /**
  61. Sign up a new user
  62. */
  63. - (AWSTask<AWSCognitoIdentityUserPoolSignUpResponse *> *)signUp:(NSString *)username
  64. password:(NSString *)password
  65. userAttributes:(nullable NSArray<AWSCognitoIdentityUserAttributeType *> *)userAttributes
  66. validationData:(nullable NSArray<AWSCognitoIdentityUserAttributeType *> *)validationData;
  67. /**
  68. Return the user who last authenticated. Username may be nil if current user is unknown.
  69. @return The last authenticated user
  70. */
  71. - (nullable AWSCognitoIdentityUser *)currentUser;
  72. /**
  73. Return the user without a username, when username is unknown.
  74. */
  75. - (AWSCognitoIdentityUser *)getUser;
  76. /**
  77. Return the user with a specific username
  78. */
  79. - (AWSCognitoIdentityUser *)getUser:(NSString *)username;
  80. /**
  81. Clear the last known user only without signing out of their user session
  82. */
  83. - (void) clearLastKnownUser;
  84. /**
  85. Clear everything from keychain, including last known user and user sessions for all users.
  86. */
  87. - (void) clearAll;
  88. @end
  89. @interface AWSCognitoIdentityUserPoolConfiguration : NSObject
  90. @property (nonatomic, readonly) NSString *clientId;
  91. @property (nonatomic, readonly, nullable) NSString *clientSecret;
  92. @property (nonatomic, readonly) NSString *poolId;
  93. @property (nonatomic, readonly) NSString *pinpointAppId;
  94. @property (nonatomic, readonly) BOOL shouldProvideCognitoValidationData;
  95. @property (nonatomic, readonly) BOOL migrationEnabled;
  96. - (instancetype)initWithClientId:(NSString *)clientId
  97. clientSecret:(nullable NSString *)clientSecret
  98. poolId:(NSString *)poolId;
  99. - (instancetype)initWithClientId:(NSString *)clientId
  100. clientSecret:(nullable NSString *)clientSecret
  101. poolId:(NSString *)poolId
  102. shouldProvideCognitoValidationData:(BOOL)shouldProvideCognitoValidationData;
  103. - (instancetype)initWithClientId:(NSString *)clientId
  104. clientSecret:(nullable NSString *)clientSecret
  105. poolId:(NSString *)poolId
  106. shouldProvideCognitoValidationData:(BOOL)shouldProvideCognitoValidationData
  107. pinpointAppId:(nullable NSString *)pinpointAppId;
  108. - (instancetype)initWithClientId:(NSString *)clientId
  109. clientSecret:(nullable NSString *)clientSecret
  110. poolId:(NSString *)poolId
  111. shouldProvideCognitoValidationData:(BOOL)shouldProvideCognitoValidationData
  112. pinpointAppId:(nullable NSString *)pinpointAppId
  113. migrationEnabled:(BOOL) migrationEnabled;
  114. @end
  115. /**
  116. When interactive sign in is initiated, this encapsulates the last known username
  117. */
  118. @interface AWSCognitoIdentityPasswordAuthenticationInput : NSObject
  119. @property(nonatomic, readonly, nullable) NSString *lastKnownUsername;
  120. @end
  121. /**
  122. When interactive auth requires a multifactor authentication code, this encapsulates the
  123. destination and delivery medium
  124. */
  125. @interface AWSCognitoIdentityMultifactorAuthenticationInput : NSObject
  126. @property(nonatomic, readonly, nullable) NSString *destination;
  127. @property(nonatomic, assign, readonly) AWSCognitoIdentityProviderDeliveryMediumType deliveryMedium;
  128. @end
  129. /**
  130. When responding to an interactive sign in, this encapsulates the end users' username and password
  131. */
  132. @interface AWSCognitoIdentityPasswordAuthenticationDetails : NSObject
  133. @property(nonatomic, strong) NSString *username;
  134. @property(nonatomic, strong) NSString *password;
  135. @property(nonatomic, strong, nullable) NSArray<AWSCognitoIdentityUserAttributeType *> *validationData;
  136. - (nullable instancetype)initWithUsername:(NSString *)username
  137. password:(NSString *)password;
  138. @end
  139. /**
  140. When responding to a custom sign in, this encapsulates the end users challenge responses
  141. */
  142. @interface AWSCognitoIdentityCustomChallengeDetails : NSObject
  143. /**
  144. Optional developer provided validation data to add to the initate auth call
  145. */
  146. @property(nonatomic, strong, nullable) NSArray<AWSCognitoIdentityUserAttributeType *> *validationData;
  147. /**
  148. If you know your initial challenge, set this property to the challenge name
  149. */
  150. @property(nonatomic, strong, nullable) NSString *initialChallengeName;
  151. /**
  152. The end user challenge responses for this challenge
  153. */
  154. @property(nonatomic, strong) NSDictionary<NSString*,NSString*>* challengeResponses;
  155. -(instancetype) initWithChallengeResponses: (NSDictionary<NSString*,NSString*> *) challengeResponses;
  156. @end
  157. /**
  158. When responding to a new password required challenge this encapsulates the end users' new password and required attributes
  159. */
  160. @interface AWSCognitoIdentityNewPasswordRequiredDetails : NSObject
  161. /**
  162. The end user's new password
  163. */
  164. @property(nonatomic, strong, nonnull) NSString *proposedPassword;
  165. /**
  166. Any attribute the end user is setting. Values must be present for all
  167. required attributes. Any other attributes are optional.
  168. */
  169. @property(nonatomic, strong, nullable) NSArray<AWSCognitoIdentityUserAttributeType*> *userAttributes;
  170. /**
  171. Initializer given a new password and map of user attributes to set
  172. **/
  173. -(instancetype) initWithProposedPassword: (NSString *) proposedPassword userAttributes:(NSDictionary<NSString*,NSString*> *) userAttributes;
  174. @end
  175. /**
  176. When responding to a custom sign in, this encapsulates the challenge parameters that define the challenge
  177. */
  178. @interface AWSCognitoIdentityCustomAuthenticationInput : NSObject
  179. @property(nonatomic, strong) NSDictionary<NSString*,NSString*>* challengeParameters;
  180. -(instancetype) initWithChallengeParameters: (NSDictionary<NSString*,NSString*> *) challengeParameters;
  181. @end
  182. /**
  183. When responding to new password required, this encapsulates the existing user attributes and the required user attributes.
  184. */
  185. @interface AWSCognitoIdentityNewPasswordRequiredInput : NSObject
  186. @property(nonatomic, strong) NSDictionary<NSString*,NSString*>* userAttributes;
  187. @property(nonatomic, strong) NSSet<NSString*>* requiredAttributes;
  188. -(instancetype) initWithUserAttributes: (NSDictionary<NSString*,NSString*> *) userAttributes requiredAttributes: (NSSet<NSString*>*) requiredAttributes;
  189. @end
  190. /**
  191. When responding to software mfa setup required, this encapsulates the secret code the end user must provide to their software mfa.
  192. */
  193. @interface AWSCognitoIdentitySoftwareMfaSetupRequiredInput : NSObject
  194. @property(nonatomic, strong) NSString *secretCode;
  195. @property(nonatomic, strong) NSString *username;
  196. -(instancetype) initWithSecretCode: (NSString *) secretCode username: (NSString *) username;
  197. @end
  198. /**
  199. When responding to a software mfa setup required challenge this encapsulates the end user's user code and friendly name for their TOTP
  200. */
  201. @interface AWSCognitoIdentitySoftwareMfaSetupRequiredDetails : NSObject
  202. /**
  203. The end user's code from their software mfa
  204. */
  205. @property(nonatomic, strong, nonnull) NSString *userCode;
  206. /**
  207. The friendly device name that will be specified when this software mfa is requested.
  208. */
  209. @property(nonatomic, strong, nullable) NSString *friendlyDeviceName;
  210. /**
  211. Initializer given the software tokens' code and friendly device name
  212. **/
  213. -(instancetype) initWithUserCode: (NSString *) userCode friendlyDeviceName:(NSString* _Nullable) friendlyDeviceName;
  214. @end
  215. /**
  216. When responding to a select mfa challenge, this encapsulates the available mfas the end user can choose from
  217. */
  218. @interface AWSCognitoIdentitySelectMfaInput : NSObject
  219. @property(nonatomic, strong) NSDictionary<NSString*,NSString *>* availableMfas;
  220. -(instancetype) initWithAvailableMfas: (NSDictionary<NSString*,NSString *>*) availableMfas;
  221. @end
  222. /**
  223. When responding to a select mfa challenge this encapsulates the end users mfa choice
  224. */
  225. @interface AWSCognitoIdentitySelectMfaDetails : NSObject
  226. /**
  227. The mfa the end user selected
  228. */
  229. @property(nonatomic, strong, nonnull) NSString *selectedMfa;
  230. /**
  231. Initializer given the mfa selected by the end user
  232. **/
  233. -(instancetype) initWithSelectedMfa:(NSString*) selectedMfa;
  234. @end
  235. /**
  236. The error domain for AWSCognitoIdentityProvider errors.
  237. <ul>
  238. <li>AWSCognitoIdentityProviderClientErrorUnknown - Unknown error.</li>
  239. <li>AWSCognitoIdentityProviderClientErrorInvalidAuthenticationDelegate - Necessary authentication delegate isn't set.</li>
  240. <li>AWSCognitoIdentityProviderClientErrorCustomAuthenticationNotSupported - Custom authentication is not supported by this SDK.</li>
  241. <li>AWSCognitoIdentityProviderClientErrorDeviceNotTracked - This device does not have an id, either it was never tracked or previously forgotten.</li>
  242. </ul>
  243. */
  244. typedef NS_ENUM(NSInteger, AWSCognitoIdentityClientErrorType) {
  245. AWSCognitoIdentityProviderClientErrorUnknown = 0,
  246. AWSCognitoIdentityProviderClientErrorInvalidAuthenticationDelegate = -1000,
  247. AWSCognitoIdentityProviderClientErrorCustomAuthenticationNotSupported = -2000,
  248. AWSCognitoIdentityProviderClientErrorDeviceNotTracked = -3000,
  249. };
  250. @interface AWSCognitoIdentityUserPoolSignUpResponse : AWSCognitoIdentityProviderSignUpResponse
  251. @property (nonatomic, readonly) AWSCognitoIdentityUser* user;
  252. @end
  253. @protocol AWSCognitoIdentityInteractiveAuthenticationDelegate <NSObject>
  254. @optional
  255. /**
  256. Initialize ui to prompt end user for username and password
  257. */
  258. -(id<AWSCognitoIdentityPasswordAuthentication>) startPasswordAuthentication;
  259. /**
  260. Initialize ui to prompt end user for multifactor authentication code
  261. */
  262. -(id<AWSCognitoIdentityMultiFactorAuthentication>) startMultiFactorAuthentication;
  263. /**
  264. Initialize ui to prompt end user to remember this device
  265. */
  266. -(id<AWSCognitoIdentityRememberDevice>) startRememberDevice;
  267. /**
  268. Initialize ui to prompt end user to set a new password and specify profile information as part of sign in
  269. */
  270. -(id<AWSCognitoIdentityNewPasswordRequired>) startNewPasswordRequired;
  271. /**
  272. Initialize ui to prompt end user for custom authentication flow
  273. */
  274. -(id<AWSCognitoIdentityCustomAuthentication>) startCustomAuthentication;
  275. /**
  276. Initialize ui to prompt end user to setup a software mfa token */
  277. -(id<AWSCognitoIdentitySoftwareMfaSetupRequired>) startSoftwareMfaSetupRequired;
  278. /**
  279. Initialize ui to prompt end user to pick desired mfa */
  280. -(id<AWSCognitoIdentitySelectMfa>) startSelectMfa;
  281. @end
  282. @protocol AWSCognitoIdentityPasswordAuthentication <NSObject>
  283. /**
  284. Obtain username and password from end user.
  285. @param authenticationInput input details including last known username
  286. @param passwordAuthenticationCompletionSource set passwordAuthenticationCompletionSource.result
  287. with the username and password received from the end user.
  288. */
  289. -(void) getPasswordAuthenticationDetails: (AWSCognitoIdentityPasswordAuthenticationInput *) authenticationInput passwordAuthenticationCompletionSource: (AWSTaskCompletionSource<AWSCognitoIdentityPasswordAuthenticationDetails *> *) passwordAuthenticationCompletionSource;
  290. /**
  291. This step completed, usually either display an error to the end user or dismiss ui
  292. @param error the error if any that occured
  293. */
  294. -(void) didCompletePasswordAuthenticationStepWithError:(NSError* _Nullable) error;
  295. @end
  296. @protocol AWSCognitoIdentityMultiFactorAuthentication <NSObject>
  297. /**
  298. Obtain mfa code from the end user
  299. @param authenticationInput details about the deliveryMedium and masked destination for where the code was sent
  300. @param mfaCodeCompletionSource set mfaCodeCompletionSource.result with the mfa code from end user
  301. */
  302. -(void) getMultiFactorAuthenticationCode: (AWSCognitoIdentityMultifactorAuthenticationInput *) authenticationInput mfaCodeCompletionSource: (AWSTaskCompletionSource<NSString *> *) mfaCodeCompletionSource;
  303. /**
  304. This step completed, usually either display an error to the end user or dismiss ui
  305. @param error the error if any that occured
  306. */
  307. -(void) didCompleteMultifactorAuthenticationStepWithError:(NSError* _Nullable) error;
  308. @end
  309. @protocol AWSCognitoIdentityCustomAuthentication <NSObject>
  310. /**
  311. Obtain input for a custom challenge from the end user
  312. @param authenticationInput details the challenge including the challenge name and inputs
  313. @param customAuthCompletionSource set customAuthCompletionSource.result with the challenge answers from the end user
  314. */
  315. -(void) getCustomChallengeDetails: (AWSCognitoIdentityCustomAuthenticationInput *) authenticationInput customAuthCompletionSource: (AWSTaskCompletionSource<AWSCognitoIdentityCustomChallengeDetails *> *) customAuthCompletionSource;
  316. /**
  317. This step completed, usually either display an error to the end user or dismiss ui
  318. @param error the error if any that occured
  319. */
  320. -(void) didCompleteCustomAuthenticationStepWithError:(NSError* _Nullable) error;
  321. @end
  322. @protocol AWSCognitoIdentityRememberDevice <NSObject>
  323. /**
  324. Obtain whether to remember this device or not
  325. @param rememberDeviceCompletionSource set customAuthCompletionSource.result with YES or NO answer from the end user
  326. */
  327. -(void) getRememberDevice: (AWSTaskCompletionSource<NSNumber *> *) rememberDeviceCompletionSource;
  328. /**
  329. This step completed, usually either display an error to the end user or dismiss ui
  330. @param error the error if any that occured
  331. */
  332. -(void) didCompleteRememberDeviceStepWithError:(NSError* _Nullable) error;
  333. @end
  334. @protocol AWSCognitoIdentityNewPasswordRequired <NSObject>
  335. /**
  336. Obtain a new password and specify profile information as part of sign in from the end user
  337. @param newPasswordRequiredInput user profile and required attributes of the end user
  338. @param newPasswordRequiredCompletionSource set newPasswordRequiredCompletionSource.result with the new password and any attribute updates from the end user
  339. */
  340. -(void) getNewPasswordDetails: (AWSCognitoIdentityNewPasswordRequiredInput *) newPasswordRequiredInput newPasswordRequiredCompletionSource: (AWSTaskCompletionSource<AWSCognitoIdentityNewPasswordRequiredDetails *> *) newPasswordRequiredCompletionSource;
  341. /**
  342. This step completed, usually either display an error to the end user or dismiss ui
  343. @param error the error if any that occured
  344. */
  345. -(void) didCompleteNewPasswordStepWithError:(NSError* _Nullable) error;
  346. @end
  347. @protocol AWSCognitoIdentitySoftwareMfaSetupRequired <NSObject>
  348. /**
  349. Obtain information about end user's software mfa
  350. @param softwareMfaSetupInput contains secret code necessary for end user to configure their software mfa
  351. @param softwareMfaSetupRequiredCompletionSource set softwareMfaSetupRequiredCompletionSource.result with the secret code and device name from the end user
  352. */
  353. -(void) getSoftwareMfaSetupDetails: (AWSCognitoIdentitySoftwareMfaSetupRequiredInput *) softwareMfaSetupInput softwareMfaSetupRequiredCompletionSource: (AWSTaskCompletionSource<AWSCognitoIdentitySoftwareMfaSetupRequiredDetails *> *) softwareMfaSetupRequiredCompletionSource;
  354. /**
  355. This step completed, usually either display an error to the end user or dismiss ui
  356. @param error the error if any that occured
  357. */
  358. -(void) didCompleteMfaSetupStepWithError:(NSError* _Nullable) error;
  359. @end
  360. @protocol AWSCognitoIdentitySelectMfa <NSObject>
  361. /**
  362. Obtain which mfa end user wants to provide
  363. @param selectMfaInput contains which mfas are available
  364. @param selectMfaCompletionSource set selectMfaCompletionSource.result with the mfa end user picked
  365. */
  366. -(void) getSelectMfaDetails: (AWSCognitoIdentitySelectMfaInput *) selectMfaInput selectMfaCompletionSource: (AWSTaskCompletionSource<AWSCognitoIdentitySelectMfaDetails *> *) selectMfaCompletionSource;
  367. /**
  368. This step completed, usually either display an error to the end user or dismiss ui
  369. @param error the error if any that occured
  370. */
  371. -(void) didCompleteSelectMfaStepWithError:(NSError* _Nullable) error;
  372. @end
  373. NS_ASSUME_NONNULL_END