OAuth1 Zig Reference Documentation
OAuth1
Current Version: 11.6.1
Chilkat.OAuth1
Generate the OAuth 1.0 signature and related authentication values from
the HTTP method, request URL, credentials, token, nonce, and timestamp.
Produce the value to send in the HTTP
Generate a URL that includes the OAuth 1.0 query parameters when the API
expects authentication data in the request URL.
Add or remove request-specific name/value parameters that must be
included in the normalized parameter string and signature calculation.
Sign with
Inspect the exact Generate OAuth 1.0 signatures, authorization headers, and signed request URLs.
Chilkat.OAuth1 builds the signed OAuth 1.0 authentication data
needed for APIs that still require OAuth 1.0 request signing. It can generate
the signature base string, HMAC key, signature, URL-encoded signature,
normalized signed parameter string, Authorization header, and generated URL
containing OAuth query parameters. It supports consumer credentials, access
tokens, nonce and timestamp generation, extra signed parameters, optional
realm handling, HMAC-SHA1, HMAC-SHA256, RSA-SHA1, and RSA-SHA256 signing.
OAuth 1.0 signing
Authorization header
Authorization header
when OAuth parameters should be supplied as a header.
Signed URL output
Extra signed parameters
HMAC or RSA signatures
HMAC-SHA1, HMAC-SHA256,
RSA-SHA1, or RSA-SHA256, with RSA private keys
supplied by SetRsaKey.
Debuggable signing details
BaseString, HmacKey,
QueryString, Signature, and
EncodedSignature used to build the OAuth request.
OauthMethod and OauthUrl, provide the consumer
key and secret, set any token and token secret, generate or assign
Nonce and Timestamp, add request parameters with
AddParam, then call Generate. Use
AuthorizationHeader when sending OAuth data in an HTTP header, or
GeneratedUrl when the signed OAuth parameters should be placed
in the URL.
OauthUrl to the base request URL without query parameters.
Add query parameters separately with AddParam so they are
included correctly in the OAuth 1.0 signature calculation.
Object Creation
// Add the package once:
// zig fetch --save https://chilkatdownload.com/11.6.1/chilkat-zig-11.6.1.tar.gz
// and in build.zig:
// const chilkat = b.dependency("chilkat", .{ .target = target, .optimize = optimize });
// exe.root_module.addImport("chilkat", chilkat.module("chilkat"));
const chilkat = @import("chilkat");
// Once per process, before any other Chilkat call:
try chilkat.unlockBundle("Anything for 30-day trial");
const o_auth1 = try chilkat.OAuth1.init();
defer o_auth1.deinit();Creates the underlying native Chilkat object. OAuth1 is a one-pointer struct passed by value; copying it copies the handle (two names for one object). Returns error.OutOfMemory if the library could not allocate the object. Use an object from one thread at a time; it may be handed from one thread to another.
Releases the native object. Call it exactly once per object (usually with defer); the handle is invalid afterwards. Objects returned by methods are owned by the caller too and are released the same way.
Wraps a handle obtained from the C API (chilkat.c.CkOAuth1), taking ownership of it. The struct's handle field goes the other way, for anything the Zig API does not cover.
Errors and memory
Methods that can fail return an error union: a method whose only outcome is success or failure returns Error!void; a method producing a string returns (Error || Allocator.Error)![:0]u8; a method producing an object returns Error!T. chilkat.Error is error{ChilkatFailed}; the reason for a failure is in getLastErrorText, and the object remains usable. Properties never fail, and methods that answer a question (hasMember, isUnlocked, ...) return a plain bool.
String arguments are [:0]const u8 (UTF-8; string literals can be passed as is). String results are copies allocated with the allocator argument and owned by the caller, so they stay valid across later calls on the same object.
const text = o_auth1.someMethod(allocator, ...) catch |err| {
const why = try o_auth1.getLastErrorText(allocator);
defer allocator.free(why);
std.debug.print("{s}\n", .{why});
return err;
};
defer allocator.free(text);
Properties
AuthorizationHeader
pub fn getAuthorizationHeader(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
The authorization header. This is what would be included in the Authorization HTTP request header if it is going to be used as the means for providing the OAuth1 authorization information.
topBaseString
pub fn getBaseString(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
This is the exact string that was signed. For example, if the signature method is HMAC-SHA1, the BaseString is the exact string that passed to the HMAC-SHA1. An application does not set the BaseString property. The BaseString is exposed as a property to allow for debugging and to see the exact string that is signed.
topConsumerKey
pub fn getConsumerKey(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
pub fn setConsumerKey(self: OAuth1, value: [:0]const u8) void
The consumer key.
topConsumerSecret
pub fn getConsumerSecret(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
pub fn setConsumerSecret(self: OAuth1, value: [:0]const u8) void
The consumer secret.
topDebugLogFilePath
pub fn getDebugLogFilePath(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
pub fn setDebugLogFilePath(self: OAuth1, value: [:0]const u8) void
If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.
Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.
Possible causes of hangs include:
- A timeout property set to 0, indicating an infinite timeout.
- A hang occurring within an event callback in the application code.
- An internal bug in the Chilkat code causing the hang.
EncodedSignature
pub fn getEncodedSignature(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
The URL encoded representation of the Signature property
topGeneratedUrl
pub fn getGeneratedUrl(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
The URL that includes the OAuth1 query params.
topHmacKey
pub fn getHmacKey(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
The exact HMAC key used to sign the BaseString. An application does not directly set the HmacKey. The HmacKey property is read-only and is provided for debugging to see the exact HMAC key used to sign the BaseString. The HMAC key is composed from the consumer secret (if it exists) and the token secret (if it exists).
topLastErrorHtml
pub fn getLastErrorHtml(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastErrorText
pub fn getLastErrorText(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
LastErrorXml
pub fn getLastErrorXml(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastMethodSuccess
pub fn getLastMethodSuccess(self: OAuth1) bool
pub fn setLastMethodSuccess(self: OAuth1, value: bool) void
Indicates the success or failure of the most recent method call: true means success, false means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.
Nonce
pub fn getNonce(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
pub fn setNonce(self: OAuth1, value: [:0]const u8) void
The nonce.
topOauthMethod
pub fn getOauthMethod(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
pub fn setOauthMethod(self: OAuth1, value: [:0]const u8) void
The HTTP method, such as GET, POST, PUT, DELETE, or HEAD. Defaults to GET.
OauthUrl
pub fn getOauthUrl(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
pub fn setOauthUrl(self: OAuth1, value: [:0]const u8) void
The OAuth URL, such as http://echo.lab.madgex.com/echo.ashx. See http://bettiolo.github.io/oauth-reference-page/ to compare Chilkat results with another tool's results.
Note: The OAuthUrl should not include query parameters. For example, do not set the OAuthUrl equal to
https://rest.sandbox.netsuite.com/app/site/hosting/restlet.nl?script=165&deploy=1Instead, set OAuthUrl equal to
https://rest.sandbox.netsuite.com/app/site/hosting/restlet.nland then subsequently call AddParam for each query parameter. top
OauthVersion
pub fn getOauthVersion(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
pub fn setOauthVersion(self: OAuth1, value: [:0]const u8) void
The oauth_version. Defaults to 1.0. May be set to the empty string to exclude.
QueryString
pub fn getQueryString(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
Contains the normalized set of request parameters that are signed. This is a read-only property made available for debugging purposes.
topRealm
pub fn getRealm(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
pub fn setRealm(self: OAuth1, value: [:0]const u8) void
The realm (optional).
topSignature
pub fn getSignature(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
The generated base64 signature.
topSignatureMethod
pub fn getSignatureMethod(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
pub fn setSignatureMethod(self: OAuth1, value: [:0]const u8) void
The signature method. Defaults to HMAC-SHA1. Other possible choices are HMAC-SHA256, RSA-SHA1, and RSA-SHA256 (or the equivalent RSA-SHA2).
Timestamp
pub fn getTimestamp(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
pub fn setTimestamp(self: OAuth1, value: [:0]const u8) void
The timestamp, such as 1441632569.
Token
pub fn getToken(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
pub fn setToken(self: OAuth1, value: [:0]const u8) void
The token.
topTokenSecret
pub fn getTokenSecret(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
pub fn setTokenSecret(self: OAuth1, value: [:0]const u8) void
The token secret
topUncommonOptions
pub fn getUncommonOptions(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
pub fn setUncommonOptions(self: OAuth1, value: [:0]const u8) void
This is a catch-all property to be used for uncommon needs. This property defaults to the empty string and should typically remain empty.
Can be set to a list of the following comma separated keywords:
INCLUDE_REALM- Introduced in v9.5.0.85. Include the Realm in the signature calculation and outputs.
VerboseLogging
pub fn getVerboseLogging(self: OAuth1) bool
pub fn setVerboseLogging(self: OAuth1, value: bool) void
If set to true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
Version
pub fn getVersion(self: OAuth1, allocator: Allocator) Allocator.Error![:0]u8
Methods
AddParam
Adds an extra name/value parameter to the OAuth1 signature.
Returns error.ChilkatFailed on failure; getLastErrorText explains why.
Generate
Generate the signature based on the property settings. Input properties are OauthVersion, OauthMethod, Url, ConsumerKey, ConsumerSecret, Token, TokenSecret, Nonce, and Timestamp. Properties set by this method include: BaseString, Signature, HmacKey, EncodedSignature, QueryString, GeneratedUrl, andAuthorizationHeader.
Returns error.ChilkatFailed on failure; getLastErrorText explains why.
GenNonce
Generates a random nonce num_bytes in length and sets the Nonce property to the hex encoded value.
Returns error.ChilkatFailed on failure; getLastErrorText explains why.
GenTimestamp
Sets the Timestamp property to the current date/time.
Returns error.ChilkatFailed on failure; getLastErrorText explains why.
RemoveParam
Removes a name/value parameter from the OAuth1 signature.
Returns error.ChilkatFailed on failure; getLastErrorText explains why.
SetRsaKey
Sets the RSA key to be used when the SignatureMethod is set to RSA-SHA1 or RSA-SHA2.
Returns error.ChilkatFailed on failure; getLastErrorText explains why.