这个错误指明用户在登录时需要提供新密码,并且在其用户属性中缺少必需的属性。为了解决此问题,您需要确保向Cognito提交正确的用户属性,以便他们可以成功登录。以下是一个简单的代码示例,可以使用execute方法更新用户的属性:
use Aws\CognitoIdentityProvider\CognitoIdentityProviderClient;
$client = new CognitoIdentityProviderClient([...]);
$response = $client->respondToAuthChallenge([
'ClientId' => 'your-client-id',
'ChallengeName' => 'NEW_PASSWORD_REQUIRED',
'Session' => 'the-session-id-from-initiate-auth-response',
'ChallengeResponses' => [
'NEW_PASSWORD' => 'the-new-password',
'USERNAME' => 'the-username',
'userAttributes' => [
'email' => 'the-email-address',
'name' => 'the-name',
'custom:attribute_name' => 'the-custom-attribute-value',
],
],
]);
在上面的代码中,您需要'your-client-id”替换为您应用程序的客户端ID,并'the-session-id-from-initiate-auth-response”替换为从initiate-auth响应中获取的会话ID。您还需要'the-new-password”替换为用户提供的新密码,并将用户属性替换为正确的值。
如果您仍然遇到此错误,请确保您正确初始化CognitoIdentityProviderClient,并使用正确的AWS凭证进行身份验证。
上一篇:AWSCognitoOIDC联合身份不读取访问令牌中的声明。
下一篇:AwsCognitoPHPSDK在使用MicrosoftActiveDirectory进行SAML身份验证时不返回自定义属性。