Unicode C++
Unicode C++
Configure Azure SAS Authentication for REST
See more REST Examples
Demonstrates Rest.SetAuthAzureSas, which associates an AuthAzureSAS provider so requests are authorized with an Azure Shared Access Signature token.
Background. A SAS token grants time-limited, permission-scoped access to Azure Storage resources without exposing the account key on the wire. Use SAS authorization when a query-token approach is preferred over Shared Key headers.
Chilkat Unicode C++ Downloads
#include <CkRestW.h>
#include <CkAuthAzureSASW.h>
void ChilkatSample(void)
{
bool success = false;
CkRestW rest;
bool bTls = true;
bool bAutoReconnect = true;
success = rest.Connect(L"example.com",443,bTls,bAutoReconnect);
if (success == false) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
// Configure Azure Shared Access Signature (SAS) authentication. Provide the account access key
// and the SAS token query parameters; Chilkat adds the SAS token to each request.
CkAuthAzureSASW azSas;
// Normally you would not hard-code secrets in source. You should instead obtain them from an
// interactive prompt, environment variable, or a secrets vault.
azSas.put_AccessKey(L"BASE64_ACCOUNT_ACCESS_KEY");
// Associate the provider with the REST object.
success = rest.SetAuthAzureSas(azSas);
if (success == false) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
const wchar_t *responseText = rest.fullRequestNoBody(L"GET",L"/mycontainer/myblob.txt");
if (rest.get_LastMethodSuccess() == false) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
wprintf(L"%s\n",responseText);
}