OAuth1 Lua Reference Documentation
chilkat.OAuth1
Current Version: 11.7.0
Markdown version of this page for AI tools (v 11.7.0) · all AI docs
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
local chilkat = require("chilkat")
local oauth1 = chilkat.OAuth1.new()Creates the object (chilkat.OAuth1() does the same). Lua's garbage collector frees it when it is no longer referenced; oauth1:dispose() frees it at once, and in Lua 5.4 and later local oauth1 <close> = chilkat.OAuth1.new() frees it when the block ends. Calling a method of a disposed object raises an error.
Errors
A method that fails returns nil followed by the error text, as io.open does: local body, err = oauth1:method(...), where err is the object's last_error_text. Wrap the call in assert() to raise an error with that text instead. Methods that answer a question return true or false, numbers are returned as they are (check last_method_success where the description says a value means failure), and property reads and writes never fail for Chilkat reasons.
Misuse raises a Lua error: a wrong argument type or a missing argument (bad argument #1 to ...), an unknown property name, a write to a read-only property, an out-of-range integer, or an object of the wrong class.
Names are Chilkat's in snake_case: QuickGetStr is quick_get_str, LastErrorText is last_error_text. Properties are fields (oauth1.verbose_logging = true) and methods use the colon (oauth1:method(...)). Strings are UTF-8; binary data is a Lua string of bytes. Indexes are 0-based, as in every Chilkat API. Unlocking: call chilkat.unlock_bundle("...") once at startup.
Properties
AuthorizationHeader
local strVal = oauth1.authorization_header
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
local strVal = oauth1.base_string
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
local strVal = oauth1.consumer_key
oauth1.consumer_key = strVal
The consumer key.
topConsumerSecret
local strVal = oauth1.consumer_secret
oauth1.consumer_secret = strVal
The consumer secret.
topDebugLogFilePath
local strVal = oauth1.debug_log_file_path
oauth1.debug_log_file_path = 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.
EncodedSignature
local strVal = oauth1.encoded_signature
The URL encoded representation of the Signature property
topGeneratedUrl
local strVal = oauth1.generated_url
The URL that includes the OAuth1 query params.
topHmacKey
local strVal = oauth1.hmac_key
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
local strVal = oauth1.last_error_html
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
local strVal = oauth1.last_error_text
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
local strVal = oauth1.last_error_xml
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
local boolVal = oauth1.last_method_success
oauth1.last_method_success = boolVal
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
local strVal = oauth1.nonce
oauth1.nonce = strVal
The nonce.
topOauthMethod
local strVal = oauth1.oauth_method
oauth1.oauth_method = strVal
The HTTP method, such as GET, POST, PUT, DELETE, or HEAD. Defaults to GET.
OauthUrl
local strVal = oauth1.oauth_url
oauth1.oauth_url = strVal
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
local strVal = oauth1.oauth_version
oauth1.oauth_version = strVal
The oauth_version. Defaults to 1.0. May be set to the empty string to exclude.
QueryString
local strVal = oauth1.query_string
Contains the normalized set of request parameters that are signed. This is a read-only property made available for debugging purposes.
topRealm
local strVal = oauth1.realm
oauth1.realm = strVal
The realm (optional).
topSignature
local strVal = oauth1.signature
The generated base64 signature.
topSignatureMethod
local strVal = oauth1.signature_method
oauth1.signature_method = strVal
The signature method. Defaults to HMAC-SHA1. Other possible choices are HMAC-SHA256, RSA-SHA1, and RSA-SHA256 (or the equivalent RSA-SHA2).
Timestamp
local strVal = oauth1.timestamp
oauth1.timestamp = strVal
The timestamp, such as 1441632569.
Token
local strVal = oauth1.token
oauth1.token = strVal
The token.
topTokenSecret
local strVal = oauth1.token_secret
oauth1.token_secret = strVal
The token secret
topUncommonOptions
local strVal = oauth1.uncommon_options
oauth1.uncommon_options = strVal
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
local boolVal = oauth1.verbose_logging
oauth1.verbose_logging = boolVal
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
local strVal = oauth1.version
Methods
AddParam
-- value is a string
-- ok is true, or nil and err on failure
local ok, err = oauth1:add_param(name, value)
Adds an extra name/value parameter to the OAuth1 signature.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
Generate
local ok, err = oauth1: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 true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
GenNonce
-- ok is true, or nil and err on failure
local ok, err = oauth1:gen_nonce(num_bytes)
Generates a random nonce num_bytes in length and sets the Nonce property to the hex encoded value.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
GenTimestamp
local ok, err = oauth1:gen_timestamp()
Sets the Timestamp property to the current date/time.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
RemoveParam
-- ok is true, or nil and err on failure
local ok, err = oauth1:remove_param(name)
Removes a name/value parameter from the OAuth1 signature.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
SetRsaKey
-- ok is true, or nil and err on failure
local ok, err = oauth1:set_rsa_key(priv_key)
Sets the RSA key to be used when the SignatureMethod is set to RSA-SHA1 or RSA-SHA2.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.