3

I've been working on an iOS application that uses AWS Mobile Hub as a backend, and I can't seem to figure out how to implement a custom authentication UI for the User sign in feature. Better yet, I can't find any docs that at least give a hint at how i'm supposed to do it. The only single bit of resources I found was AWS's provided Auth UI feature, which is not ideal in my circumstance. (i should mention that I am a bit new to AWS development on swift)

The idea is I can use the provided awsconfiguration.json given to you when you launch a new project on Mobile Hub, then integrate it into a UIViewController class to use for authentication without using the AuthUI library.

Here's what i've tried:

@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var passwordField: UITextField!

var passwordAuthenticationCompletion: AWSTaskCompletionSource<AWSCognitoIdentityPasswordAuthenticationDetails>!

func getDetails(_ authenticationInput: AWSCognitoIdentityPasswordAuthenticationInput, passwordAuthenticationCompletionSource: AWSTaskCompletionSource<AWSCognitoIdentityPasswordAuthenticationDetails>) {
    passwordAuthenticationCompletion = passwordAuthenticationCompletionSource
}

@IBAction func logInTapped(_ sender: Any) {
    var emailText = emailField.text!
    var passwordText = passwordField.text!

    passwordAuthenticationCompletion.set(result: AWSCognitoIdentityPasswordAuthenticationDetails.init(username: emailText, password: passwordText))
}

func didCompleteStepWithError(_ error: Error?) {
    if error != nil {
        let alertController = UIAlertController(title: error?.localizedDescription, message: "error", preferredStyle: UIAlertControllerStyle.alert)
        alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.default, handler: nil))

        self.present(alertController, animated: true, completion: nil)
    } else {
        print("logged in")
    }
}

I get returned nil when passwordAuthenticationCompletion.set() is called. Could somebody tell me what i'm doing wrong, or possibly point me in the right direction?

Thanks.

  • Have you seen the swift [User Pool Sample](https://github.com/awslabs/aws-sdk-ios-samples/tree/master/CognitoYourUserPools-Sample/Swift) or perhaps the corresponding [docs on ios cognito user pool integration](https://docs.aws.amazon.com/cognito/latest/developerguide/tutorial-integrating-user-pools-ios.html) – Jacob Lange Apr 17 '18 at 03:48
  • Unfortunately the documentation is only in objective-C but you should be able to follow along via the swift user pool sample. – Jacob Lange Apr 17 '18 at 03:49
  • Yeah, I have looked at those. I understand how the cognito Auth flow works, but I thought that a UserPool object would be initialized in awsmobileclient getting its information from the awsconfiguration.json file. How do I access it? – Hunter Lovell Apr 17 '18 at 04:01
  • Hmm, I'm honestly not sure as I don't use the AWSMobileClient I found the documentation was really poor. I've only ever used AWSCognitoIdentityProvider directly, basically by modifying the user pool sample for my needs. – Jacob Lange Apr 17 '18 at 04:09

1 Answers1

1

Found it out.
The way to access the Default cognito user pool thats attached to mobile hub is by importing the AWSUserPoolsSignIn library, and use AWSCognitoUserPoolsSignInProvider.sharedInstance().

  • Where did you find that? Jesus the documentation for this thing is a complete shitshow. – Rob Aug 15 '18 at 21:59