AWSCognitoIdentityMultiFactorAuthentication никогда не возвращается

Я реализовал пример из 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 я никогда не получаю обратный вызов метода didCompleteMultifactorAuthenticationStepWithError в делегате AWSCognitoIdentityMultiFactorAuthentication.

Есть мысли, в чем может заключаться мое упущение?


person Perry Hoekstra    schedule 04.11.2019    source источник


Ответы (1)


Хорошо, решение состоит в том, чтобы НЕ использовать AWSCognitoIdentify, вместо этого используйте AWSMobileClient. Я пропустил метод проверки MFA:

AWSMobileClient.sharedInstance().confirmSignIn(challengeResponse: mfaCode) { (signInResult, error) in

    DispatchQueue.main.async {self.handleConfirmation(signInResult: signInResult, error: error)}
     }
}
person Perry Hoekstra    schedule 09.11.2019