PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Rest
integer li_BTls
integer li_BAutoReconnect
oleobject loo_SsUsername
oleobject loo_SsPassword
string ls_ResponseText
li_Success = 0
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")
if li_rc < 0 then
destroy loo_Rest
MessageBox("Error","Connecting to COM object failed")
return
end if
li_BTls = 1
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("example.com",443,li_BTls,li_BAutoReconnect)
if li_Success = 0 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
return
end if
// 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.
loo_SsUsername = create oleobject
li_rc = loo_SsUsername.ConnectToNewObject("Chilkat.SecureString")
loo_SsUsername.Append("myUsername")
loo_SsPassword = create oleobject
li_rc = loo_SsPassword.ConnectToNewObject("Chilkat.SecureString")
loo_SsPassword.Append("myPassword")
li_Success = loo_Rest.SetAuthBasicSecure(loo_SsUsername,loo_SsPassword)
if li_Success = 0 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
destroy loo_SsUsername
destroy loo_SsPassword
return
end if
ls_ResponseText = loo_Rest.FullRequestNoBody("GET","/api/protected")
if loo_Rest.LastMethodSuccess = 0 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
destroy loo_SsUsername
destroy loo_SsPassword
return
end if
Write-Debug ls_ResponseText
destroy loo_Rest
destroy loo_SsUsername
destroy loo_SsPassword