Delphi DLL
Delphi DLL
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 Delphi DLL Downloads
var
success: Boolean;
rest: HCkRest;
bTls: Boolean;
bAutoReconnect: Boolean;
azSas: HCkAuthAzureSAS;
responseText: PWideChar;
begin
success := False;
rest := CkRest_Create();
bTls := True;
bAutoReconnect := True;
success := CkRest_Connect(rest,'example.com',443,bTls,bAutoReconnect);
if (success = False) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
// 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.
azSas := CkAuthAzureSAS_Create();
// Normally you would not hard-code secrets in source. You should instead obtain them from an
// interactive prompt, environment variable, or a secrets vault.
CkAuthAzureSAS_putAccessKey(azSas,'BASE64_ACCOUNT_ACCESS_KEY');
// Associate the provider with the REST object.
success := CkRest_SetAuthAzureSas(rest,azSas);
if (success = False) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
responseText := CkRest__fullRequestNoBody(rest,'GET','/mycontainer/myblob.txt');
if (CkRest_getLastMethodSuccess(rest) = False) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
Memo1.Lines.Add(responseText);
CkRest_Dispose(rest);
CkAuthAzureSAS_Dispose(azSas);