添加AWS标头

时间:2016-02-05 14:24:45

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

我正在开发一个我有服务器的项目。服务器连接到Amazon-Cognito以获取Identity Id和令牌。这是我的PHP代码。

test.php的:

include 'aws.phar';

//require 'vendor/autoload.php';
use Aws\CognitoIdentity\CognitoIdentityClient;
use Aws\Sts\StsClient;
use Aws\Credentials\Credentials;
use Aws\S3\S3Client;

echo "OK";

$Client = CognitoIdentityClient::factory(array(
  'version' => 'latest',
  'profile' => 'project1',
  'region'  => 'ap-northeast-1'
));

$result = $Client->getOpenIdTokenForDeveloperIdentity(array(
  'IdentityPoolId' => 'xxxxxxxxxxxx',

  'Logins' => array(
    'login.blupinch.app' => 'sandesh-004',
  ),
  'TokenDuration' => 3600,
));

echo $token = $result['Token'];
//echo null;

当我打开浏览器并输入服务器的URL时,我只能看到“OK”,但不能看到$token的值。有趣的是,如果我从命令行执行此操作,我可以看到“OK”和$token值:

php test.php 

为什么会这样? 为什么我看不到$token的价值?

更新: 当我运行“php test.php”时。我可以看到令牌的回声。就像这个

ubuntu @ ip-172-31-30-222:/ var / www / html $ php test.php

   OKeyJraWQiOiJhcC1ub3J0aGVhc3QtMTEiLCJ0eXAiOiJKV1MiLCJhbGciOiJSUzUxMiJ9.eyJzdWIiOiJhcC1ub3J0aGVhc3QtMToxMmJiZTJjOS0zMDZkLTRmY2ItOGY4Mi0yZmNlNjc3NmE1NjQiLCJhdWQiOiJhcC1ub3J0aGVhc3QtMTphODcxZmE1Zi0yM2EyLTQ4MGQtYmFhNi1iNGVkMzE0MzcyNDQiLCJhbXIiOlsiYXV0aGVudGljYXRlZCIsImxvZ2luLmJsdXBpbmNoLmFwcCIsImxvZ2luLmJsdXBpbmNoLmFwcDphcC1ub3J0aGVhc3QtMTphODcxZmE1Zi0yM2EyLTQ4MGQtYmFhNi1iNGVkMzE0MzcyNDQ6c2FuZGVzaC0wMDQiXSwiaXNzIjoiaHR0cHM6Ly9jb2duaXRvLWlkZW50aXR5LmFtYXpvbmF3cy5jb20iLCJleHAiOjE0NTQ2ODczMzcsImlhdCI6MTQ1NDY4MzczN30.BSTYTw8bk27vuqHaElIjC1KdncJpQHQXpqJr3--eKGOIi1vq8rpTGuljm2XjNInCXvjjMTLxaG8ZN-gUHYdZGcvK6Bm9ts1Y_BPfOflVKjRU3rxemmY24gOQeb1xI0No6nvyhJW6MpkoOF2fGWmr79mL0J0PnepOQ4HxG_HJ6yGdrvRypFjDM7g7kLXvETeEYrJeDdvnYuoeh1sqRn7RkA9eea_5pq8Sbgk5bXhF1RUhLF_6pi-YMIu52-lLFZdbA0LxGTWrIKvZY-KhsKSBLt_A5ek52pXQSPJUcBFOVWgajVqpdBB7i-ls1IjLth0baLtCXgk1qsq52kDKWqvR6g

3 个答案:

答案 0 :(得分:1)

使用代码

echo $token = $result['Token'];

您只是回显将$ result ['Token']的值赋给$ token的布尔结果。看起来你应该引用'TokenDuration'

你需要这样做

$token = $result['TokenDuration'];
echo $token;

答案 1 :(得分:0)

这不会输出真,这不会是什么。

echo $token = $result['Token'];

答案 2 :(得分:0)

echo $token = !empty($result['Token']) ? $result['Token'] : "Token is empty";