Zig
Zig
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.
Note: This example requires Chilkat v10.1.0 or later.
Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const secrets = try chilkat.Secrets.init();
defer secrets.deinit();
// On Windows, this is the Windows Credentials Manager
// On MacOS/iOS, it is the Apple Keychain
secrets.setLocation("local_manager");
// Specify the secret to be fetched.
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateString("appName", "MyApp") catch {};
json.updateString("service", "OAuth2") catch {};
json.updateString("domain", "onedrive") catch {};
json.updateString("username", "matt") catch {};
// Append the content of the secret to a Chilkat StringBuilder object.
const sb = try chilkat.StringBuilder.init();
defer sb.deinit();
secrets.getSecretSb(json, sb) catch {
std.debug.print("{s}\n", .{try secrets.getLastErrorText(alloc)});
return;
};
std.debug.print("{s}\n", .{try sb.getAsString(alloc)});
std.debug.print("Success.\n", .{});
}