Skip to main content

Access Key

Access key authentication is the default when you connect using a storage account connection string.

Option 1: Connection String (Recommended)

<?php

use AzureOss\\Storage\\Queue\\QueueServiceClient;

$service = QueueServiceClient::fromConnectionString(
getenv('AZURE_STORAGE_CONNECTION_STRING')
);

For local development with Azurite, you can use:

AZURE_STORAGE_CONNECTION_STRING="UseDevelopmentStorage=true"

UseDevelopmentStorage=true tells the SDK to connect to the local Azurite emulator instead of Azure Storage.

Option 2: Explicit Endpoint + Shared Key

<?php

use AzureOss\\Storage\\Queue\\QueueServiceClient;
use AzureOss\Storage\Common\Auth\StorageSharedKeyCredential;
use GuzzleHttp\Psr7\Uri;

$credential = new StorageSharedKeyCredential(
getenv('AZURE_STORAGE_ACCOUNT_NAME'),
getenv('AZURE_STORAGE_ACCOUNT_KEY')
);

$endpoint = new Uri('https://'.getenv('AZURE_STORAGE_ACCOUNT_NAME').'.queue.core.windows.net/');
$service = new QueueServiceClient($endpoint, $credential);