Storage/src/SigningHelper.php
public function v2Sign(ConnectionInterface $connection, $expires, $resource, $generation, array $options)
    {
        list($credentials, $options) = $this->getSigningCredentials($connection, $options);

        $expires = $this->normalizeExpiration($expires);
        $resource = $this->normalizeResource($resource);
        $options = $this->normalizeOptions($options);
        $headers = $this->normalizeHeaders($options['headers']);

        // Make sure disallowed headers are not included.
        $illegalHeaders = [
            'x-goog-encryption-key',
            'x-goog-encryption-key-sha256'
        ];
        if ($illegal = array_intersect_key(array_flip($illegalHeaders), $headers)) {
            throw new \InvalidArgumentException(sprintf(
                '%s %s not allowed in Signed URL headers.',
                implode(' and ', array_keys($illegal)),
                count($illegal) === 1 ? 'is' : 'are'
            ));
        }

        // Sort headers by name.
        ksort($headers);

        $toSign = [
            $options['method'],
            $options['contentMd5'],
            $options['contentType'],
            $expires,
        ];

        $signedHeaders = [];
        foreach ($headers as $name => $value) {
            $signedHeaders[] = $name .':'. $value;
        }

        // Push the headers onto the end of the signing string.
        if ($signedHeaders) {
            $toSign = array_merge($toSign, $signedHeaders);
        }

        $toSign[] = $resource;

        $stringToSign = $this->createV2CanonicalRequest($toSign);

        $signature = $credentials->signBlob($stringToSign, [
            'forceOpenssl' => $options['forceOpenssl']
        ]);

        // Start with user-provided query params and add required parameters.
        $params = $options['queryParams'];
        $params['GoogleAccessId'] = $credentials->getClientName();
        $params['Expires'] = $expires;
        $params['Signature'] = $signature;

        $params = $this->addCommonParams($generation, $params, $options);

        $queryString = $this->buildQueryString($params);

        $resource = $this->normalizeUriPath($options['cname'], $resource);
        return 'https://' . $options['cname'] . $resource . '?' . $queryString;
    }
public function v2Sign(ConnectionInterface $connection, $expires, $resource, $generation, array $options)
    {
        list($credentials, $options) = $this->getSigningCredentials($connection, $options);

        $expires = $this->normalizeExpiration($expires);
        $resource = $this->normalizeResource($resource);
        $options = $this->normalizeOptions($options);
        $headers = $this->normalizeHeaders($options['headers']);

        // Make sure disallowed headers are not included.
        $illegalHeaders = [
            'x-goog-encryption-key',
            'x-goog-encryption-key-sha256'
        ];
        if ($illegal = array_intersect_key(array_flip($illegalHeaders), $headers)) {
            throw new \InvalidArgumentException(sprintf(
                '%s %s not allowed in Signed URL headers.',
                implode(' and ', array_keys($illegal)),
                count($illegal) === 1 ? 'is' : 'are'
            ));
        }

        // Sort headers by name.
        ksort($headers);

        $toSign = [
            $options['method'],
            $options['contentMd5'],
            $options['contentType'],
            $expires,
        ];

        $signedHeaders = [];
        foreach ($headers as $name => $value) {
            $signedHeaders[] = $name .':'. $value;
        }

        // Push the headers onto the end of the signing string.
        if ($signedHeaders) {
            $toSign = array_merge($toSign, $signedHeaders);
        }

        $toSign[] = $resource;

        $stringToSign = $this->createV2CanonicalRequest($toSign);

        $signature = $credentials->signBlob($stringToSign, [
            'forceOpenssl' => $options['forceOpenssl']
        ]);

        // Start with user-provided query params and add required parameters.
        $params = $options['queryParams'];
        $params['GoogleAccessId'] = $credentials->getClientName();
        $params['Expires'] = $expires;
        $params['Signature'] = $signature;

        $params = $this->addCommonParams($generation, $params, $options);

        $queryString = $this->buildQueryString($params);

        $resource = $this->normalizeUriPath($options['cname'], $resource);
        return 'https://' . $options['cname'] . $resource . '?' . $queryString;
    }
public function v2Sign ( ConnectionInterface $ connection , $ expires , $ resource , $ generation , array $ options ) { list ( $ credentials , $ options ) = $ this -> getSigningCredentials ( $ connection , $ options ) ; $ expires = $ this -> normalizeExpiration ( $ expires ) ; $ resource = $ this -> normalizeResource ( $ resource ) ; $ options = $ this -> normalizeOptions ( $ options ) ; $ headers = $ this -> normalizeHeaders ( $ options [ 'headers' ] ) ; // Make sure disallowed headers are not included. $ illegalHeaders = [ 'x-goog-encryption-key' , 'x-goog-encryption-key-sha256' ] ; if ( $ illegal = array_intersect_key ( array_flip ( $ illegalHeaders ) , $ headers ) ) { throw new \ InvalidArgumentException ( sprintf ( '%s %s not allowed in Signed URL headers.' , implode ( ' and ' , array_keys ( $ illegal ) ) , count ( $ illegal ) === 1 ? 'is' : 'are' ) ) ; } // Sort headers by name. ksort ( $ headers ) ; $ toSign = [ $ options [ 'method' ] , $ options [ 'contentMd5' ] , $ options [ 'contentType' ] , $ expires , ] ; $ signedHeaders = [ ] ; foreach ( $ headers as $ name => $ value ) { $ signedHeaders [ ] = $ name . ':' . $ value ; } // Push the headers onto the end of the signing string. if ( $ signedHeaders ) { $ toSign = array_merge ( $ toSign , $ signedHeaders ) ; } $ toSign [ ] = $ resource ; $ stringToSign = $ this -> createV2CanonicalRequest ( $ toSign ) ; $ signature = $ credentials -> signBlob ( $ stringToSign , [ 'forceOpenssl' => $ options [ 'forceOpenssl' ] ] ) ; // Start with user-provided query params and add required parameters. $ params = $ options [ 'queryParams' ] ; $ params [ 'GoogleAccessId' ] = $ credentials -> getClientName ( ) ; $ params [ 'Expires' ] = $ expires ; $ params [ 'Signature' ] = $ signature ; $ params = $ this -> addCommonParams ( $ generation , $ params , $ options ) ; $ queryString = $ this -> buildQueryString ( $ params ) ; $ resource = $ this -> normalizeUriPath ( $ options [ 'cname' ] , $ resource ) ; return 'https://' . $ options [ 'cname' ] . $ resource . '?' . $ queryString ; }
Sign a URL using Google Signed URLs v2.

This method will be deprecated in the future.

@param ConnectionInterface $connection A connection to the Cloud Storage
API.
@param Timestamp|\DateTimeInterface|int $expires The signed URL
expiration.
@param string $resource The URI to the storage resource, preceded by a
leading slash.
@param int|null $generation The resource generation.
@param array $options Configuration options. See
{@see Google\Cloud\Storage\StorageObject::signedUrl()} for
details.
@return string
@throws \InvalidArgumentException
@throws \RuntimeException If required data could not be gathered from
credentials.
@throws \RuntimeException If OpenSSL signing is required by user input
and OpenSSL is not available.
Sign a URL using Google Signed URLs v2 .