AWSMobileClient
final public class AWSMobileClient : _AWSMobileClient
extension AWSMobileClient: AWSCognitoAuthDelegate
extension AWSMobileClient: AWSIdentityProviderManager
AWSMobileClient is used for all auth related operations when your app is accessing AWS backend.
-
Returns the current state of user. If MobileClient is not initialized, it will return
unknownDeclaration
Swift
public var currentUserState: UserState -
Undocumented
Declaration
Swift
public var deviceOperations: DeviceOperations -
The singleton instance of
AWSMobileClient.Deprecation note: use
AWSMobileClient.default()since it communicates better the API intent.Declaration
Swift
@available(*, deprecated, renamed: "default") override public class func sharedInstance() -> AWSMobileClientReturn Value
The singleton
AWSMobileClientinstance. -
The default instance of
AWSMobileClient. The configuration is loaded from theawsconfiguration.jsonfile.You can manage your own instance of
AWSMobileClientby constructing it withAWSMobileClient(configuration), however please note that multiple instances of AWSMobileClient is not supported.Implementation Notes:
The
AWSMobileClientrelies onAWSInfofor configuration and once that class is initialized, the configuration cannot be reset and/or re-initialized. Therefore, even though you can instantiateAWSMobileClientmultiple times, all instances will have the same configuration reference.Declaration
Swift
@objc public class func `default`() -> AWSMobileClientReturn Value
The default
AWSMobileClientinstance -
Adds a listener who receives notifications on user state change.
Declaration
Swift
public func addUserStateListener(_ object: AnyObject, _ callback: @escaping UserStateChangeCallback)Parameters
objectThe object who intends to receive notification. A strong reference is held to the object and the developer is required to call
removeUserStateListenerto stop getting notifications and release the object.callbackCallback describing the new user state.
-
Removes a registered listener. If no listener exists, call is ignored.
Declaration
Swift
public func removeUserStateListener(_ object: AnyObject)Parameters
objectThe object to be de-registered from receiving notifications.
-
Updates the service configuration for the Cognito Services
Warning
This method is intended for internal use only.Declaration
Swift
static func updateCognitoService(userPoolConfiguration: AWSServiceConfiguration?, identityPoolConfiguration: AWSServiceConfiguration?) -
Returns the username attribute of the access token for the current logged in user, nil otherwise. Note that the value stored may vary depending on how sign-in was performed. @see https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-using-tokens-with-identity-providers.html#amazon-cognito-user-pools-using-the-access-token
Declaration
Swift
public var username: String? { get } -
Undocumented
Declaration
Swift
public var userSub: String? { get } -
The identity id associated with this provider. This value will be fetched from the keychain at startup. If you do not want to reuse the existing identity id, you must call the clearKeychain method. If the identityId is not fetched yet, it will return nil. Use
getIdentityId()method to force a server fetch when identityId is not available.Declaration
Swift
override public var identityId: String? { get } -
Returns true if there is a user currently signed in.
Declaration
Swift
@objc public var isSignedIn: Bool { get } -
Undocumented
Declaration
Swift
public func handleAuthResponse(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -
Fetches the
AWSCredentialsasynchronously.Declaration
Swift
public func getAWSCredentials(_ completionHandler: @escaping (AWSCredentials?, Error?) -> Void)Parameters
completionHandlercompletionHandler which would have
AWSCredentialsif successfully retrieved, else error. -
Asynchronous deleteUser method which requires network activity.
Declaration
Swift
public func deleteUser(completionHandler: @escaping ((Error?) -> Void))Parameters
completionHandlercompletion handler for success or error callback.
-
When called, will send a confirmation code to user which can be used to reset the password.
Declaration
Swift
public func forgotPassword(username: String, clientMetaData: [String:String] = [:], completionHandler: @escaping ((ForgotPasswordResult?, Error?) -> Void))Parameters
usernameusername of the user who forgot the password.
clientMetaDataA map of custom key-value pairs that you can provide as input for any custom workflows that this action triggers.
completionHandlercompletionHandler which will be called when result is available.
-
Resets the password for the user if they have a valid confirmation code using the specified new password.
Declaration
Swift
public func confirmForgotPassword(username: String, newPassword: String, confirmationCode: String, clientMetaData: [String:String] = [:], completionHandler: @escaping ((ForgotPasswordResult?, Error?) -> Void))Parameters
usernameusername of the user who forgot the password
newPasswordthe new password which the user wants to set
confirmationCodethe confirmation code sent to the user
clientMetaDataA map of custom key-value pairs that you can provide as input for any custom workflows that this action triggers.
completionHandlercompletionHandler which will be called when a result is available.
-
Change password of a logged in user.
Declaration
Swift
public func changePassword(currentPassword: String, proposedPassword: String, completionHandler: @escaping ((Error?) -> Void))Parameters
currentPasswordcurrent password of the user.
proposedPasswordthe new password which user wants to set.
completionHandlercompletionHandler which will be called when the result is avilable. If error is nil, the change was successful.
-
Signs in a user with the given username and password.
Declaration
Swift
public func signIn(username: String, password: String, validationData: [String: String]? = nil, clientMetaData: [String: String] = [:], completionHandler: @escaping ((SignInResult?, Error?) -> Void))Parameters
usernameusername of the user.
passwordpassword of the user.
validationDatavalidation data for this sign in. Overrides any key-value pairs in
clientMetadatawhen the same key exists in validation data.clientMetaDataA map of custom key-value pairs that you can provide as input for any custom workflows that this action triggers.
completionHandlercompletionHandler which will be called when result is available.
-
Confirm a sign in which requires additional validation via steps like SMS MFA.
Declaration
Swift
public func confirmSignIn(challengeResponse: String, userAttributes: [String:String] = [:], clientMetaData: [String:String] = [:], completionHandler: @escaping ((SignInResult?, Error?) -> Void))Parameters
challengeResponseconfirmation code or TOTP token which is available to the user.
userAttributesuser attributes required for the operation.
clientMetaDataA map of custom key-value pairs that you can provide as input for any custom workflows that this action triggers.
completionHandlercompletionHandler which will be called when result is available.
-
Federates a social provider like Google, Facebook, Amazon or Twitter. If user is already signed in through the
signInmethod, it will returnAWSMobileClientError.federationProviderExistserror. If federation provider name has changed, previous federation provider’s token will be erased and the new token will be used going forward; the user state is un-affected in that case.Declaration
Swift
public func federatedSignIn(providerName: String, token: String, federatedSignInOptions: FederatedSignInOptions = FederatedSignInOptions(), completionHandler: @escaping ((UserState?, Error?) -> Void))Parameters
providerNameProvider name for federation provider, e.g. graph.facebook.com, accounts.google.com
tokenThe
idTokencompletionHandlercompletion handler on successful credentials fetch.
-
Shows a fully managed sign in screen which allows users to sign up and sign in.
Declaration
Swift
@available(iOS 13, *) public func showSignIn(presentationAnchor: ASPresentationAnchor, hostedUIOptions: HostedUIOptions, _ completionHandler: @escaping(UserState?, Error?) -> Void)Parameters
presentationAnchorThe presentation Anchor to show the ASWEbAuthenticationSession
hostedUIOptionsThe options object which allows showSignIn to present a hosted web UI.
completionHandlerThe completion handler to be called when user finishes the sign in action.
-
Shows a fully managed sign in screen which allows users to sign up and sign in.
Declaration
Swift
public func showSignIn(navigationController: UINavigationController, signInUIOptions: SignInUIOptions = SignInUIOptions(), hostedUIOptions: HostedUIOptions? = nil, _ completionHandler: @escaping(UserState?, Error?) -> Void)Parameters
navigationControllerThe navigation controller which would act as the anchor for this UI.
signInUIOptionsThe options object which allows changing logo, background color and if the user can cancel the sign in operation if using native auth UI. This options object will be ignored if
hostedUIOptionsis passed in.hostedUIOptionsThe options object which allows showSignIn to present a hosted web UI. If passed,
signInUIOptionsare ignored since they are applicable only to native UI.completionHandlerThe completion handler to be called when user finishes the sign in action.
-
Undocumented
Declaration
Swift
public func getViewController() -> UIViewController -
Undocumented
Declaration
Swift
public func shouldLaunchSignInVCIfRefreshTokenIsExpired() -> Bool -
Asynchronous signout method which requires network activity. Based on the options specified in
SignOutOptions, appropriate tasks will be performed.Declaration
Swift
@available(iOS 13, *) public func signOut(presentationAnchor: ASPresentationAnchor, options: SignOutOptions = SignOutOptions(), completionHandler: @escaping ((Error?) -> Void))Parameters
optionsSignOutOptions which specify actions.
presentationAnchorIf you have
completionHandlercompletion handler for success or error callback.
-
Asynchronous signout method which requires network activity. Based on the options specified in
SignOutOptions, appropriate tasks will be performed.Declaration
Swift
public func signOut(options: SignOutOptions = SignOutOptions(), completionHandler: @escaping ((Error?) -> Void))Parameters
optionsSignOutOptions which specify actions.
completionHandlercompletion handler for success or error callback.
-
Signs out the current logged in user and clears the local keychain store. Note: This does not invalidate the tokens from the service or sign out the user from other devices.
Declaration
Swift
public func signOut() -
Invoke this function to release any sign-in waits. When you receive a notifcation which is
signedOutFederatedTokensInvalidorsignedOutUserPoolsTokensInvalidyou need to provide SDK the token viafederatemethod or call thesignInmethod and complete the sign-in flow. If you can’t get the latest token from the user, you can call this method to un-block any waiting calls.Declaration
Swift
public func releaseSignInWait() -
Sign up with username, password and other attrbutes like phone, email.
Declaration
Swift
public func signUp(username: String, password: String, userAttributes: [String: String] = [:], validationData: [String: String] = [:], clientMetaData: [String:String] = [:], completionHandler: @escaping ((SignUpResult?, Error?) -> Void))Parameters
usernameusername of the user.
passwordpassword of the user
userAttributesuser attributes which contain attributes like phone_number, email, etc.
validationDatavalidation data for the user.
clientMetaDataA map of custom key-value pairs that you can provide as input for any custom workflows that this action triggers.
completionHandlercompletionHandler which will be called when a sign up result is available.
-
Confirms a sign up for a user using a verification code.
Declaration
Swift
public func confirmSignUp(username: String, confirmationCode: String, clientMetaData: [String:String] = [:], completionHandler: @escaping ((SignUpResult?, Error?) -> Void))Parameters
usernameusername of the user.
confirmationCodeconfirmation code sent to the user.
clientMetaDataA map of custom key-value pairs that you can provide as input for any custom workflows that this action triggers.
completionHandlercompletionHandler which will be called when a result is available.
-
Re-sends the sign up code to the user via email or phone_number.
Declaration
Swift
public func resendSignUpCode(username: String, clientMetaData: [String:String] = [:], completionHandler: @escaping ((SignUpResult?, Error?) -> Void))Parameters
usernameusername of the user who wants a new registration code.
clientMetaDataA map of custom key-value pairs that you can provide as input for any custom workflows that this action triggers.
completionHandlercompletionHandler which will be called when a result is available.
-
Returns cached UserPools auth JWT tokens if valid. If the
idTokenis not valid, and a refresh token is available, refresh token is used to get a newidToken. If there is no refresh token and the user is signed in, a notification is dispatched to indicate requirement of user to re-signin. The call to wait will be synchronized so that if multiple threads call this method, they will block till the first thread gets the token.Declaration
Swift
public func getTokens(_ completionHandler: @escaping TokenCompletion)Parameters
completionHandlerTokens if available, else error.
-
Verify a user attribute like phone_number.
This method is only valid for users signed in via UserPools (either directly or via HostedUI).
Declaration
Swift
public func verifyUserAttribute(attributeName: String, clientMetaData: [String:String] = [:], completionHandler: @escaping ((UserCodeDeliveryDetails?, Error?) -> Void))Parameters
attributeNamename of the attribute.
clientMetaDataA map of custom key-value pairs that you can provide as input for any custom workflows that this action triggers.
completionHandlercompletionHandler which will be called when the result is avilable.
-
Update the attributes for a user.
This method is only valid for users signed in via UserPools (either directly or via HostedUI).
Declaration
Swift
public func updateUserAttributes(attributeMap: [String: String], clientMetaData: [String:String] = [:], completionHandler: @escaping (([UserCodeDeliveryDetails]?, Error?) -> Void))Parameters
attributeMapthe attribute map of the user.
clientMetaDataA map of custom key-value pairs that you can provide as input for any custom workflows that this action triggers.
completionHandlercompletionHandler which will be called when the result is avilable.
-
Fetches the attributes for logged in user.
This method is only valid for users signed in via UserPools (either directly or via HostedUI).
Declaration
Swift
public func getUserAttributes(completionHandler: @escaping (([String : String]?, Error?) -> Void))Parameters
completionHandlercompletion handler which will be invoked when result is available.
-
Confirm the updated attributes using a confirmation code.
This method is only valid for users signed in via UserPools (either directly or via HostedUI).
Declaration
Swift
public func confirmUpdateUserAttributes(attributeName: String, code: String, completionHandler: @escaping ((Error?) -> Void))Parameters
attributeNamethe attribute to be confirmed.
codethe code sent to the user.
completionHandlercompletionHandler which will be called when the result is avilable.
-
Confirm the attribute using a confirmation code.
This method is only valid for users signed in via UserPools (either directly or via HostedUI).
Declaration
Swift
public func confirmVerifyUserAttribute(attributeName: String, code: String, completionHandler: @escaping ((Error?) -> Void))Parameters
attributeNamethe attribute to be verified.
codethe code sent to the user.
completionHandlercompletionHandler which will be called when the result is avilable.
-
Asynchronously returns a valid AWS credentials or an error object if it cannot retrieve valid credentials. It should cache valid credentials as much as possible and refresh them when they are invalid.
Declaration
Swift
override public func credentials() -> AWSTask<AWSCredentials>Return Value
A valid AWS credentials or an error object describing the error.
-
Invalidates the cached temporary AWS credentials. If the credentials provider does not cache temporary credentials, this operation is a no-op.
Declaration
Swift
override public func invalidateCachedTemporaryCredentials() -
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.
Declaration
Swift
override public func getIdentityId() -> AWSTask<NSString>Return Value
Asynchronous task which contains the identity id or error.
-
Clear the cached AWS credentials for this provider.
Declaration
Swift
override public func clearCredentials() -
Clear ALL saved values for this provider (identityId, credentials, logins).
Declaration
Swift
override public func clearKeychain()
-
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.
Declaration
Swift
public func logins() -> AWSTask<NSDictionary>
View on GitHub
Install in Dash
AWSMobileClient Class Reference