Amazon web services AWS PHP SDK-如何为联邦用户生成登录端点?
有人能帮我使用AWS STS getFederationTokenAPI为联邦用户生成登录终点吗 以下是我的代码-Amazon web services AWS PHP SDK-如何为联邦用户生成登录端点?,amazon-web-services,aws-php-sdk,aws-sts,Amazon Web Services,Aws Php Sdk,Aws Sts,有人能帮我使用AWS STS getFederationTokenAPI为联邦用户生成登录终点吗 以下是我的代码- <?php require 'aws-autoloader.php'; use Aws\Sts\StsClient; use Aws\Sts\Exception\StsException; $credentials = new Aws\Credentials\Credentials('MYKEY', 'MYSECRET'); $client = new StsClien
<?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());
}