在AWS Cognito中,更新邮箱后如何重新发送验证码?
解决方案:重发AWS Cognito邮箱更新后的验证验证码
- 正确接口:使用
GetUserAttributeVerificationCode接口,该接口专门用于重发用户属性更新后的验证验证码,完全匹配你的场景。 - 无效原因说明:
ResendConfirmationCode仅服务于注册阶段的账号确认流程,和属性更新的验证流程属于独立的验证码体系,所以生成的验证码无法通过VerifyUserAttribute校验。- 重复调用
updateUserAttributes设置相同邮箱时,Cognito会判定属性值无变更,不会触发新的验证邮件发送逻辑。
- PHP代码示例(基于AWS SDK for PHP):
use Aws\CognitoIdentityProvider\CognitoIdentityProviderClient; // 初始化Cognito客户端 $client = new CognitoIdentityProviderClient([ 'region' => '你的AWS区域', 'version' => 'latest', 'credentials' => [ 'key' => '你的AWS Access Key', 'secret' => '你的AWS Secret Key', ], ]); // 调用接口重发验证码 $result = $client->getUserAttributeVerificationCode([ 'Username' => '用户的用户名或ID', 'UserPoolId' => '你的Cognito用户池ID', 'AttributeName' => 'email', // 指定要重发验证的属性为邮箱 ]); // 可选:获取返回的会话值(用于后续关联操作) $session = $result['Session'];
内容的提问来源于stack exchange,提问作者Emilien
相关产品推荐
相关产品推荐

