From 8310c2ecab488fa325db3dcf2f8723bbcfe58941 Mon Sep 17 00:00:00 2001 From: "Vincent Jiang (LEI)" Date: Fri, 26 Apr 2019 23:06:52 +0800 Subject: [PATCH] source code copied from azure-storage-php for v1.4.0-blob release --- ChangeLog.md | 4 ++ README.md | 4 ++ composer.json | 4 +- src/Blob/BlobRestProxy.php | 61 +++++++++++++++++++++++++++++ src/Blob/Internal/BlobResources.php | 4 +- 5 files changed, 73 insertions(+), 4 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index ad63862..60d2918 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,7 @@ +2019.04 - version 1.4.0 +* Added support for OAuth authentication. +* Resolved some issues on Linux platform. + 2019.03 - version 1.3.0 * Fixed a bug where blob name '0' cannot be created. * Documentation refinement. diff --git a/README.md b/README.md index ee45167..949cc7f 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,10 @@ BlobEndpoint=[myBlobEndpoint];SharedAccessSignature=[sasToken] ```php $blobClient = BlobRestProxy::createBlobService($connectionString); ``` +Or for token authentication: +```php +$blobClient = BlobRestProxy::createBlobServiceWithTokenCredential($token, $connectionString); +``` ### Using Middlewares To specify the middlewares, user have to create an array with middlewares and put it in the `$requestOptions` with key 'middlewares'. The sequence of diff --git a/composer.json b/composer.json index 99267d2..a995e15 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "microsoft/azure-storage-blob", - "version": "1.3.0", + "version": "1.4.0", "description": "This project provides a set of PHP client libraries that make it easy to access Microsoft Azure Storage Blob APIs.", "keywords": [ "php", "azure", "storage", "sdk", "blob" ], "license": "MIT", @@ -12,7 +12,7 @@ ], "require": { "php": ">=5.6.0", - "microsoft/azure-storage-common": "~1.3.0" + "microsoft/azure-storage-common": "~1.4" }, "autoload": { "psr-4": { diff --git a/src/Blob/BlobRestProxy.php b/src/Blob/BlobRestProxy.php index 67104ef..2776f06 100644 --- a/src/Blob/BlobRestProxy.php +++ b/src/Blob/BlobRestProxy.php @@ -75,6 +75,7 @@ use MicrosoftAzure\Storage\Blob\Models\SetBlobTierOptions; use MicrosoftAzure\Storage\Common\Internal\Authentication\SharedAccessSignatureAuthScheme; use MicrosoftAzure\Storage\Common\Internal\Authentication\SharedKeyAuthScheme; +use MicrosoftAzure\Storage\Common\Internal\Authentication\TokenAuthScheme; use MicrosoftAzure\Storage\Common\Internal\Http\HttpFormatter; use MicrosoftAzure\Storage\Common\Internal\Middlewares\CommonRequestMiddleware; use MicrosoftAzure\Storage\Common\Internal\Serialization\XmlSerializer; @@ -171,6 +172,66 @@ public static function createBlobService( return $blobWrapper; } + /** + * Builds a blob service object, it accepts the following + * options: + * + * - http: (array) the underlying guzzle options. refer to + * http://docs.guzzlephp.org/en/latest/request-options.html for detailed available options + * - middlewares: (mixed) the middleware should be either an instance of a sub-class that + * implements {@see MicrosoftAzure\Storage\Common\Middlewares\IMiddleware}, or a + * `callable` that follows the Guzzle middleware implementation convention + * + * Please refer to + * https://docs.microsoft.com/en-us/azure/storage/common/storage-auth-aad + * for authenticate access to Azure blobs and queues using Azure Active Directory. + * + * @param string $token The bearer token passed as reference. + * @param string $connectionString The configuration connection string. + * @param array $options Array of options to pass to the service + * + * @return BlobRestProxy + */ + public static function createBlobServiceWithTokenCredential( + &$token, + $connectionString, + array $options = [] + ) { + $settings = StorageServiceSettings::createFromConnectionStringForTokenCredential( + $connectionString + ); + + $primaryUri = Utilities::tryAddUrlScheme( + $settings->getBlobEndpointUri() + ); + + $secondaryUri = Utilities::tryAddUrlScheme( + $settings->getBlobSecondaryEndpointUri() + ); + + $blobWrapper = new BlobRestProxy( + $primaryUri, + $secondaryUri, + $settings->getName(), + $options + ); + + // Getting authentication scheme + $authScheme = new TokenAuthScheme( + $token + ); + + // Adding common request middleware + $commonRequestMiddleware = new CommonRequestMiddleware( + $authScheme, + Resources::STORAGE_API_LATEST_VERSION, + Resources::BLOB_SDK_VERSION + ); + $blobWrapper->pushMiddleware($commonRequestMiddleware); + + return $blobWrapper; + } + /** * Builds an anonymous access object with given primary service * endpoint. The service endpoint should contain a scheme and a diff --git a/src/Blob/Internal/BlobResources.php b/src/Blob/Internal/BlobResources.php index 2851173..de5f323 100644 --- a/src/Blob/Internal/BlobResources.php +++ b/src/Blob/Internal/BlobResources.php @@ -41,8 +41,8 @@ class BlobResources extends Resources { // @codingStandardsIgnoreStart - const BLOB_SDK_VERSION = '1.3.0'; - const STORAGE_API_LATEST_VERSION = '2017-04-17'; + const BLOB_SDK_VERSION = '1.4.0'; + const STORAGE_API_LATEST_VERSION = '2017-11-09'; // Error messages const INVALID_BTE_MSG = "The blob block type must exist in %s";