AWSCognitoIdentityMultiFactorAuthentication Никогда не возвращается - PullRequest
0 голосов
/ 04 ноября 2019

Я реализовал пример из 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 делегате.

Есть какие-нибудь мысли о том, каким может быть мое упущение?

1 Ответ

0 голосов
/ 09 ноября 2019

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

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

    DispatchQueue.main.async {self.handleConfirmation(signInResult: signInResult, error: error)}
     }
}
...