No Description

AWSIdentityProvider.h 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //
  2. // Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License").
  5. // You may not use this file except in compliance with the License.
  6. // A copy of the License is located at
  7. //
  8. // http://aws.amazon.com/apache2.0
  9. //
  10. // or in the "license" file accompanying this file. This file is distributed
  11. // on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  12. // express or implied. See the License for the specific language governing
  13. // permissions and limitations under the License.
  14. //
  15. #import <Foundation/Foundation.h>
  16. #import "AWSServiceEnum.h"
  17. NS_ASSUME_NONNULL_BEGIN
  18. FOUNDATION_EXPORT NSString *const AWSCognitoIdentityIdChangedNotification;
  19. FOUNDATION_EXPORT NSString *const AWSCognitoNotificationPreviousId;
  20. FOUNDATION_EXPORT NSString *const AWSCognitoNotificationNewId;
  21. FOUNDATION_EXPORT NSString *const AWSIdentityProviderDigits;
  22. FOUNDATION_EXPORT NSString *const AWSIdentityProviderFacebook;
  23. FOUNDATION_EXPORT NSString *const AWSIdentityProviderGoogle;
  24. FOUNDATION_EXPORT NSString *const AWSIdentityProviderLoginWithAmazon;
  25. FOUNDATION_EXPORT NSString *const AWSIdentityProviderTwitter;
  26. FOUNDATION_EXPORT NSString *const AWSIdentityProviderAmazonCognitoIdentity;
  27. FOUNDATION_EXPORT NSString *const AWSCognitoCredentialsProviderHelperErrorDomain;
  28. typedef NS_ENUM(NSInteger, AWSCognitoCredentialsProviderHelperErrorType) {
  29. AWSCognitoCredentialsProviderHelperErrorTypeIdentityIsNil,
  30. AWSCognitoCredentialsProviderHelperErrorTypeTokenRefreshTimeout,
  31. };
  32. @class AWSTask<__covariant ResultType>;
  33. /**
  34. AWSIdentityProvider provides an interface for acquiring an identity token from a provider.
  35. */
  36. @protocol AWSIdentityProvider <NSObject>
  37. /**
  38. The name of the identity provider. e.g. graph.facebook.com.
  39. */
  40. @property (nonatomic, readonly) NSString *identityProviderName;
  41. /**
  42. Returns the token associated with this provider. If the token is cached and invalid, should refresh and return the valid token.
  43. */
  44. - (AWSTask<NSString *> *)token;
  45. @end
  46. /**
  47. `AWSIdentityProviderManager` provides an interface for creating the `logins` dictionary for Amazon Cognito Identity.
  48. */
  49. @protocol AWSIdentityProviderManager <NSObject>
  50. /**
  51. Each entry in logins represents a single login with an identity provider. The key is the domain of the login provider (e.g. 'graph.facebook.com') and the value is the OAuth/OpenId Connect token that results from an authentication with that login provider.
  52. */
  53. - (AWSTask<NSDictionary<NSString *, NSString *> *> *)logins;
  54. @optional
  55. /**
  56. * If the token contains the role arn and there are multiple roles, return the custom role to assume. This is currently only supported for SAML identity providers.
  57. */
  58. @property (nonatomic, readonly) NSString *customRoleArn;
  59. @end
  60. /**
  61. AWSCognitoCredentialsProviderHelper provides a Cognito specific identity provider. Cognito Identity providers are associated with an identity pool. If the identity pool supports authenticated access, multiple logins may be added to link to the Cognito identity.
  62. */
  63. @protocol AWSCognitoCredentialsProviderHelper <AWSIdentityProvider, AWSIdentityProviderManager>
  64. /**
  65. The identity pool for this provider. Used to when making calls to the Amazon Cognito service
  66. */
  67. @property (nonatomic, strong, readonly) NSString *identityPoolId;
  68. /**
  69. The identity id as determined by the Amazon Cognito service
  70. */
  71. @property (nonatomic, strong, nullable) NSString *identityId;
  72. /**
  73. */
  74. @property (nonatomic, strong, readonly, nullable) id<AWSIdentityProviderManager> identityProviderManager;
  75. /**
  76. Get/retrieve the identity id for this provider. If an identity id is already set on this provider, no remote call is made and the identity will be returned as a result of the AWSTask (the identityId is also available as a property). If no identityId is set on this provider, one will be retrieved from the service.
  77. */
  78. - (AWSTask<NSString *> *)getIdentityId;
  79. /**
  80. Is this provider considered 'authenticated'. By default, only returns YES if logins is set.
  81. */
  82. - (BOOL)isAuthenticated;
  83. /**
  84. Clear saved values for identityId, token, and logins.
  85. */
  86. - (void)clear;
  87. @end
  88. /**
  89. An abstract implementation of the AWSCognitoCredentialsProviderHelper.
  90. */
  91. @interface AWSAbstractCognitoCredentialsProviderHelper : NSObject <AWSCognitoCredentialsProviderHelper>
  92. /**
  93. The identity pool for this provider. Used to when making calls to the Amazon Cognito service
  94. */
  95. @property (nonatomic, strong, readonly) NSString *identityPoolId;
  96. /**
  97. The identity id as determined by the Amazon Cognito service
  98. */
  99. @property (nonatomic, strong, nullable) NSString *identityId;
  100. /**
  101. The identity provider manager that asynchronously returns `logins`.
  102. */
  103. @property (nonatomic, strong, readonly, nullable) id<AWSIdentityProviderManager> identityProviderManager;
  104. @end
  105. /**
  106. An abstract implementation of the AWSCognitoCredentialsProviderHelper. Developers should extend this class when they want to implement developer authenticated identities and want to support the basic Amazon Cognito authflow in the same application.
  107. */
  108. @interface AWSCognitoCredentialsProviderHelper : AWSAbstractCognitoCredentialsProviderHelper
  109. @property (nonatomic, assign) BOOL useEnhancedFlow;
  110. - (instancetype)initWithRegionType:(AWSRegionType)regionType
  111. identityPoolId:(NSString *)identityPoolId
  112. useEnhancedFlow:(BOOL)useEnhancedFlow
  113. identityProviderManager:(nullable id<AWSIdentityProviderManager>)identityProviderManager;
  114. @end
  115. NS_ASSUME_NONNULL_END