In AWS iOS SDK, how do I handle FORCE_CHANGE_PASSWORD User Status

后端 未结 2 2077
时光取名叫无心
时光取名叫无心 2021-01-06 09:24

I have followed the sample here

https://github.com/awslabs/aws-sdk-ios-samples/tree/master/CognitoYourUserPools-Sample

To integrate interactive cognito login

相关标签:
2条回答
  • 2021-01-06 10:08

    Sorted this now. Posting it here in case it helps anyone else.

    First, you need to create a view controller that will allow the user to specify the new password. The ViewController should have a AWSTaskCompletionSource<AWSCognitoIdentityNewPasswordRequiredDetails> as a property:

    var newPasswordCompletion: AWSTaskCompletionSource<AWSCognitoIdentityNewPasswordRequiredDetails>?
    

    Following the pattern in the sample referred to in the question, I then implemented AWSCognitoIdentityNewPasswordRequired as an extension to the view controller as follows:

    extension NewPasswordRequiredViewController: AWSCognitoIdentityNewPasswordRequired {
        func getNewPasswordDetails(_ newPasswordRequiredInput: AWSCognitoIdentityNewPasswordRequiredInput, newPasswordRequiredCompletionSource:
        AWSTaskCompletionSource<AWSCognitoIdentityNewPasswordRequiredDetails>) {                    
            self.newPasswordCompletion = newPasswordRequiredCompletionSource
        }
    
        func didCompleteNewPasswordStepWithError(_ error: Error?) {
            if let error = error as? NSError {
                // Handle error
            } else {
                // Handle success, in my case simply dismiss the view controller
                self.dismiss(animated: true, completion: nil)
            }
        }
    
    }
    

    Again following the design of the sample detailed in the question, add a function to the AWSCognitoIdentityInteractiveAuthenticationDelegate extension to AppDelegate:

    extension AppDelegate: AWSCognitoIdentityInteractiveAuthenticationDelegate {
        func startPasswordAuthentication() -> AWSCognitoIdentityPasswordAuthentication {
            //Existing implementation
        }
        func startNewPasswordRequired() -> AWSCognitoIdentityNewPasswordRequired {
            // Your code to handle how the NewPasswordRequiredViewController is created / presented, the view controller should be returned
            return self.newPasswordRequiredViewController!
        }
    }
    
    0 讨论(0)
  • 2021-01-06 10:18

    The perfect example to implement the ResetPassword when u create the user in Cognito Console.

    But, Integrating this ResetPassword mechanism to your existing app is your responsibility.

    https://github.com/davidtucker/CognitoSampleApplication/tree/article1/CognitoApplication

    0 讨论(0)
提交回复
热议问题