rc4347/cloudfront-signer

该软件包最新版本(0.0.4)没有提供许可信息。

0.0.4 2023-07-01 16:15 UTC

This package is auto-updated.

Last update: 2024-08-30 01:34:25 UTC


README

Latest Stable Version Total Downloads

这是一个简单的 PHP 服务,使您能够轻松地将官方 AWS SDK for PHP 包含到您的 PHP 应用程序中。

它可以帮助您对文件或资源进行签名。

跳转到

入门指南

安装

您可以通过在项目的 composer.json 中添加 rc4347/cloudfront-signer 软件包来使用 Composer 安装 PHP 服务。

{
    "require": {
        "rc4347/cloudfront-signer": "^0.0.4"
    }
}

用法

use RC4347\CloudFrontSigner\credentials\AccessConfig;
use RC4347\CloudFrontSigner\credentials\ClientConfig;
use RC4347\CloudFrontSigner\credentials\ExpireConfig;
use RC4347\CloudFrontSigner\SignedUrlService;

# configuration
$client = new ClientConfig('latest', 'default', '<YOUR_S3_REGION>');
$expire = time() + 300; # returns 5 minutes
$access = new AccessConfig('<YOUR_PRIVATE_KEY>', '<YOUR_S3_KEY_PAIR_ID>'); # private key can get file or string 
$resourceKey = 'https://<YOUR_ID>.cloudfront.net/example/example.png';
$config = new ExpireConfig($resourceKey, $expire);
# Execution
/**
* @returns string "https://<YOUR_ID>.cloudfront.net/example/example.png?Expires=<EXPIRES>&Signature=<SIGNATURE>&Key-Pair-Id=<YOUR_S3_KEY_PAIR_ID>"
 */
$urlService = new SignedUrlService($config, $client, $access);
return $urlService->run();
/**
 * if policy param is empty it will be get default policy.
* @returns array|string [
        "CloudFront-Policy": <GENERATED_POLICY>,
        "CloudFront-Signature": <SIGNATURE>,
        "CloudFront-Key-Pair-Id": <YOUR_S3_KEY_PAIR_ID>
    ]
 */
$policy = <<<POLICY
{
    "Statement": [
        {
            "Resource": "{$this->config->resourceKey}",
            "Condition": {
                "DateLessThan": {"AWS:EpochTime": {$this->config->expires}}
            }
        }
    ]
}
POLICY;

$cookieService = new SignedCookieService($config, $client, $access, $policy) # policy is optional
return $cookieService->run();

资源

更多信息