【问题标题】:AWSCognitoIdentityMultiFactorAuthentication Never ReturnsAWSCognitoIdentityMultiFactorAuthentication 永不返回
【发布时间】:2020-02-29 09:08:42
【问题描述】:

我以这种方式实现了来自https://github.com/awslabs/aws-sdk-ios-samples/blob/master/CognitoYourUserPools-Sample/Swift/CognitoYourUserPoolsSample/MFAViewController.swift 的示例:

import Foundation
import UIKit
import AWSMobileClient
import AWSCognitoIdentityProvider

class MFAModalViewController: UIViewController {

    @IBOutlet weak var messageLabel: UILabel!
    @IBOutlet var backgroundView: UIView!
    @IBOutlet weak var boxView: UIView!
    @IBOutlet weak var mfaTextField: UITextField!

    public var message: String?
    var mfaCompletionSource: AWSTaskCompletionSource<NSString>?

    @IBAction func mfaTextFieldChanged(_ sender: Any) {
        if let mfaCode = mfaTextField.text, mfaCode.count == 6 {

            self.mfaCompletionSource?.set(result: NSString(string: mfaCode))
        }
    }

    override func viewDidLoad()
    {
        super.viewDidLoad()

        if let message = message {
            messageLabel.text = message
        }
    }
}

extension MFAModalViewController: AWSCognitoIdentityMultiFactorAuthentication {
    func getCode(_ authenticationInput: AWSCognitoIdentityMultifactorAuthenticationInput, mfaCodeCompletionSource: AWSTaskCompletionSource<NSString>) {
        hud.dismiss()

        self.mfaCompletionSource = mfaCodeCompletionSource
    }

    func didCompleteMultifactorAuthenticationStepWithError(_ error: Error?) {
        ...
    }
}

但是,在将 AWSTaskComplettionSource 设置为输入的 MFA 代码后,我再也没有收到对 AWSCognitoIdentityMultiFactorAuthentication 委托中的 didCompleteMultifactorAuthenticationStepWithError 方法的回调。

对我的遗漏有什么想法吗?

【问题讨论】:

    标签: ios swift amazon-cognito multi-factor-authentication


    【解决方案1】:

    好的,解决方案是不使用 AWSCognitoIdentify,而是使用 AWSMobileClient。我错过了一种 MFA 验证方法:

    AWSMobileClient.sharedInstance().confirmSignIn(challengeResponse: mfaCode) { (signInResult, error) in
    
        DispatchQueue.main.async {self.handleConfirmation(signInResult: signInResult, error: error)}
         }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-15
      • 2018-01-11
      • 2011-07-25
      • 1970-01-01
      相关资源
      最近更新 更多