OAuth1 Chilkat2 Perl Reference Documentation

Chilkat2::OAuth1

Current Version: 11.7.0

Markdown version of this page for AI tools (v 11.7.0) · all AI docs

Chilkat.OAuth1

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

Generate the OAuth 1.0 signature and related authentication values from the HTTP method, request URL, credentials, token, nonce, and timestamp.

Authorization header

Produce the value to send in the HTTP Authorization header when OAuth parameters should be supplied as a header.

Signed URL output

Generate a URL that includes the OAuth 1.0 query parameters when the API expects authentication data in the request URL.

Extra signed parameters

Add or remove request-specific name/value parameters that must be included in the normalized parameter string and signature calculation.

HMAC or RSA signatures

Sign with HMAC-SHA1, HMAC-SHA256, RSA-SHA1, or RSA-SHA256, with RSA private keys supplied by SetRsaKey.

Debuggable signing details

Inspect the exact BaseString, HmacKey, QueryString, Signature, and EncodedSignature used to build the OAuth request.

Common pattern: Set 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.
URL guidance: Set 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

use Chilkat2;

my $oAuth1 = Chilkat2::OAuth1->new;
# or set properties (and RaiseError) at creation:
# my $oAuth1 = Chilkat2::OAuth1->new(VerboseLogging => 1, RaiseError => 1);
my $oAuth1 = Chilkat2::OAuth1->new(Property => $value, ...);

Creates the object. The optional pairs set writable properties (and RaiseError) in order, as if set one by one; an unknown or read-only name croaks. use Chilkat2; loads every class; the Chilkat2/OAuth1.pm file holds only this class's documentation (perldoc Chilkat2::OAuth1).

Perl frees the object when its last reference goes (undef $oAuth1, or the variable going out of scope); there is nothing to close. Objects returned by methods are independent and freed the same way. The class may be subclassed (use parent -norequire, 'Chilkat2::OAuth1';): an object is a blessed hash reference whose hash is free for the subclass's own fields.

my $boolVal = $oAuth1->RaiseError;
$oAuth1->RaiseError($boolVal);

When false (the default), a method that fails returns false (or undef), and the reason is in LastErrorText. When true, it dies with a Chilkat2::Error instead, as DBI does with its RaiseError. Objects returned by a method inherit the value of the object that returned them.

Errors

A Chilkat2::Error stringifies to the failed call's full LastErrorText, and has the methods text, class ('Chilkat2::OAuth1'), method (the method name) and object. Methods that look something up and find nothing return undef without dying (each such method says so), methods that answer a question (HasMember, IsUnlocked, ...) return a plain boolean, and property reads and writes never fail for Chilkat reasons.

Misuse always croaks, with your file and line, whatever RaiseError is: a wrong number of arguments, a reference or undef where a string or number is expected, an object of the wrong class, an out-of-range integer, a string containing a NUL character, a wide character in a byte string, or a write to a read-only property.

Strings are Perl character strings in both directions (length, regexes and :encoding layers see characters); binary data (BinData) is a byte string. Unlocking: call Chilkat2::Global->new->UnlockBundle('...') once at startup.

Properties

AuthorizationHeader
# $strVal is a string (read-only)
my $strVal = $oAuth1->AuthorizationHeader;
Introduced in version 9.5.0.53

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.

top
BaseString
# $strVal is a string (read-only)
my $strVal = $oAuth1->BaseString;
Introduced in version 9.5.0.53

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.

top
ConsumerKey
# $strVal is a string
my $strVal = $oAuth1->ConsumerKey;
$oAuth1->ConsumerKey($strVal);
Introduced in version 9.5.0.53

The consumer key.

top
ConsumerSecret
# $strVal is a string
my $strVal = $oAuth1->ConsumerSecret;
$oAuth1->ConsumerSecret($strVal);
Introduced in version 9.5.0.53

The consumer secret.

top
DebugLogFilePath
# $strVal is a string
my $strVal = $oAuth1->DebugLogFilePath;
$oAuth1->DebugLogFilePath($strVal);

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.

More Information and Examples
top
EncodedSignature
# $strVal is a string (read-only)
my $strVal = $oAuth1->EncodedSignature;
Introduced in version 9.5.0.53

The URL encoded representation of the Signature property

top
GeneratedUrl
# $strVal is a string (read-only)
my $strVal = $oAuth1->GeneratedUrl;
Introduced in version 9.5.0.53

The URL that includes the OAuth1 query params.

top
HmacKey
# $strVal is a string (read-only)
my $strVal = $oAuth1->HmacKey;
Introduced in version 9.5.0.53

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).

top
LastErrorHtml
# $strVal is a string (read-only)
my $strVal = $oAuth1->LastErrorHtml;

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.

top
LastErrorText
# $strVal is a string (read-only)
my $strVal = $oAuth1->LastErrorText;

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.

top
LastErrorXml
# $strVal is a string (read-only)
my $strVal = $oAuth1->LastErrorXml;

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.

top
LastMethodSuccess
# $boolVal is a boolean
my $boolVal = $oAuth1->LastMethodSuccess;
$oAuth1->LastMethodSuccess($boolVal);

Indicates the success or failure of the most recent method call: 1 means success, 0 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.

top
Nonce
# $strVal is a string
my $strVal = $oAuth1->Nonce;
$oAuth1->Nonce($strVal);
Introduced in version 9.5.0.53

The nonce.

top
OauthMethod
# $strVal is a string
my $strVal = $oAuth1->OauthMethod;
$oAuth1->OauthMethod($strVal);
Introduced in version 9.5.0.53

The HTTP method, such as GET, POST, PUT, DELETE, or HEAD. Defaults to GET.

top
OauthUrl
# $strVal is a string
my $strVal = $oAuth1->OauthUrl;
$oAuth1->OauthUrl($strVal);
Introduced in version 9.5.0.53

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=1
Instead, set OAuthUrl equal to
https://rest.sandbox.netsuite.com/app/site/hosting/restlet.nl
and then subsequently call AddParam for each query parameter.

top
OauthVersion
# $strVal is a string
my $strVal = $oAuth1->OauthVersion;
$oAuth1->OauthVersion($strVal);
Introduced in version 9.5.0.53

The oauth_version. Defaults to 1.0. May be set to the empty string to exclude.

top
QueryString
# $strVal is a string (read-only)
my $strVal = $oAuth1->QueryString;
Introduced in version 9.5.0.53

Contains the normalized set of request parameters that are signed. This is a read-only property made available for debugging purposes.

top
Realm
# $strVal is a string
my $strVal = $oAuth1->Realm;
$oAuth1->Realm($strVal);
Introduced in version 9.5.0.70

The realm (optional).

top
Signature
# $strVal is a string (read-only)
my $strVal = $oAuth1->Signature;
Introduced in version 9.5.0.53

The generated base64 signature.

top
SignatureMethod
# $strVal is a string
my $strVal = $oAuth1->SignatureMethod;
$oAuth1->SignatureMethod($strVal);
Introduced in version 9.5.0.53

The signature method. Defaults to HMAC-SHA1. Other possible choices are HMAC-SHA256, RSA-SHA1, and RSA-SHA256 (or the equivalent RSA-SHA2).

More Information and Examples
top
Timestamp
# $strVal is a string
my $strVal = $oAuth1->Timestamp;
$oAuth1->Timestamp($strVal);
Introduced in version 9.5.0.53

The timestamp, such as 1441632569.

top
Token
# $strVal is a string
my $strVal = $oAuth1->Token;
$oAuth1->Token($strVal);
Introduced in version 9.5.0.53

The token.

top
TokenSecret
# $strVal is a string
my $strVal = $oAuth1->TokenSecret;
$oAuth1->TokenSecret($strVal);
Introduced in version 9.5.0.53

The token secret

top
UncommonOptions
# $strVal is a string
my $strVal = $oAuth1->UncommonOptions;
$oAuth1->UncommonOptions($strVal);
Introduced in version 9.5.0.85

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.

top
VerboseLogging
# $boolVal is a boolean
my $boolVal = $oAuth1->VerboseLogging;
$oAuth1->VerboseLogging($boolVal);

If set to 1, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is 0. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
# $strVal is a string (read-only)
my $strVal = $oAuth1->Version;

Version of the component/library, such as "10.1.0"

More Information and Examples
top

Methods

AddParam
# $name is a string
# $value is a string
# $success is true or false
my $success = $oAuth1->AddParam($name, $value);
Introduced in version 9.5.0.53

Adds an extra name/value parameter to the OAuth1 signature.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

More Information and Examples
top
Generate
# $success is true or false
my $success = $oAuth1->Generate();
Introduced in version 9.5.0.53

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 true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

More Information and Examples
top
GenNonce
# $numBytes is an integer
# $success is true or false
my $success = $oAuth1->GenNonce($numBytes);
Introduced in version 9.5.0.55

Generates a random nonce $numBytes in length and sets the Nonce property to the hex encoded value.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
GenTimestamp
# $success is true or false
my $success = $oAuth1->GenTimestamp();
Introduced in version 9.5.0.55

Sets the Timestamp property to the current date/time.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
RemoveParam
# $name is a string
# $success is true or false
my $success = $oAuth1->RemoveParam($name);
Introduced in version 9.5.0.53

Removes a name/value parameter from the OAuth1 signature.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
SetRsaKey
# $privKey is a Chilkat2::PrivateKey
# $success is true or false
my $success = $oAuth1->SetRsaKey($privKey);
Introduced in version 9.5.0.64

Sets the RSA key to be used when the SignatureMethod is set to RSA-SHA1 or RSA-SHA2.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top