docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a simple utility that signs API requests using OAuth 1.0a with HMAC-SHA256 signature method for secure authentication.
You need to implement a request signing utility that:
The utility should handle:
Your function should accept:
httpMethod: String representing the HTTP method (e.g., "GET", "POST")url: String representing the base URL (without query parameters)params: Object containing request parameters (including OAuth parameters)consumerSecret: String containing the OAuth consumer secrettokenSecret: String containing the OAuth token secret (optional, can be empty string)Return the base64-encoded HMAC-SHA256 signature as a string.
/**
* Signs an OAuth request using HMAC-SHA256 signature method.
*
* @param {string} httpMethod - The HTTP method (GET, POST, etc.)
* @param {string} url - The base URL without query parameters
* @param {Object} params - Request parameters including OAuth parameters
* @param {string} consumerSecret - OAuth consumer secret
* @param {string} tokenSecret - OAuth token secret (can be empty string)
* @returns {string} Base64-encoded HMAC-SHA256 signature
*/
function signRequest(httpMethod, url, params, consumerSecret, tokenSecret) {
// Implementation here
}
module.exports = { signRequest };Provides OAuth 1.0a signature generation with HMAC-SHA256 support.