0

我正在尝试使用 Amazon Cognito 和 Twitter Digits 对用户进行身份验证。当我创建用户时,会创建一个与 Digits 登录没有任何连接的未经身份验证的用户。

这是我的代码:

   override func viewDidLoad() {
        super.viewDidLoad()

        let credentialsProvider = AWSCognitoCredentialsProvider(regionType:.USEast1, identityPoolId:"us-east-1:1b21eda6-56e8-4094-a7af-XXXXXXXXXXXX")
        let configuration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: credentialsProvider)
        AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration

        let authButton = DGTAuthenticateButton(authenticationCompletion: { (session: DGTSession?, error: NSError?) in
            if (session != nil) {

                let value = (session!.authToken)! + ";" + (session!.authTokenSecret)!
                credentialsProvider.logins = ["www.digits.com" : value]

                credentialsProvider.getIdentityId().continueWithBlock({ (task) -> AnyObject? in
                    print(task.result)
                    print(task.error)

                    return nil
                })

                self.saveNumber((session?.phoneNumber)!)

            } else {
                print("Authentication error: \(error!.localizedDescription)")
            }
        })
        authButton.center = self.view.center
        self.view.addSubview(authButton)
    }

和代码saveNumber

func saveNumber(number : String) {

        let syncClient = AWSCognito.defaultCognito()
        let dataset = syncClient.openOrCreateDataset("userInfo")

        dataset.setString(number, forKey: "phoneNumber")
        dataset.synchronize().continueWithBlock { (task) -> AnyObject? in

            if task.error != nil {
                print("Uh Oh")
                print(task.error?.localizedDescription)
            }else{
                print("Yay!")
            }
            return nil
        }

    }

用户未通过身份验证

有任何想法吗?谢谢!

4

1 回答 1

0

鉴于您在“无法设置默认 Cognito 凭据提供程序和服务配置”评论中的错误消息,您似乎正在尝试在正确配置之前使用 credentialsProvider。将初始化凭证提供程序的代码移动到didFinishLaunchingWithOptionsAppDelegate。您可以通过以下方式访问 viewDidLoad 中的凭据提供程序:

AWSServiceManager.defaultServiceManager.defaultServiceConfiguration.credentialsProvider

同样通过日志记录,确保在调用任何需要凭据的操作(例如dataset.synchronize().

于 2016-06-28T16:32:18.140 回答