Delphi DLL
Delphi DLL
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 DLL Downloads
var
success: Boolean;
rest: HCkRest;
bTls: Boolean;
bAutoReconnect: Boolean;
ssUsername: HCkSecureString;
ssPassword: HCkSecureString;
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;
// 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 := CkSecureString_Create();
CkSecureString_Append(ssUsername,'myUsername');
ssPassword := CkSecureString_Create();
CkSecureString_Append(ssPassword,'myPassword');
success := CkRest_SetAuthBasicSecure(rest,ssUsername,ssPassword);
if (success = False) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
responseText := CkRest__fullRequestNoBody(rest,'GET','/api/protected');
if (CkRest_getLastMethodSuccess(rest) = False) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
Memo1.Lines.Add(responseText);
CkRest_Dispose(rest);
CkSecureString_Dispose(ssUsername);
CkSecureString_Dispose(ssPassword);