/** * Test sign request URL */ public function testSignRequestUrl() { $credentials = new Zend_Service_WindowsAzure_Credentials_SharedAccessSignature('myaccount', '', false); $queryString = $credentials->createSignedQueryString('pictures/blob.txt', '', 'b', 'r', '2009-02-09', '2009-02-10'); $credentials->setPermissionSet(array('http://blob.core.windows.net/myaccount/pictures/blob.txt?' . $queryString)); $requestUrl = 'http://blob.core.windows.net/myaccount/pictures/blob.txt?comp=metadata'; $result = $credentials->signRequestUrl($requestUrl, Zend_Service_WindowsAzure_Storage::RESOURCE_BLOB); $this->assertEquals('http://blob.core.windows.net/myaccount/pictures/blob.txt?comp=metadata&' . $queryString, $result); }
/** * Generate shared access URL * * @param string $containerName Container name * @param string $blobName Blob name * @param string $resource Signed resource - container (c) - blob (b) * @param string $permissions Signed permissions - read (r), write (w), delete (d) and list (l) * @param string $start The time at which the Shared Access Signature becomes valid. * @param string $expiry The time at which the Shared Access Signature becomes invalid. * @param string $identifier Signed identifier * @return string */ public function generateSharedAccessUrl($containerName = '', $blobName = '', $resource = 'b', $permissions = 'r', $start = '', $expiry = '', $identifier = '') { if ($containerName === '') { throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.'); } if (!self::isValidContainerName($containerName)) { throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.'); } // Resource name $resourceName = self::createResourceName($containerName, $blobName); // Generate URL return $this->getBaseUrl() . '/' . $resourceName . '?' . $this->_sharedAccessSignatureCredentials->createSignedQueryString($resourceName, '', $resource, $permissions, $start, $expiry, $identifier); }