Sample code for 30+ languages & platforms
Lua Requires Chilkat v10.1.0+

Windows Credentials Manager / Apple Keychain - Get a String Secret to a StringBuilder

See more Secrets Examples

On Windows, fetches the content of a text secret from the Windows Credentials Manager.

On MacOS or iOS, fetches from the Apple Keychain.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.

local secrets = chilkat.Secrets.new()

-- On Windows, this is the Windows Credentials Manager
-- On MacOS/iOS, it is the Apple Keychain
secrets.location = "local_manager"

-- Specify the secret to be fetched.
local json = chilkat.JsonObject.new()
json:update_string("appName", "MyApp")
json:update_string("service", "OAuth2")
json:update_string("domain", "onedrive")
json:update_string("username", "matt")

-- Append the content of the secret to a Chilkat StringBuilder object.
local sb = chilkat.StringBuilder.new()
local success = secrets:get_secret_sb(json, sb)
if not success then
    print(secrets.last_error_text)
    return
end

print(sb:get_as_string())
print("Success.")