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

Windows Credentials Manager / Apple Keychain - Get a JSON Secret

See more Secrets Examples

On Windows, fetches the content of a JSON 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")

-- Get the secret.
local jsonSecret = chilkat.JsonObject.new()
local success = secrets:get_secret_json(json, jsonSecret)
if not success then
    print(secrets.last_error_text)
    return
end

jsonSecret.emit_compact = false
print(jsonSecret:emit())
print("Success.")