用户在AWS Cognito用户池中显示,而不显示在身份池

时间:2017-01-31 11:26:08

标签: ios amazon-web-services swift3 amazon-cognito aws-mobilehub

所以我最近将用户池ID,App Client ID,Region Type和App Client Secret更改为新的User和Identity池。 但是,当我构建并测试它时,事情就像预期的那样,用户创建并登录身份验证过程。

唯一的问题是,当我检查新用户池时,它显示已创建了包含所有详细信息等的用户身份。但是当我检查身份池时,它显示没有用户登录过。

我已检查过IAM角色,两者在移动集线器以及我创建的用户池和标识池中都是相同的。

这个项目目前由MobileHub框架提供支持,我不太确定我应该使用哪个Cognito框架。

注册视图控制器类

// MARK: - IBAction Sign up button.
@IBAction func SignUpButton(_ sender: Any) {
    guard let usernameValue = self.Username.text, !usernameValue.isEmpty,
        let passwordValue = self.Password.text, !passwordValue.isEmpty
        else {
            showAlertBad(title: "Missing required fields", message: "Please enter a username or password.")
            return
    }

    var attributes = [AWSCognitoIdentityUserAttributeType]()

    if let emailValue = self.Email.text, !emailValue.isEmpty {
        let email = AWSCognitoIdentityUserAttributeType()
        email?.name = "email"
        email?.value = emailValue
        attributes.append(email!)
    }


    // Sign up the user
    self.pool?.signUp(usernameValue, password: passwordValue, userAttributes: attributes, validationData: nil).continue ({[weak self] (task: AWSTask) -> AnyObject? in
        guard let strongSelf = self else { return nil }
        DispatchQueue.main.async(execute: {

            if let error = task.error {
                _ = task.error
                // Error handling code goes here.
                self?.showAlertBad(title: "Uh Oh!", message: error.localizedDescription)

            } else if let result = task.result   {
                // handle the case where user has to confirm his identity via email / SMS
                if (result.user.confirmedStatus != AWSCognitoIdentityUserStatus.confirmed) {
                    strongSelf.sentTo = result.codeDeliveryDetails?.destination
                    strongSelf.performSegue(withIdentifier: "SignUpConfirmSegue", sender: sender)
                } else {
                   // Fantastic the user has been able to Sign up!
                    self?.showAlertGood(title: "Registration Complete", message: "Registration was successful.")

                    strongSelf.presentingViewController?.dismiss(animated: true, completion: nil)
                }
            }
        })
        return nil
    })

}

登录查看控制器类

func handleLoginWithSignInProvider(signInProvider: AWSSignInProvider) {

    AWSIdentityManager.defaultIdentityManager().loginWithSign(signInProvider, completionHandler: {(result, error) -> Void in
        if error == nil {
            /* If no error reported by the Sign in provider, discard the sign in view controller */
            DispatchQueue.main.async(execute: {
                self.presentingViewController?.dismiss(animated: true, completion: nil)
            })
        }
        print("Login with sign in provider result = \(result), error =\(error)")
    })
}

0 个答案:

没有答案