I am trying to explicitly sign into AWS Cognito on iOS in Swift.
Most of the samples show a delegate approach to displaying the sign in UI when user.getDetails is called, but I would like to simply show my sign in UI and explicitly sign in with user.getSession.
My User Pool and App Client is set up in AWS console.
Default service configuration is set in the code.
var serviceManager = AWSServiceManager.default()!
var serviceConfiguration = AWSServiceConfiguration(region: .APNortheast1, credentialsProvider: nil)
serviceManager.defaultServiceConfiguration = serviceConfiguration
The pool configuration is set up in code with my clientid, clientsecret, and poolid.
let poolConfiguration = AWSCognitoIdentityUserPoolConfiguration(clientId: "MY_ID", clientSecret: "MY_SECRET", poolId: "POOL_ID")
AWSCognitoIdentityUserPool.register(with: AWSManager.shared().serviceConfiguration, userPoolConfiguration: poolConfiguration, forKey: "UserPool")
userPool = AWSCognitoIdentityUserPool(forKey: "UserPool")
However trying to call get session the task result is always nil.
let cognitoUser = AuthenticationManager.shared().userPool.currentUser()
let getSessionTask = cognitoUser?.getSession(email, password: password, validationData: nil)
getSessionTask?.continueWith(block: { (task) -> Any? in
print("result: \(String(describing: task.result))")
if let result = task.result {
print("user signed in? \(cognitoUser?.isSignedIn)")
}
return nil
}, cancellationToken: nil)
What is the proper way to explicitly sign in and check if sign worked or if there was an error such as incorrect credentials?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.