【发布时间】:2016-09-25 18:14:55
【问题描述】:
我已设置 API Gateway Endpoints,授权启用为 IAM。
首先,我尝试使用自己的用户凭据(密钥、机密)访问资源,并且成功了。
然后,我使用身份池设置了 Cognito。该池允许经过身份验证和未经身份验证的访问。 我已经使用 PHP SDK 生成了凭据:
$id = $cognitoClient->getId([
'AccountId' => 'xxx',
'IdentityPoolId' => 'xxx',
]);
$credentials = $cognitoClient->getCredentialsForIdentity([
'IdentityId' => $id->get('IdentityId')
])->get('Credentials');
这能够生成凭据 - 正在返回 AccessKeyId、SecretKey 和 SessionToken。
我附加的未经身份验证访问的角色定义如下:
信任关系:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "cognito-identity.amazonaws.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"cognito-identity.amazonaws.com:aud": "xxx"
}
}
}
]
}
内联策略:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "cognito-sync:*",
"Resource": [
"arn:aws:cognito-sync:us-east-1:123456789012:identitypool/${cognito-identity.amazonaws.com:aud}/identity/${cognito-identity.amazonaws.com:sub}/*"
]
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "cognito-sync:*",
"Resource": [
"arn:aws:cognito-sync:us-east-1:xxxxx:identitypool/*"
]
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"apigateway:*"
],
"Resource": [
"*"
]
}
]
}
我没有为该角色附加任何托管策略。
现在,在使用 PHP SDK 生成凭据后,我使用邮递员访问资源(我在使用我的帐户凭据时也使用了邮递员)。此调用给出以下错误:
{"message":"The security token included in the request is invalid."}
我无法确定这里出了什么问题。
【问题讨论】:
标签: php amazon-web-services amazon-cognito aws-api-gateway