Azure Table: Create a Read-Only Table Service SAS
See more Azure Table Service Examples
Generates a short-lived HTTPS-only account-key service SAS for ExampleCustomers, restricted to one partition and the inclusive lexical row range customer-001 through customer-099. Includes Table-specific spk/srk/epk/erk fields, lowercase canonical table name and tn. It grants entity reads, not table creation/deletion or policy administration. Respect stricter account SAS-expiration policies.
Writes a token without a leading question mark to private table-sas.txt, replacing a prior token. Anyone holding it can exercise its permissions until expiry; do not log it. This is an account-key Table service SAS, not a Blob user-delegation SAS.
Targets Azure Storage Table service in the public cloud, not Azure Cosmos DB for Table. Uses Chilkat 11.6.0 or later and an unlocked library. Direct data requests pin x-ms-version 2026-04-06 and OData 3.0. Shared Key examples read private qa_data/azure/storage.json with account and access_key string fields. Authentication examples explain their additional fields. Create private local directories before running; keep credentials, tokens, SAS, entity values, checkpoints and diagnostics outside public content and source control.
HTTPS certificates are verified. Transport completion and HTTP status are checked separately. Writes are not automatically retried after an uncertain outcome. Entity keys, ETags and continuation tokens remain strings. Examples operate on the existing ExampleCustomers table unless noted; review the targets before adapting them. Microsoft Entra ID with suitable Table data roles is preferred where available.
Chilkat Unicode C++ Downloads
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>
#include <CkAuthAzureSASW.h>
#include <CkDateTimeW.h>
#include <CkFileAccessW.h>
void ChilkatSample(void)
{
bool success = false;
// StringBuilder compares text by value in every generated language.
CkStringBuilderW textCompare;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success = false;
CkJsonObjectW config;
config.put_Strict(true);
success = config.LoadFile(L"qa_data/azure/storage.json");
if (success != true) {
wprintf(L"Could not load private Azure configuration.\n");
return;
}
textCompare.Clear();
textCompare.SetString(config.stringOf(L"account"));
bool sameText1 = textCompare.ContentsEqual(L"",true);
if ((config.JsonTypeOf(L"account") != 1) || (sameText1 == true)) {
wprintf(L"Supply the storage account name.\n");
return;
}
// access_key is the base64 account key, not a connection string or SAS.
textCompare.Clear();
textCompare.SetString(config.stringOf(L"access_key"));
bool sameText2 = textCompare.ContentsEqual(L"",true);
if ((config.JsonTypeOf(L"access_key") != 1) || (sameText2 == true)) {
wprintf(L"Supply the base64 account access key.\n");
return;
}
CkAuthAzureSASW sas;
sas.put_AccessKey(config.stringOf(L"access_key"));
sas.put_StringToSign(L"sp,st,se,resource,si,sip,spr,sv,spk,srk,epk,erk");
CkStringBuilderW canonical;
success = canonical.Append(L"/table/");
if (success != true) {
wprintf(L"Could not prepare the request.\n");
return;
}
success = canonical.Append(config.stringOf(L"account"));
if (success != true) {
wprintf(L"Could not prepare the request.\n");
return;
}
success = canonical.Append(L"/examplecustomers");
if (success != true) {
wprintf(L"Could not prepare the request.\n");
return;
}
success = sas.SetNonTokenParam(L"resource",canonical.getAsString());
if (success != true) {
wprintf(L"Could not prepare the request.\n");
return;
}
// Canonicalized table name must be lowercase. tn belongs in the token, not StringToSign.
CkDateTimeW start;
CkDateTimeW expiry;
success = start.SetFromCurrentSystemTime();
if (success != true) {
wprintf(L"Could not prepare the request.\n");
return;
}
success = expiry.SetFromCurrentSystemTime();
if (success != true) {
wprintf(L"Could not prepare the request.\n");
return;
}
success = start.AddSeconds(-300);
if (success != true) {
wprintf(L"Could not prepare the request.\n");
return;
}
success = expiry.AddSeconds(900);
if (success != true) {
wprintf(L"Could not prepare the request.\n");
return;
}
success = sas.SetTokenParam(L"tn",L"tn",L"examplecustomers");
if (success != true) {
wprintf(L"Could not prepare the request.\n");
return;
}
success = sas.SetTokenParam(L"sp",L"sp",L"r");
if (success != true) {
wprintf(L"Could not prepare the request.\n");
return;
}
success = sas.SetTokenParam(L"st",L"st",start.getAsTimestamp(false));
if (success != true) {
wprintf(L"Could not prepare the request.\n");
return;
}
success = sas.SetTokenParam(L"se",L"se",expiry.getAsTimestamp(false));
if (success != true) {
wprintf(L"Could not prepare the request.\n");
return;
}
success = sas.SetTokenParam(L"spr",L"spr",L"https");
if (success != true) {
wprintf(L"Could not prepare the request.\n");
return;
}
success = sas.SetTokenParam(L"sv",L"sv",L"2026-04-06");
if (success != true) {
wprintf(L"Could not prepare the request.\n");
return;
}
success = sas.SetTokenParam(L"spk",L"spk",L"customers-west");
if (success != true) {
wprintf(L"Could not prepare the request.\n");
return;
}
success = sas.SetTokenParam(L"epk",L"epk",L"customers-west");
if (success != true) {
wprintf(L"Could not prepare the request.\n");
return;
}
success = sas.SetTokenParam(L"srk",L"srk",L"customer-001");
if (success != true) {
wprintf(L"Could not prepare the request.\n");
return;
}
success = sas.SetTokenParam(L"erk",L"erk",L"customer-099");
if (success != true) {
wprintf(L"Could not prepare the request.\n");
return;
}
const wchar_t *sasToken = sas.generateToken();
if (sas.get_LastMethodSuccess() != true) {
wprintf(L"Could not sign the SAS.\n");
return;
}
CkFileAccessW files;
success = files.WriteEntireTextFile(L"qa_data/azure/table-sas.txt",sasToken,L"utf-8",false);
if (success != true) {
wprintf(L"Could not save private SAS token.\n");
return;
}
wprintf(L"Read-only Table SAS saved privately; expires in about 15 minutes.\n");
}