Delphi ActiveX
Delphi ActiveX
Configure HTTP Basic Authentication with SecureString
See more REST Examples
Demonstrates Rest.SetAuthBasicSecure, which configures HTTP Basic authentication using SecureString objects instead of plaintext strings.
Background. A SecureString keeps sensitive values encrypted in memory, reducing the window in which credentials appear as readable plaintext. This is otherwise equivalent to SetAuthBasic.
Chilkat Delphi ActiveX Downloads
var
success: Integer;
rest: TChilkatRest;
bTls: Integer;
bAutoReconnect: Integer;
ssUsername: TChilkatSecureString;
ssPassword: TChilkatSecureString;
responseText: WideString;
begin
success := 0;
rest := TChilkatRest.Create(Self);
bTls := 1;
bAutoReconnect := 1;
success := rest.Connect('example.com',443,bTls,bAutoReconnect);
if (success = 0) then
begin
Memo1.Lines.Add(rest.LastErrorText);
Exit;
end;
// SetAuthBasicSecure configures HTTP Basic authentication using SecureString objects, which keep
// the credentials encrypted in memory.
// Normally you would not hard-code secrets in source. You should instead obtain them from an
// interactive prompt, environment variable, or a secrets vault.
ssUsername := TChilkatSecureString.Create(Self);
ssUsername.Append('myUsername');
ssPassword := TChilkatSecureString.Create(Self);
ssPassword.Append('myPassword');
success := rest.SetAuthBasicSecure(ssUsername.ControlInterface,ssPassword.ControlInterface);
if (success = 0) then
begin
Memo1.Lines.Add(rest.LastErrorText);
Exit;
end;
responseText := rest.FullRequestNoBody('GET','/api/protected');
if (rest.LastMethodSuccess = 0) then
begin
Memo1.Lines.Add(rest.LastErrorText);
Exit;
end;
Memo1.Lines.Add(responseText);