Delphi DLL
Delphi DLL
Configure AWS Signature Authentication for REST
See more REST Examples
Demonstrates Rest.SetAuthAws, which associates an AuthAws provider so Chilkat signs each request using AWS Signature Version 4. The provider supplies the access key, secret key, region, and service name.
Background. AWS requires each request to be signed with a signature derived from the secret key, region, service, and request contents. Configuring the provider lets Chilkat compute and attach the signature automatically.
Chilkat Delphi DLL Downloads
var
success: Boolean;
rest: HCkRest;
bTls: Boolean;
bAutoReconnect: Boolean;
authAws: HCkAuthAws;
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 AWS Signature Version 4 request signing. Provide the access key, secret key, region,
// and service name.
authAws := CkAuthAws_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.
CkAuthAws_putAccessKey(authAws,'AWS_ACCESS_KEY');
CkAuthAws_putSecretKey(authAws,'AWS_SECRET_KEY');
CkAuthAws_putRegion(authAws,'us-east-1');
CkAuthAws_putServiceName(authAws,'s3');
// Associate the provider so Chilkat signs each request according to AWS requirements.
success := CkRest_SetAuthAws(rest,authAws);
if (success = False) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
responseText := CkRest__fullRequestNoBody(rest,'GET','/');
if (CkRest_getLastMethodSuccess(rest) = False) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
Memo1.Lines.Add(responseText);
CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);