【问题标题】:AWS Cognito Developer Authentication in PHPPHP 中的 AWS Cognito 开发人员身份验证
【发布时间】:2015-05-15 22:29:59
【问题描述】:

我正在尝试使用 PHP SDK 实现开发者身份验证,但一直收到此错误:

致命错误:未捕获 Aws\CognitoIdentity\Exception\CognitoIdentityException:AWS 错误 代码:AccessDeniedException,状态代码:400,AWS 请求 ID: da162f98-fb50-11e4-937e-0bf2642a4752,AWS 错误类型:客户端,AWS 错误消息:用户:arn:aws:iam::256661818246:user/tester 不是 授权执行: 认知身份:GetOpenIdTokenForDeveloperIdentity 资源: arn:aws:cognito-identity:us-east-1:256661818246:identitypool/us-east-1:69767873-2de2-4cc7-a78f-3d18b5e9bf71, 用户代理:aws-sdk-php2/2.8.3 Guzzle/3.9.3 curl/7.20.0 PHP/5.3.6 投入 /var/www/html/aws/Aws/Common/Exception/NamespaceExceptionFactory.php 在第 91 行

这是我的示例代码:

<?php
session_start();

//Include AWS client libs
require (dirname(__DIR__).'/aws/aws-autoloader.php');
use Aws\CognitoIdentity\CognitoIdentityClient;
use Aws\Sts\StsClient;

/* Global Vars */
$aws_region = 'us-east-1';
$aws_key = '<AWS_KEY>';
$aws_secret = '<AWS_SECRET>';
$aws_account_id = '<AWS_ACCOUNT_ID>';
$identity_pool_id = 'us-east-1:xxxx-xxxx-xxxx-xxxx';

//Initialize a Cognito Identity Client using the Factory
$client = CognitoIdentityClient::factory(array('region' => $aws_region, 'key' => $aws_key, 'secret' => $aws_secret));

/* Acquire new Identity */
$identity = $client->getOpenIdTokenForDeveloperIdentity(array('IdentityPoolId' => $identity_pool_id, 'Logins' => array('login.custom.traffic' => 'jkljkasdjk')));

//Obtain Identity from response data structure
$id = $identity->get('IdentityId');
echo "IdentityId: ".$id;
?>

我怀疑在尝试获取开发者身份时发生错误。我错过了什么?

【问题讨论】:

    标签: php amazon-web-services


    【解决方案1】:

    此错误背后的原因是 IAM 用户“tester”可能没有附加策略。 您可以从 IAM 控制台附加一个现有的策略“AmazonCognitoDeveloperAuthenticatedIdentities”,该策略允许该用户访问 Cognito API,包括“getOpenIdTokenForDeveloperIdentity”。

    【讨论】:

    • 谢谢维奈。正如您正确提到的那样,我花了很多时间搜索 Cognito 的身份池,而不是 IAM。
    猜你喜欢
    • 1970-01-01
    • 2014-12-05
    • 2015-04-15
    • 2016-06-29
    • 2015-01-05
    • 2015-11-05
    • 2015-05-10
    • 1970-01-01
    • 2018-05-17
    相关资源
    最近更新 更多