Zig Requires Chilkat v11.5.0+
Zig
curl Update Local Manager Secrets
See more CURL Examples
Demonstrates how to initially write secrets to the local manager that will later be used in curl commands. On Windows, this refers to the Windows Credential Manager, and on macOS, it refers to the Apple Keychain.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 will store 3 secrets in the local manager.
// On Windows, this refers to the Windows Credential Manager, and on macOS, it refers to the Apple Keychain.
// These secrets will be used at a later point in time in curl commands,
// as shown in this example: Using Local Manager Secrets with curl
// Also see: Chilkat v11.5.0 — Secrets Integration
// and also: Chilkat Secrets API
const secrets = try chilkat.Secrets.init();
defer secrets.deinit();
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateString("appName", "sharepoint") catch {};
json.updateString("service", "oauth2") catch {};
json.updateString("username", "client_id") catch {};
// These are not actual/real values..
secrets.updateSecretStr(json, "4afc67c5-6d3f-4ed0-91c7-5d239c78bff7") catch {
std.debug.print("{s}\n", .{try secrets.getLastErrorText(alloc)});
return;
};
json.updateString("username", "client_secret") catch {};
secrets.updateSecretStr(json, "Rlh8Q~xaP10Dw-goWQDLXrRJfYAFVW1hHauvfhO6") catch {
std.debug.print("{s}\n", .{try secrets.getLastErrorText(alloc)});
return;
};
json.updateString("username", "token_endpoint") catch {};
secrets.updateSecretStr(json, "https://login.microsoftonline.com/5f410b89-177f-40b3-9d66-ac519c728025/oauth2/v2.0/token") catch {
std.debug.print("{s}\n", .{try secrets.getLastErrorText(alloc)});
return;
};
// -----------------------------------------------------------------------------------------------------------
// The above secrets would be accessed like this:
const json2 = try chilkat.JsonObject.init();
defer json2.deinit();
json2.setEnableSecrets(true);
// Chilkat sees the secret specification string (beginning with "!!") and resolves from the local manager.
json2.updateString("x", "!!sharepoint|oauth2|client_id") catch {};
std.debug.print("x = {s}\n", .{try json2.stringOf(alloc, "x")});
json2.updateString("y", "!!sharepoint|oauth2|client_secret") catch {};
std.debug.print("y = {s}\n", .{try json2.stringOf(alloc, "y")});
json2.updateString("z", "!!sharepoint|oauth2|token_endpoint") catch {};
std.debug.print("z = {s}\n", .{try json2.stringOf(alloc, "z")});
// You can see the values retrieved from the local manager:
// x = 4afc67c5-6d3f-4ed0-91c7-5d239c78bff7
// y = Rlh8Q~xaP10Dw-goWQDLXrRJfYAFVW1hHauvfhO6
// z = https://login.microsoftonline.com/5f410b89-177f-40b3-9d66-ac519c728025/oauth2/v2.0/token
}