getUser() 之类的操作有效,但 $client->adminCreateUser() 等操作无效。 当我调用 $client->a-6ren">
gpt4 book ai didi

php - 来自 CognitoIdentityProviderClient::adminCreateUser() 的 MissingAuthenticationTokenException ("Missing Authentication Token")

转载 作者:可可西里 更新时间:2023-11-01 12:56:21 26 4
gpt4 key购买 nike

我有 AWS PHP SDK 的有效实现。 $client->getUser() 之类的操作有效,但 $client->adminCreateUser() 等操作无效。

当我调用 $client->adminCreateUser([...]) 时,结果是:

Error executing "AdminCreateUser" on "https://cognito-idp.ap-southeast-2.amazonaws.com"; AWS HTTP error: Client error: `POST https://cognito-idp.ap-southeast-2.amazonaws.com` resulted in a `400 Bad Request` response:
{"__type":"MissingAuthenticationTokenException","message":"Missing Authentication Token"}
MissingAuthenticationTokenException (client): Missing Authentication Token - {"__type":"MissingAuthenticationTokenException","message":"Missing Authentication Token"}

/var/www/project/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php 中的 191

使用完全相同的凭据从 CLI(例如 cognito-idp admin-create-user)调用的类似服务正在运行。

这是什么原因造成的?


示例详细信息

我的环境:

  • Ubuntu 18.04
  • Apache 2.4.29
  • PHP 7.3
  • aws/aws-sdk-php 3.92.3

.aws/凭证

[default]
aws_access_key_id=XXXX
aws_secret_access_key=XXXX

我正在使用我的开发者凭证

示例代码:

$client = new CognitoIdentityProviderClient([
'version' => 'latest',
'region' => 'ap-southeast-2',
'credentials' => false, // Set to false to allow roles provisioned to our EC2 instances
]);

$result = $client->adminCreateUser([
'DesiredDeliveryMediums' => ['Email'],
'MessageAction' => 'RESEND',
'TemporaryPassword' => 'TemporaryPassword1234',
'UserAttributes' => [
['Name' => 'email', 'Value' => 'mailbox@domain.tld'],
],
'UserPoolId' => 'ap-southeast-2_XXXX',
'Username' => 'mailbox@domain.tld',
]);

最佳答案

您需要从 CognitoIdentityProviderClient 配置中删除 'credentials' => false

adminCreateUser() 操作需要一个签名的请求(不像 signUp() 这样的操作,这就是为什么 signUp() 可以与未签名的请求,但 adminCreateUser() 和其他需要开发人员凭据的操作不会)

来自 AWS 文档

https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-cognito-idp-2016-04-18.html#admincreateuser

AdminCreateUser requires developer credentials.

https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_configuration.html#credentials

Pass false to use null credentials and not sign requests.

需要签署请求以提供开发者凭据。

关于php - 来自 CognitoIdentityProviderClient::adminCreateUser() 的 MissingAuthenticationTokenException ("Missing Authentication Token"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55896967/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com