首页 > 解决方案 > AWS - Swift 中此身份池不支持未经身份验证的访问。

问题描述

我有用于注册和唱歌的自定义 UI,所以不使用 AWSAuthUI

我能够按照文档成功设置注册,并且能够在用户池中看到确认用户。

我在 DynamoDB 访问中遇到问题(身份验证问题)

波纹管是用于登录的代码

@IBAction func btn_login(_ sender: UIButton) {
    ActivityIndicator.start()
    if(txt_soul_id.text != "" && txt_pwd.text != ""){

        let emailTextField = txt_soul_id.text!
        let passwordTextField = txt_pwd.text!

        let len = passwordTextField.count
        if(len > 7){
            if(Validations.isValidPassword(password: passwordTextField)){
                let mypool = configuration.pool?.getUser(emailTextField)

                mypool?.getSession(emailTextField, password: passwordTextField, validationData: nil).continueWith(block: { (task) in
                    if(task.error != nil){
                        ActivityIndicator.stop()
                        Alerts.normal_display(msg_title: "", msg_desc: (task.error?._userInfo!["message"])!, action_title: "OK", myVC: self)
                    }else{
                        ActivityIndicator.stop()
                        DispatchQueue.main.async {
                            let vc = self.storyboard?.instantiateViewController(withIdentifier: "EditProfileVC_sid") as! EditProfileVC
                            self.navigationController?.pushViewController(vc, animated: true)
                        }
                    }
                    return nil
                })
            }else{
                ActivityIndicator.stop()
                Alerts.normal_display(msg_title: "", msg_desc: "Password must require number, special character, uppercase and lowercase letter.", action_title: "Ok", myVC: self)
            }
        }else{
            ActivityIndicator.stop()
            Alerts.normal_display(msg_title: "Minimum 8 Character", msg_desc: "Your password must be at least 8 characters", action_title: "Ok", myVC: self)
        }
    }else{
        ActivityIndicator.stop()
        Alerts.normal_display(msg_title: "Required", msg_desc: "Username and password required", action_title: "OK", myVC: self)
    }
}

成功登录后,我试图保存到我创建的 dynamodb 模型中

@IBAction func save_profile(_ sender: UIButton) {
    let dynamoDbObjectMapper = AWSDynamoDBObjectMapper.default()
    // Create data object using data models you downloaded from Mobile Hub
    let userItem: User = User()
    var stype : [String]? = nil
    stype?.append("soltype1")
     userItem._userId = AWSIdentityManager.default().identityId
    //userItem._soultypes = stype
    userItem._about = "About Me"
    userItem._bday = "19-19-1991"
    userItem._culture = "Jain"
    userItem._email = "abc@gmail.com"
    userItem._mobile = 1234567890
    userItem._mobilePrefix = "+32"
    userItem._soulid = "mysid"


    //Save a new item
    dynamoDbObjectMapper.save(userItem, completionHandler: {
        (error: Error?) -> Void in
        if let error = error {
            print("Amazon DynamoDB Save Error: \(error)")
            return
        }
        print("An item was saved.")
    })
}

userItem._userId 为零

为 identityId 提供错误 nil 以及 Amazon DynamoDB 保存错误:错误 Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=8 "(null)" UserInfo={__type=NotAuthorizedException, message=此身份池不支持未经身份验证的访问。}

标签: swiftamazon-web-servicesamazon-dynamodbamazon-cognito

解决方案


推荐阅读