【问题标题】:MissingAuthenticationTokenException ("Missing Authentication Token") from CognitoIdentityProviderClient::adminCreateUser()来自 CognitoIdentityProviderClient::adminCreateUser() 的 MissingAuthenticationTokenException(“缺少身份验证令牌”)
【发布时间】:2019-09-17 16:49:00
【问题描述】:

我有一个 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',
]);

【问题讨论】:

  • 所以我猜你已经访问过这个链接,但是我想我会把它留在这里以保持完整性docs.aws.amazon.com/cognito-user-identity-pools/latest/…
  • 只是一个查询:只有 AdminCreateUser 在 PHP 中失败,还是其他 Cognito Admin API 也失败了?由于未正确设置适用于 PHP 的 AWS 开发工具包,您似乎收到此错误,并且与 Cognito 无关。
  • 我尝试的所有管理操作都以同样的方式失败,以及像 listUserPools 这样的操作,但像 initiateAuth 和 respondToAuthChallenge 这样的操作工作正常。您能否建议可能导致这种情况的设置问题?

标签: php amazon-web-services aws-sdk amazon-cognito


【解决方案1】:

您需要从 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 需要开发人员凭据。

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

传递 false 以使用空凭据而不签署请求。

需要对请求进行签名以提供开发者凭据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-03
    • 1970-01-01
    • 2020-08-27
    • 2017-02-24
    • 1970-01-01
    • 2020-04-19
    • 2019-03-25
    • 2020-09-18
    相关资源
    最近更新 更多