|
26 | 26 |
|
27 | 27 | use MicrosoftAzure\Storage\Common\Internal\Authentication\SharedAccessSignatureAuthScheme; |
28 | 28 | use MicrosoftAzure\Storage\Common\Internal\Authentication\SharedKeyAuthScheme; |
| 29 | +use MicrosoftAzure\Storage\Common\Internal\Authentication\TokenAuthScheme; |
29 | 30 | use MicrosoftAzure\Storage\Common\Internal\Http\HttpFormatter; |
30 | 31 | use MicrosoftAzure\Storage\Common\Internal\Middlewares\CommonRequestMiddleware; |
31 | 32 | use MicrosoftAzure\Storage\Common\Internal\Serialization\XmlSerializer; |
@@ -132,6 +133,66 @@ public static function createQueueService( |
132 | 133 | return $queueWrapper; |
133 | 134 | } |
134 | 135 |
|
| 136 | + /** |
| 137 | + * Builds a queue service object, it accepts the following |
| 138 | + * options: |
| 139 | + * |
| 140 | + * - http: (array) the underlying guzzle options. refer to |
| 141 | + * http://docs.guzzlephp.org/en/latest/request-options.html for detailed available options |
| 142 | + * - middlewares: (mixed) the middleware should be either an instance of a sub-class that |
| 143 | + * implements {@see MicrosoftAzure\Storage\Common\Middlewares\IMiddleware}, or a |
| 144 | + * `callable` that follows the Guzzle middleware implementation convention |
| 145 | + * |
| 146 | + * Please refer to |
| 147 | + * https://docs.microsoft.com/en-us/azure/storage/common/storage-auth-aad |
| 148 | + * for authenticate access to Azure blobs and queues using Azure Active Directory. |
| 149 | + * |
| 150 | + * @param string $token The bearer token passed as reference. |
| 151 | + * @param string $connectionString The configuration connection string. |
| 152 | + * @param array $options Array of options to pass to the service |
| 153 | + * |
| 154 | + * @return QueueRestProxy |
| 155 | + */ |
| 156 | + public static function createQueueServiceWithTokenCredential( |
| 157 | + &$token, |
| 158 | + $connectionString, |
| 159 | + array $options = [] |
| 160 | + ) { |
| 161 | + $settings = StorageServiceSettings::createFromConnectionStringForTokenCredential( |
| 162 | + $connectionString |
| 163 | + ); |
| 164 | + |
| 165 | + $primaryUri = Utilities::tryAddUrlScheme( |
| 166 | + $settings->getQueueEndpointUri() |
| 167 | + ); |
| 168 | + |
| 169 | + $secondaryUri = Utilities::tryAddUrlScheme( |
| 170 | + $settings->getQueueSecondaryEndpointUri() |
| 171 | + ); |
| 172 | + |
| 173 | + $queueWrapper = new QueueRestProxy( |
| 174 | + $primaryUri, |
| 175 | + $secondaryUri, |
| 176 | + $settings->getName(), |
| 177 | + $options |
| 178 | + ); |
| 179 | + |
| 180 | + // Getting authentication scheme |
| 181 | + $authScheme = new TokenAuthScheme( |
| 182 | + $token |
| 183 | + ); |
| 184 | + |
| 185 | + // Adding common request middleware |
| 186 | + $commonRequestMiddleware = new CommonRequestMiddleware( |
| 187 | + $authScheme, |
| 188 | + Resources::STORAGE_API_LATEST_VERSION, |
| 189 | + Resources::QUEUE_SDK_VERSION |
| 190 | + ); |
| 191 | + $queueWrapper->pushMiddleware($commonRequestMiddleware); |
| 192 | + |
| 193 | + return $queueWrapper; |
| 194 | + } |
| 195 | + |
135 | 196 | /** |
136 | 197 | * Lists all queues in the storage account. |
137 | 198 | * |
|
0 commit comments