Class OAuth1
- All Implemented Interfaces:
AutoCloseable
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.
</section>
Instances hold a native Chilkat object: close them with ChilkatObject.close() (try-with-resources) when
done; an unclosed instance is freed when it becomes unreachable.
- See Also:
- Online reference
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an extra name/value parameter to the OAuth1 signature.voidgenerate()Generate the signature based on the property settings.voidgenNonce(int numBytes)Generates a random noncenumBytesin length and sets the Nonce property to the hex encoded value.voidSets the Timestamp property to the current date/time.The authorization header.This is the exact string that was signed.The consumer key.The consumer secret.The URL encoded representation of the Signature propertyThe URL that includes the OAuth1 query params.The exact HMAC key used to sign the BaseString.getNonce()The nonce.The HTTP method, such asGET,POST,PUT,DELETE, orHEAD.The OAuth URL, such ashttp://echo.lab.madgex.com/echo.ashx.The oauth_version.Contains the normalized set of request parameters that are signed.getRealm()The realm (optional).The generated base64 signature.The signature method.The timestamp, such as1441632569.getToken()The token.The token secretThis is a catch-all property to be used for uncommon needs.voidremoveParam(String name)Removes a name/value parameter from the OAuth1 signature.voidsetConsumerKey(String value)Sets theConsumerKeyproperty; seegetConsumerKey().voidsetConsumerSecret(String value)Sets theConsumerSecretproperty; seegetConsumerSecret().voidSets theNonceproperty; seegetNonce().voidsetOauthMethod(String value)Sets theOauthMethodproperty; seegetOauthMethod().voidsetOauthUrl(String value)Sets theOauthUrlproperty; seegetOauthUrl().voidsetOauthVersion(String value)Sets theOauthVersionproperty; seegetOauthVersion().voidSets theRealmproperty; seegetRealm().voidsetRsaKey(PrivateKey privKey)Sets the RSA key to be used when the SignatureMethod is set toRSA-SHA1orRSA-SHA2.voidsetSignatureMethod(String value)Sets theSignatureMethodproperty; seegetSignatureMethod().voidsetTimestamp(String value)Sets theTimestampproperty; seegetTimestamp().voidSets theTokenproperty; seegetToken().voidsetTokenSecret(String value)Sets theTokenSecretproperty; seegetTokenSecret().voidsetUncommonOptions(String value)Sets theUncommonOptionsproperty; seegetUncommonOptions().Methods inherited from class com.chilkatsoft.chilkat2.ChilkatObject
close, getDebugLogFilePath, getLastErrorHtml, getLastErrorText, getLastErrorXml, getLastMethodSuccess, getVerboseLogging, getVersion, isClosed, setDebugLogFilePath, setLastMethodSuccess, setVerboseLogging, toString
-
Constructor Details
-
OAuth1
public OAuth1()Creates a newOAuth1object.
-
-
Method Details
-
getAuthorizationHeader
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.- Returns:
- the value of the
AuthorizationHeaderproperty (read-only)
-
getBaseString
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.- Returns:
- the value of the
BaseStringproperty (read-only)
-
getConsumerKey
The consumer key.- Returns:
- the value of the
ConsumerKeyproperty
-
setConsumerKey
Sets theConsumerKeyproperty; seegetConsumerKey().- Parameters:
value- the new value (notnull)
-
getConsumerSecret
The consumer secret.- Returns:
- the value of the
ConsumerSecretproperty
-
setConsumerSecret
Sets theConsumerSecretproperty; seegetConsumerSecret().- Parameters:
value- the new value (notnull)
-
getEncodedSignature
The URL encoded representation of the Signature property- Returns:
- the value of the
EncodedSignatureproperty (read-only)
-
getGeneratedUrl
The URL that includes the OAuth1 query params.- Returns:
- the value of the
GeneratedUrlproperty (read-only)
-
getHmacKey
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).- Returns:
- the value of the
HmacKeyproperty (read-only)
-
getNonce
The nonce.- Returns:
- the value of the
Nonceproperty
-
setNonce
Sets theNonceproperty; seegetNonce().- Parameters:
value- the new value (notnull)
-
getOauthMethod
The HTTP method, such asGET,POST,PUT,DELETE, orHEAD. Defaults toGET.- Returns:
- the value of the
OauthMethodproperty
-
setOauthMethod
Sets theOauthMethodproperty; seegetOauthMethod().- Parameters:
value- the new value (notnull)
-
getOauthUrl
The OAuth URL, such ashttp://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.
- Returns:
- the value of the
OauthUrlproperty
-
setOauthUrl
Sets theOauthUrlproperty; seegetOauthUrl().- Parameters:
value- the new value (notnull)
-
getOauthVersion
The oauth_version. Defaults to1.0. May be set to the empty string to exclude.- Returns:
- the value of the
OauthVersionproperty
-
setOauthVersion
Sets theOauthVersionproperty; seegetOauthVersion().- Parameters:
value- the new value (notnull)
-
getQueryString
Contains the normalized set of request parameters that are signed. This is a read-only property made available for debugging purposes.- Returns:
- the value of the
QueryStringproperty (read-only)
-
getRealm
The realm (optional).- Returns:
- the value of the
Realmproperty
-
setRealm
Sets theRealmproperty; seegetRealm().- Parameters:
value- the new value (notnull)
-
getSignature
The generated base64 signature.- Returns:
- the value of the
Signatureproperty (read-only)
-
getSignatureMethod
The signature method. Defaults toHMAC-SHA1. Other possible choices areHMAC-SHA256,RSA-SHA1, andRSA-SHA256(or the equivalentRSA-SHA2).- Returns:
- the value of the
SignatureMethodproperty
-
setSignatureMethod
Sets theSignatureMethodproperty; seegetSignatureMethod().- Parameters:
value- the new value (notnull)
-
getTimestamp
The timestamp, such as1441632569.- Returns:
- the value of the
Timestampproperty
-
setTimestamp
Sets theTimestampproperty; seegetTimestamp().- Parameters:
value- the new value (notnull)
-
getToken
The token.- Returns:
- the value of the
Tokenproperty
-
setToken
Sets theTokenproperty; seegetToken().- Parameters:
value- the new value (notnull)
-
getTokenSecret
The token secret- Returns:
- the value of the
TokenSecretproperty
-
setTokenSecret
Sets theTokenSecretproperty; seegetTokenSecret().- Parameters:
value- the new value (notnull)
-
getUncommonOptions
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.
- Returns:
- the value of the
UncommonOptionsproperty
-
setUncommonOptions
Sets theUncommonOptionsproperty; seegetUncommonOptions().- Parameters:
value- the new value (notnull)
-
addParam
Adds an extra name/value parameter to the OAuth1 signature.- Parameters:
name- thenameargument (notnull)value- thevalueargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
genNonce
public void genNonce(int numBytes)Generates a random noncenumBytesin length and sets the Nonce property to the hex encoded value.- Parameters:
numBytes- thenumBytesargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
genTimestamp
public void genTimestamp()Sets the Timestamp property to the current date/time.- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
generate
public void 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.- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
removeParam
Removes a name/value parameter from the OAuth1 signature.- Parameters:
name- thenameargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setRsaKey
Sets the RSA key to be used when the SignatureMethod is set toRSA-SHA1orRSA-SHA2.- Parameters:
privKey- theprivKeyargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-