Reputation: 866
I am using a CloudTableClient to access Table storage:
private StorageCredentials credentials;
public StorageCredentials StorageAccount
{
get
{
if (credentials == null)
{
credentials = new StorageCredentials(config["AzureStorageSettings:AccountName"],
config["AzureStorageSettings:AccountKey"]);
}
return credentials;
}
}
public CloudTableClient Tableclient
{
get
{
var storageAccount = new CloudStorageAccount(StorageAccount, true);
return storageAccount.CreateCloudTableClient();
}
}
public string TableReference => config["CampaignStorageName"];
with the settings:
"AzureStorageSettings:AccountName": "devstoreaccount1",
"AzureStorageSettings:AccountKey": "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==",
but every time I try to retrieve a record from the table
public IngestionEntity GetIngestionRecord(IngestionMessage msg)
{
var table = Tableclient.GetTableReference(TableReference);
var retrieve = TableOperation.Retrieve<IngestionEntity>(msg.PartitionKey, msg.RowKey);
var result = table.Execute(retrieve);
log.LogInformation($"{msg.ToString()}, " +
$"Query Status Code: {result.HttpStatusCode}, " +
$"Cost: {result.RequestCharge}");
return (IngestionEntity)result.Result;
}
I get the following error:
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
I am assuming this is related to https v http which dev storage uses but is there a way to allow this to authenticate so that I can use the TableClient as above or should I be doing this differently?
Upvotes: 1
Views: 113
Reputation: 136366
Please try the following code:
private CloudStorageAccount storageAccount;
public CloudStorageAccount StorageAccount
{
get
{
if (storageAccount == null)
{
storageAccount = config["AzureStorageSettings:AccountName"] == "devstoreaccount1" ? CloudStorageAccount.DevelopmentStorageAccount : new CloudStorageAccount(new StorageCredentials(config["AzureStorageSettings:AccountName"], config["AzureStorageSettings:AccountKey"]), true);
}
return storageAccount;
}
}
public CloudTableClient Tableclient
{
get
{
return StorageAccount.CreateCloudTableClient();
}
}
Basically Storage Emulator has different endpoints than your regular Storage Accounts and when you create an instance of CloudStorageAccount
using Storage Emulator credentials, the SDK thinks that you're trying to connect to an account named devstoreaccount1
in the cloud. Because the key for devstoreaccount1
is not the same as the key for Storage Emulator account, you're getting 403 error.
Upvotes: 2