Tcl
Tcl
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 Tcl Downloads
load ./chilkat.dll
set success 0
set rest [new_CkRest]
set bTls 1
set bAutoReconnect 1
set success [CkRest_Connect $rest "example.com" 443 $bTls $bAutoReconnect]
if {$success == 0} then {
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
exit
}
# 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.
set ssUsername [new_CkSecureString]
CkSecureString_Append $ssUsername "myUsername"
set ssPassword [new_CkSecureString]
CkSecureString_Append $ssPassword "myPassword"
set success [CkRest_SetAuthBasicSecure $rest $ssUsername $ssPassword]
if {$success == 0} then {
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
delete_CkSecureString $ssUsername
delete_CkSecureString $ssPassword
exit
}
set responseText [CkRest_fullRequestNoBody $rest "GET" "/api/protected"]
if {[CkRest_get_LastMethodSuccess $rest] == 0} then {
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
delete_CkSecureString $ssUsername
delete_CkSecureString $ssPassword
exit
}
puts "$responseText"
delete_CkRest $rest
delete_CkSecureString $ssUsername
delete_CkSecureString $ssPassword