Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

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 Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Rest,
  Chilkat.AuthAzureStorage;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  rest: TRest;
  bTls: Boolean;
  bAutoReconnect: Boolean;
  azAuth: TAuthAzureStorage;
  responseText: string;

begin
  success := False;

  rest := TRest.Create;
  bTls := True;
  bAutoReconnect := True;
  success := rest.Connect('example.com',443,bTls,bAutoReconnect);
  if (success = False) then
    begin
      WriteLn(rest.LastErrorText);
      Exit;
    end;

  //  Configure Azure Storage Shared Key authentication.  Provide the account name, base64 account
  //  access key, service, and (optionally) the x-ms-version.
  azAuth := TAuthAzureStorage.Create;
  azAuth.Account := '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.
  azAuth.AccessKey := 'BASE64_ACCOUNT_ACCESS_KEY';
  azAuth.Scheme := 'SharedKey';
  azAuth.Service := 'Blob';
  azAuth.XMsVersion := '2021-08-06';

  //  Associate the provider so Chilkat automatically adds the Shared Key Authorization header.
  success := rest.SetAuthAzureStorage(azAuth);
  if (success = False) then
    begin
      WriteLn(rest.LastErrorText);
      Exit;
    end;

  responseText := rest.FullRequestNoBody('GET','/mycontainer?restype=container&comp=list');
  if (rest.LastMethodSuccess = False) then
    begin
      WriteLn(rest.LastErrorText);
      Exit;
    end;
  WriteLn(responseText);


  rest.Free;
  azAuth.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.