Zig
Zig
Generate OAuth 1.0 Signature
Demonstrates how to generate an OAuth 1.0 signature.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
var success: bool = false;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
success = false;
const oauth = try chilkat.OAuth1.init();
defer oauth.deinit();
// Set input parameters:
oauth.setOauthVersion("1.0");
oauth.setOauthMethod("GET");
oauth.setOauthUrl("http://echo.lab.madgex.com/echo.ashx");
oauth.setConsumerKey("key");
oauth.setConsumerSecret("secret");
oauth.setToken("accesskey");
oauth.setTokenSecret("accesssecret");
oauth.setNonce("01020304050607080102030405060708");
oauth.setTimestamp("1441659763");
// Can be "HMAC-SHA1", "HMAC-SHA256", "RSA-SHA1", or "RSA-SHA2"
oauth.setSignatureMethod("HMAC-SHA256");
oauth.generate() catch {
std.debug.print("{s}\n", .{try oauth.getLastErrorText(alloc)});
return;
};
// Examine the various outputs:
std.debug.print("{s}\n", .{try oauth.getQueryString(alloc)});
std.debug.print("{s}\n", .{try oauth.getBaseString(alloc)});
std.debug.print("{s}\n", .{try oauth.getHmacKey(alloc)});
std.debug.print("{s}\n", .{try oauth.getSignature(alloc)});
std.debug.print("{s}\n", .{try oauth.getEncodedSignature(alloc)});
std.debug.print("{s}\n", .{try oauth.getAuthorizationHeader(alloc)});
std.debug.print("{s}\n", .{try oauth.getGeneratedUrl(alloc)});
}