n8n-nodes-twitter-uploader-inf
Version:
Twitter media upload nodes for n8n
56 lines • 2.12 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OAuth1Helper = void 0;
const crypto_1 = __importDefault(require("crypto"));
const n8n_workflow_1 = require("n8n-workflow");
const OAuth1 = require('oauth-1.0a');
class OAuth1Helper {
constructor(config, node) {
this.consumerKey = config.consumerKey;
this.consumerSecret = config.consumerSecret;
this.accessToken = config.accessToken;
this.accessSecret = config.accessSecret;
this.node = node;
this.validateParameters();
}
generateAuthHeader(requestData) {
if (!this.accessToken || !this.accessSecret) {
throw new n8n_workflow_1.NodeOperationError(this.node, 'Missing required OAuth parameters: accessToken and accessSecret');
}
const oauth = new OAuth1({
consumer: {
key: this.consumerKey,
secret: this.consumerSecret,
},
signature_method: 'HMAC-SHA1',
hash_function(base_string, key) {
return crypto_1.default
.createHmac('sha1', key)
.update(base_string)
.digest('base64');
},
});
const token = {
key: this.accessToken,
secret: this.accessSecret,
};
const authHeader = oauth.authorize(requestData, token);
return oauth.toHeader(authHeader).Authorization;
}
validateParameters() {
const required = [
{ field: 'consumerKey', value: this.consumerKey },
{ field: 'consumerSecret', value: this.consumerSecret },
];
for (const { field, value } of required) {
if (!value) {
throw new n8n_workflow_1.NodeOperationError(this.node, `Missing required OAuth parameter: ${field}`);
}
}
}
}
exports.OAuth1Helper = OAuth1Helper;
//# sourceMappingURL=TwitterUtils.js.map