SignatureV4
extends AbstractSignature
in package
implements
EndpointSignatureInterface
Signature Version 4
Tags
Table of Contents
Interfaces
- EndpointSignatureInterface
- Interface for signatures that use specific region and service names when signing requests.
Constants
- DEFAULT_PAYLOAD = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
Properties
- $cacheSize : int
- $hashCache : array<string|int, mixed>
- $maxCacheSize : int
- $regionName : string
- $serviceName : string
Methods
- __construct() : mixed
- convertPostToGet() : RequestInterface
- Converts a POST request to a GET request by moving POST fields into the query string.
- createPresignedUrl() : string
- Create a pre-signed URL
- setMaxCacheSize() : self
- Set the maximum number of computed hashes to cache
- setRegionName() : self
- Set the region name instead of inferring it from a request URL
- setServiceName() : self
- Set the service name instead of inferring it from a request URL
- signRequest() : mixed
- Signs the specified request with an AWS signing protocol by using the provided AWS account credentials and adding the required headers to the request.
- createCanonicalizedPath() : mixed
- getPayload() : string
- Get the payload part of a signature from a request.
- getPresignedPayload() : string
- Get the payload of a request for use with pre-signed URLs.
- getTimestamp() : int
- Provides the timestamp used for the class (used for mocking PHP's time() function)
- addQueryValues() : mixed
- convertExpires() : mixed
- createPresignedRequest() : mixed
- createScope() : mixed
- createSigningContext() : array<string|int, mixed>
- Create the canonical representation of a request
- createStringToSign() : mixed
- getCanonicalizedQueryString() : string
- Get the canonicalized query string for a request
- getSigningKey() : string
- Get a hash for a specific key and value. If the hash was previously cached, return it
- moveHeadersToQuery() : mixed
Constants
DEFAULT_PAYLOAD
public
string
DEFAULT_PAYLOAD
= 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
Cache of the default empty entity-body payload
Properties
$cacheSize
protected
int
$cacheSize
= 0
Size of the hash cache
$hashCache
protected
array<string|int, mixed>
$hashCache
= array()
Cache of previously signed values
$maxCacheSize
protected
int
$maxCacheSize
= 50
Maximum number of hashes to cache
$regionName
protected
string
$regionName
Explicitly set region name
$serviceName
protected
string
$serviceName
Explicitly set service name
Methods
__construct()
public
__construct([string $serviceName = null ][, string $regionName = null ]) : mixed
Parameters
- $serviceName : string = null
-
Bind the signing to a particular service name
- $regionName : string = null
-
Bind the signing to a particular region name
convertPostToGet()
Converts a POST request to a GET request by moving POST fields into the query string.
public
static convertPostToGet(EntityEnclosingRequestInterface $request) : RequestInterface
Useful for pre-signing query protocol requests.
Parameters
- $request : EntityEnclosingRequestInterface
-
Request to clone
Tags
Return values
RequestInterfacecreatePresignedUrl()
Create a pre-signed URL
public
createPresignedUrl(RequestInterface $request, CredentialsInterface $credentials, mixed $expires) : string
Parameters
- $request : RequestInterface
-
Request to sign
- $credentials : CredentialsInterface
-
Credentials used to sign
- $expires : mixed
-
The time at which the URL should expire. This can be a Unix timestamp, a PHP DateTime object, or a string that can be evaluated by strtotime
Return values
stringsetMaxCacheSize()
Set the maximum number of computed hashes to cache
public
setMaxCacheSize(int $maxCacheSize) : self
Parameters
- $maxCacheSize : int
-
Maximum number of hashes to cache
Return values
selfsetRegionName()
Set the region name instead of inferring it from a request URL
public
setRegionName(string $region) : self
Parameters
- $region : string
-
Name of the region used when signing
Return values
selfsetServiceName()
Set the service name instead of inferring it from a request URL
public
setServiceName(string $service) : self
Parameters
- $service : string
-
Name of the service used when signing
Return values
selfsignRequest()
Signs the specified request with an AWS signing protocol by using the provided AWS account credentials and adding the required headers to the request.
public
signRequest(RequestInterface $request, CredentialsInterface $credentials) : mixed
Parameters
- $request : RequestInterface
-
Request to add a signature to
- $credentials : CredentialsInterface
-
Signing credentials
createCanonicalizedPath()
protected
createCanonicalizedPath(RequestInterface $request) : mixed
Parameters
- $request : RequestInterface
getPayload()
Get the payload part of a signature from a request.
protected
getPayload(RequestInterface $request) : string
Parameters
- $request : RequestInterface
Return values
stringgetPresignedPayload()
Get the payload of a request for use with pre-signed URLs.
protected
getPresignedPayload(RequestInterface $request) : string
Parameters
- $request : RequestInterface
Return values
stringgetTimestamp()
Provides the timestamp used for the class (used for mocking PHP's time() function)
protected
getTimestamp() : int
Return values
intaddQueryValues()
private
addQueryValues(mixed $scope, RequestInterface $request, CredentialsInterface $credentials, mixed $expires) : mixed
Parameters
- $scope : mixed
- $request : RequestInterface
- $credentials : CredentialsInterface
- $expires : mixed
convertExpires()
private
convertExpires(mixed $expires) : mixed
Parameters
- $expires : mixed
createPresignedRequest()
private
createPresignedRequest(RequestInterface $request, CredentialsInterface $credentials) : mixed
Parameters
- $request : RequestInterface
- $credentials : CredentialsInterface
createScope()
private
createScope(mixed $shortDate, mixed $region, mixed $service) : mixed
Parameters
- $shortDate : mixed
- $region : mixed
- $service : mixed
createSigningContext()
Create the canonical representation of a request
private
createSigningContext(RequestInterface $request, string $payload) : array<string|int, mixed>
Parameters
- $request : RequestInterface
-
Request to canonicalize
- $payload : string
-
Request payload (typically the value of the x-amz-content-sha256 header.
Return values
array<string|int, mixed> —Returns an array of context information including:
- canonical_request
- signed_headers
createStringToSign()
private
createStringToSign(mixed $longDate, mixed $credentialScope, mixed $creq) : mixed
Parameters
- $longDate : mixed
- $credentialScope : mixed
- $creq : mixed
getCanonicalizedQueryString()
Get the canonicalized query string for a request
private
getCanonicalizedQueryString(RequestInterface $request) : string
Parameters
- $request : RequestInterface
Return values
stringgetSigningKey()
Get a hash for a specific key and value. If the hash was previously cached, return it
private
getSigningKey(string $shortDate, string $region, string $service, string $secretKey) : string
Parameters
- $shortDate : string
-
Short date
- $region : string
-
Region name
- $service : string
-
Service name
- $secretKey : string
-
Secret Access Key
Return values
stringmoveHeadersToQuery()
private
moveHeadersToQuery(RequestInterface $request) : mixed
Parameters
- $request : RequestInterface