Sample code for 30+ languages & platforms
Lianja

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 Lianja Downloads

Lianja
llSuccess = .F.

loRest = createobject("CkRest")
llBTls = .T.
llBAutoReconnect = .T.
llSuccess = loRest.Connect("example.com",443,llBTls,llBAutoReconnect)
if (llSuccess = .F.) then
    ? loRest.LastErrorText
    release loRest
    return
endif

//  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.
loSsUsername = createobject("CkSecureString")
loSsUsername.Append("myUsername")
loSsPassword = createobject("CkSecureString")
loSsPassword.Append("myPassword")

llSuccess = loRest.SetAuthBasicSecure(loSsUsername,loSsPassword)
if (llSuccess = .F.) then
    ? loRest.LastErrorText
    release loRest
    release loSsUsername
    release loSsPassword
    return
endif

lcResponseText = loRest.FullRequestNoBody("GET","/api/protected")
if (loRest.LastMethodSuccess = .F.) then
    ? loRest.LastErrorText
    release loRest
    release loSsUsername
    release loSsPassword
    return
endif

? lcResponseText


release loRest
release loSsUsername
release loSsPassword