JavaScript
JavaScript
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.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat
v11.4.0 or greater.
var success = false;
var rest = new CkRest();
var bTls = true;
var bAutoReconnect = true;
success = rest.Connect("example.com",443,bTls,bAutoReconnect);
if (success == false) {
console.log(rest.LastErrorText);
return;
}
// 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.
var ssUsername = new CkSecureString();
ssUsername.Append("myUsername");
var ssPassword = new CkSecureString();
ssPassword.Append("myPassword");
success = rest.SetAuthBasicSecure(ssUsername,ssPassword);
if (success == false) {
console.log(rest.LastErrorText);
return;
}
var responseText = rest.FullRequestNoBody("GET","/api/protected");
if (rest.LastMethodSuccess == false) {
console.log(rest.LastErrorText);
return;
}
console.log(responseText);