C
C
Configure Azure Storage Shared Key Authentication
See more REST Examples
Demonstrates Rest.SetAuthAzureStorage, which associates an AuthAzureStorage provider so Chilkat automatically adds a Shared Key Authorization header. The provider supplies the account name, base64 account key, service, and scheme.
Background. Azure Storage Shared Key authorization signs each request with the account access key. The provider also manages the
x-ms-version header required by the storage REST API.Chilkat C Downloads
#include <C_CkRest.h>
#include <C_CkAuthAzureStorage.h>
void ChilkatSample(void)
{
BOOL success;
HCkRest rest;
BOOL bTls;
BOOL bAutoReconnect;
HCkAuthAzureStorage azAuth;
const char *responseText;
success = FALSE;
rest = CkRest_Create();
bTls = TRUE;
bAutoReconnect = TRUE;
success = CkRest_Connect(rest,"example.com",443,bTls,bAutoReconnect);
if (success == FALSE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
return;
}
// Configure Azure Storage Shared Key authentication. Provide the account name, base64 account
// access key, service, and (optionally) the x-ms-version.
azAuth = CkAuthAzureStorage_Create();
CkAuthAzureStorage_putAccount(azAuth,"myStorageAccount");
// Normally you would not hard-code secrets in source. You should instead obtain them from an
// interactive prompt, environment variable, or a secrets vault.
CkAuthAzureStorage_putAccessKey(azAuth,"BASE64_ACCOUNT_ACCESS_KEY");
CkAuthAzureStorage_putScheme(azAuth,"SharedKey");
CkAuthAzureStorage_putService(azAuth,"Blob");
CkAuthAzureStorage_putXMsVersion(azAuth,"2021-08-06");
// Associate the provider so Chilkat automatically adds the Shared Key Authorization header.
success = CkRest_SetAuthAzureStorage(rest,azAuth);
if (success == FALSE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
CkAuthAzureStorage_Dispose(azAuth);
return;
}
responseText = CkRest_fullRequestNoBody(rest,"GET","/mycontainer?restype=container&comp=list");
if (CkRest_getLastMethodSuccess(rest) == FALSE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
CkAuthAzureStorage_Dispose(azAuth);
return;
}
printf("%s\n",responseText);
CkRest_Dispose(rest);
CkAuthAzureStorage_Dispose(azAuth);
}