AWS Cloudfront 签名 Cookie 不适用于备用域
AWS Cloudfront Signed Cookie not working on alternate domain
问题
我有 Access Denied
使用固定策略和自定义策略对带有签名 cookie 的云端 GET 请求。
详情
cdn.example.com
是abc.cloudfront.net
的备用域名,在cloudfront和cloudflare上都设置了CNAME
- 我希望在
abc.example.com/authorize
之后可以访问 cdn.example.com
。
- 我用的是PHP,Laravel在
abc.example.com/authroize
后面,代码如下
```
$cloudFront = new Aws\CloudFront\CloudFrontClient([
'region' => 'us-west-2',
'version' => '2014-11-06'
]);
$resourceKey = 'http://cdn.example.com';
$expires = time() + 300;
$signedCookieCannedPolicy = $cloudFront->getSignedCookie([
'url' => $resourceKey,
'expires' => $expires,
'private_key' => 'pk.pem',
'key_pair_id' => 'XXXXXXXXXXXXXX',
]);
$response = Response::success();
foreach ($signedCookieCannedPolicy as $name => $value) {
$response->withCookie(Cookie::make($name, $value, 360, null, 'example.com'));
}
return $response;
```
- Cookie 是为
.example.com
设置的
- 当我转到
cdn.example.com
时,显示以下消息
提前致谢。
原来问题出在加密的 cookie 上。您可能需要检查:https://laravel.com/api/5.2/Illuminate/Cookie/CookieJar.html#method_make 如果您使用的是 Laravel 5.2,请确保在使用中间件加密时添加了异常。
问题
我有 Access Denied
使用固定策略和自定义策略对带有签名 cookie 的云端 GET 请求。
详情
cdn.example.com
是abc.cloudfront.net
的备用域名,在cloudfront和cloudflare上都设置了CNAME- 我希望在
abc.example.com/authorize
之后可以访问cdn.example.com
。 - 我用的是PHP,Laravel在
abc.example.com/authroize
后面,代码如下
```
$cloudFront = new Aws\CloudFront\CloudFrontClient([
'region' => 'us-west-2',
'version' => '2014-11-06'
]);
$resourceKey = 'http://cdn.example.com';
$expires = time() + 300;
$signedCookieCannedPolicy = $cloudFront->getSignedCookie([
'url' => $resourceKey,
'expires' => $expires,
'private_key' => 'pk.pem',
'key_pair_id' => 'XXXXXXXXXXXXXX',
]);
$response = Response::success();
foreach ($signedCookieCannedPolicy as $name => $value) {
$response->withCookie(Cookie::make($name, $value, 360, null, 'example.com'));
}
return $response;
```
- Cookie 是为
.example.com
设置的
- 当我转到
cdn.example.com
时,显示以下消息
提前致谢。
原来问题出在加密的 cookie 上。您可能需要检查:https://laravel.com/api/5.2/Illuminate/Cookie/CookieJar.html#method_make 如果您使用的是 Laravel 5.2,请确保在使用中间件加密时添加了异常。