问题描述
有人可以帮助我使用 AWS STS getFederationToken API为联盟用户生成登录端点吗?
以下是我的代码-
<?php
require 'aws-autoloader.php';
use Aws\Sts\StsClient;
use Aws\Sts\Exception\StsException;
$credentials = new Aws\Credentials\Credentials('MYKEY','MYSECRET');
$client = new StsClient([
'region' => 'ap-south-1','version' => '2011-06-15','credentials' => $credentials
]);
try {
$result = $client->getFederationToken(array(
// Name is required
'Name' => 'sv','Policy' => '{
"Version": "2012-10-17","Statement": [
{
"Action": [
"sns:*"
],"Effect": "Allow","Resource": "*"
}
]
}','DurationSeconds' => 28000,));
//echo '<pre>'; print_r($result);die;
$json_data = json_encode(['sessionId' => '$result["Credentials"]["AccessKeyId"]','sessionKey' => '$result["Credentials"]["SecretAccessKey"]','sessionToken' => '$result["Credentials"]["SessionToken"]'
]);
$issuer = urlencode("https://signin.aws.amazon.com/");
$destination = urlencode("https://console.aws.amazon.com/sns");
$sign_in_url = "https://signin.aws.amazon.com/federation?Action=getSigninToken&SessionType=json&Session=".urlencode($json_data);
$ch = curl_init();
// Will return the response,if false it print the response
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
// Set the url
curl_setopt($ch,CURLOPT_URL,$sign_in_url);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);
// Print the return data
$res = json_decode($result,true);
$sign_in_token = $res['SigninToken'];
$login_url = "https://signin.aws.amazon.com/federation?Action=login&Issuer=".$issuer."&Destination=".$destination."&SigninToken=".$sign_in_token;
echo $login_url;
} catch (StsException $e) {
// output error message if fails
print_r($e->getMessage());
}
正在产生以下链接-
但是当我尝试单击此链接时,它说- 您的登录链接中的凭据无效。请与您的管理员联系。
上面的代码有什么问题?
谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)