It requires the below steps:
To create the signature:
Concatenate the following values: ‘x-mc-date’ + ‘:’ + ‘x-mc-req-id’ + ‘:’ + ‘{uri} + ‘:’ + {application key}’ where {uri} is the actual uri of the endpoint the request is sent to and {application key} is the application key value provided when you registered your application. This creates the Data To Sign.
Use the user’s base64 decoded Secret Key to calculate the hash-based message authentication code (HMAC) of the Data To Sign using the HMAC-SHA1 algorithm.
Base64 encode the result of the signed Data to Sign.
Add an Authorization header to your request containing the following elements:
{realm} {accessKey}:{Base64 encoded signed Data To Sign}
Where:
{realm} is MC
{accessKey} is the user’s Access Key.
{Base64 encoded signed Data To Sign} is the result of the calculation made in step 3.
What is the error message (if any)?
I am currently getting an invalid signature error which I assume is because I am struggling with Step2.
I can’t use the Crypto Node as no SHA1 support so have tried the below:
I have found some similar topics in the community as produced code, I notice however whatever I put in key doesn’t change the MyHash output. Assume I am doing something wrong, any help appreciated.
An HMAC is different from a simple hash value. It is a way to calculate a signature for a message using a shared secret key.
You will need code along these lines (not tested in n8n as I don’t have example data):
function base64Decode(base64String) {
return Uint8Array.from(atob(base64String), c => c.charCodeAt(0));
}
function createAuthorizationHeader({ uri, applicationKey, secretKey, accessKey, xMcDate, xMcReqId, realm }) {
// Concatenate values to create Data To Sign
const dataToSign = `${xMcDate}:${xMcReqId}:${uri}:${applicationKey}`;
// Decode the base64 encoded secret key
const decodedSecretKey = base64Decode(secretKey);
// Create HMAC-SHA1 hash using the decoded secret key
const hmac = crypto.createHmac('sha1', decodedSecretKey);
// Update the HMAC with the Data To Sign
hmac.update(dataToSign);
// Base64 encode the result of the signed Data To Sign
const signedDataToSign = hmac.digest('base64');
// Create the Authorization header value
const authorizationHeader = `${realm} ${accessKey}:${signedDataToSign}`;
return authorizationHeader;
}