docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
A flexible OAuth 1.0 request signing utility that supports multiple signature methods based on configuration.
Implement a request signing function that dynamically selects the appropriate OAuth 1.0 signature method based on a configuration object. The function should support all four standard OAuth signature methods and generate valid signatures for HTTP requests.
The signing function should accept:
config: An object containing:
method: The signature method name (string: 'HMAC-SHA1', 'HMAC-SHA256', 'RSA-SHA1', or 'PLAINTEXT')httpMethod: The HTTP method (e.g., 'GET', 'POST')url: The request URLparams: Request parameters (object with key-value pairs)consumerSecret: The OAuth consumer secrettokenSecret: The OAuth token secret (optional, defaults to empty string if not provided)privateKey: PEM-formatted RSA private key (required only when method is 'RSA-SHA1')The function should return the OAuth signature string.
/**
* Signs an OAuth request using the specified signature method from configuration.
*
* @param {Object} config - Configuration object for signing
* @param {string} config.method - Signature method: 'HMAC-SHA1', 'HMAC-SHA256', 'RSA-SHA1', or 'PLAINTEXT'
* @param {string} config.httpMethod - HTTP method (e.g., 'GET', 'POST')
* @param {string} config.url - Request URL
* @param {Object} config.params - Request parameters
* @param {string} config.consumerSecret - OAuth consumer secret
* @param {string} [config.tokenSecret=''] - OAuth token secret (optional, defaults to empty string)
* @param {string} [config.privateKey] - PEM-formatted RSA private key (required only for RSA-SHA1)
* @returns {string} The OAuth signature
* @throws {Error} Throws an error if the signature method is unsupported
*/
function signRequest(config) {
// IMPLEMENTATION HERE
}
module.exports = {
signRequest,
};Provides OAuth 1.0 signature generation support.