|
75 | 75 | use MicrosoftAzure\Storage\Blob\Models\SetBlobTierOptions;
|
76 | 76 | use MicrosoftAzure\Storage\Common\Internal\Authentication\SharedAccessSignatureAuthScheme;
|
77 | 77 | use MicrosoftAzure\Storage\Common\Internal\Authentication\SharedKeyAuthScheme;
|
| 78 | +use MicrosoftAzure\Storage\Common\Internal\Authentication\TokenAuthScheme; |
78 | 79 | use MicrosoftAzure\Storage\Common\Internal\Http\HttpFormatter;
|
79 | 80 | use MicrosoftAzure\Storage\Common\Internal\Middlewares\CommonRequestMiddleware;
|
80 | 81 | use MicrosoftAzure\Storage\Common\Internal\Serialization\XmlSerializer;
|
@@ -171,6 +172,66 @@ public static function createBlobService(
|
171 | 172 | return $blobWrapper;
|
172 | 173 | }
|
173 | 174 |
|
| 175 | + /** |
| 176 | + * Builds a blob service object, it accepts the following |
| 177 | + * options: |
| 178 | + * |
| 179 | + * - http: (array) the underlying guzzle options. refer to |
| 180 | + * http://docs.guzzlephp.org/en/latest/request-options.html for detailed available options |
| 181 | + * - middlewares: (mixed) the middleware should be either an instance of a sub-class that |
| 182 | + * implements {@see MicrosoftAzure\Storage\Common\Middlewares\IMiddleware}, or a |
| 183 | + * `callable` that follows the Guzzle middleware implementation convention |
| 184 | + * |
| 185 | + * Please refer to |
| 186 | + * https://docs.microsoft.com/en-us/azure/storage/common/storage-auth-aad |
| 187 | + * for authenticate access to Azure blobs and queues using Azure Active Directory. |
| 188 | + * |
| 189 | + * @param string $token The bearer token passed as reference. |
| 190 | + * @param string $connectionString The configuration connection string. |
| 191 | + * @param array $options Array of options to pass to the service |
| 192 | + * |
| 193 | + * @return BlobRestProxy |
| 194 | + */ |
| 195 | + public static function createBlobServiceWithTokenCredential( |
| 196 | + &$token, |
| 197 | + $connectionString, |
| 198 | + array $options = [] |
| 199 | + ) { |
| 200 | + $settings = StorageServiceSettings::createFromConnectionStringForTokenCredential( |
| 201 | + $connectionString |
| 202 | + ); |
| 203 | + |
| 204 | + $primaryUri = Utilities::tryAddUrlScheme( |
| 205 | + $settings->getBlobEndpointUri() |
| 206 | + ); |
| 207 | + |
| 208 | + $secondaryUri = Utilities::tryAddUrlScheme( |
| 209 | + $settings->getBlobSecondaryEndpointUri() |
| 210 | + ); |
| 211 | + |
| 212 | + $blobWrapper = new BlobRestProxy( |
| 213 | + $primaryUri, |
| 214 | + $secondaryUri, |
| 215 | + $settings->getName(), |
| 216 | + $options |
| 217 | + ); |
| 218 | + |
| 219 | + // Getting authentication scheme |
| 220 | + $authScheme = new TokenAuthScheme( |
| 221 | + $token |
| 222 | + ); |
| 223 | + |
| 224 | + // Adding common request middleware |
| 225 | + $commonRequestMiddleware = new CommonRequestMiddleware( |
| 226 | + $authScheme, |
| 227 | + Resources::STORAGE_API_LATEST_VERSION, |
| 228 | + Resources::BLOB_SDK_VERSION |
| 229 | + ); |
| 230 | + $blobWrapper->pushMiddleware($commonRequestMiddleware); |
| 231 | + |
| 232 | + return $blobWrapper; |
| 233 | + } |
| 234 | + |
174 | 235 | /**
|
175 | 236 | * Builds an anonymous access object with given primary service
|
176 | 237 | * endpoint. The service endpoint should contain a scheme and a
|
|
0 commit comments