如何启用Cognito用户MFA

I faced an issue that when I call

enableMFAStatus, err := cogIProv.AdminSetUserMFAPreferenceWithContext(ctx, &cip.AdminSetUserMFAPreferenceInput{
    UserPoolId: aws.String(userPoolID),
    Username:   aws.String(username),
    SMSMfaSettings: &cip.SMSMfaSettingsType{
        Enabled:      aws.Bool(enableMFA),
        PreferredMfa: aws.Bool(true),
    },
})

it just do nothing with success response. Are there some other ways to enable SMS MFA for cognito userpool user?

There are only two API calls to enable/disable MFA for a user in a Cognito User Pool:

  • SetUserMFAPreference[a]
  • AdminSetUserMFAPreference[b]

As stated in the official AWS API documentation, both of these API calls do not return any response JSON, and there would be an empty HTTP 200 response if the API calls execute without any errors. To test and understand the behaviour of the APIs, I would recommend Cognito users to test them via the AWS CLI, before using them in an SDK of a chosen programming language.

References

[a]. https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_SetUserMFAPreference.html

[b]. https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminSetUserMFAPreference.html