How to use http-signature - 10 common examples

To help you get started, we’ve selected a few http-signature examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GetStream / stream-js / src / lib / batch_operations.js View on Github external
function(fulfill, reject) {
        this.send('request', 'post', kwargs, cb);

        kwargs.url = this.enrichUrl(kwargs.url);
        kwargs.json = true;
        kwargs.method = 'POST';
        kwargs.headers = { 'X-Api-Key': this.apiKey };
        // Make sure withCredentials is not enabled, different browser
        // fallbacks handle it differently by default (meteor)
        kwargs.withCredentials = false;

        var callback = this.wrapPromiseTask(cb, fulfill, reject);
        var req = request(kwargs, callback);

        httpSignature.sign(req, {
          algorithm: 'hmac-sha256',
          key: this.apiSecret,
          keyId: this.apiKey,
        });
      }.bind(this)
    );
github christopherbeck / OCI-Rest-APIs-nodejs / utils / ocirest.js View on Github external
// methodsThatRequireExtraHeaders ["POST", "PUT"];
  if(["POST","PUT"].indexOf(request.method.toUpperCase()) !== -1 ) 
  {
    body = body || ""; 
    request.setHeader("content-length", body.length);
    headersToSign = headersToSign.concat([ "content-type", "content-length" ]);

    if ( request.getHeader('content-type') != 'application/x-www-form-urlencoded' ){
      var shaObj = new jsSHA("SHA-256", "TEXT");
      shaObj.update(body);
      request.setHeader("x-content-sha256", shaObj.getHash('B64'));
      headersToSign = headersToSign.concat([ "x-content-sha256" ]);
    }
  }

  httpSignature.sign( request, { key: auth.privateKey,
                                 keyId: auth.tenancyId + "/" + 
                                        auth.userId + "/" + 
                                        auth.keyFingerprint,
                                 headers: headersToSign } );

  var newAuthHeaderValue = request.getHeader("Authorization").replace("Signature ", "Signature version=\"1\",");
  request.setHeader("Authorization", newAuthHeaderValue);
};
github christopherbeck / OCI-Rest-APIs-nodejs / ocirest_old.js View on Github external
// methodsThatRequireExtraHeaders ["POST", "PUT"];
  if(["POST","PUT"].indexOf(request.method.toUpperCase()) !== -1 ) 
  {
    body = body || ""; 
    request.setHeader("content-length", body.length);
    headersToSign = headersToSign.concat([ "content-type", "content-length" ]);

    if ( request.headers['content-type'] == 'x-www-form-urlencoded' ){
      var shaObj = new jsSHA("SHA-256", "TEXT");
      shaObj.update(body);
      request.setHeader("x-content-sha256", shaObj.getHash('B64'));
      headersToSign = headersToSign.concat([ "x-content-sha256" ]);
    }
  }

  httpSignature.sign( request, { key: auth.privateKey,
                                 keyId: auth.tenancyId + "/" + 
                                        auth.userId + "/" + 
                                        auth.keyFingerprint,
                                 headers: headersToSign } );

  var newAuthHeaderValue = request.getHeader("Authorization").replace("Signature ", "Signature version=\"1\",");
  request.setHeader("Authorization", newAuthHeaderValue);
};
github cloudsploit / scans / other_modules / oci / helpers.js View on Github external
var parentOcidVal = parentOcidArr[parentOcidArr.length-1];

                if (respBody.length) {
                    respBody.forEach(resp => {
                        resp[parentOcidName] = parentOcidVal
                    });
                } else {
                    respBody[parentOcidName] = parentOcidVal
                }
            }
            callback(respBody);
        });
    });

    // Create signature
    signature.sign(request, {
        key: OracleConfig.privateKey,
        keyId: [OracleConfig.tenancyId, OracleConfig.userId, OracleConfig.keyFingerprint].join('/'),
        headers: ["host", "date", "(request-target)"]
    });

    var oldAuthHead = request.getHeader("Authorization");
    var newAuthHead = oldAuthHead.replace("Signature ", "Signature version=\"1\",");
    request.setHeader("Authorization", newAuthHead);

    var requestToWrite = (body === undefined ? '': body);
    request.write(requestToWrite);
    request.end();
}
github rdkmaster / rdk / test / node_modules / protractor / node_modules / request / request.js View on Github external
Request.prototype.httpSignature = function (opts) {
  var self = this
  httpSignature.signRequest({
    getHeader: function(header) {
      return self.getHeader(header, self.headers)
    },
    setHeader: function(header, value) {
      self.setHeader(header, value)
    },
    method: self.method,
    path: self.path
  }, opts)
  debug('httpSignature authorization', self.getHeader('authorization'))

  return self
}
Request.prototype.hawk = function (opts) {
github request / request / tests / test-http-signature.js View on Github external
var server = http.createServer(function (req, res) {
  var parsed = httpSignature.parseRequest(req)
  var publicKeyPEM = publicKeyPEMs[parsed.keyId]
  var verified = httpSignature.verifySignature(parsed, publicKeyPEM)
  res.writeHead(verified ? 200 : 400)
  res.end()
})
github request / request / tests / test-http-signature.js View on Github external
var server = http.createServer(function (req, res) {
  var parsed = httpSignature.parseRequest(req)
  var publicKeyPEM = publicKeyPEMs[parsed.keyId]
  var verified = httpSignature.verifySignature(parsed, publicKeyPEM)
  res.writeHead(verified ? 200 : 400)
  res.end()
})
github SmartThingsCommunity / smartapp-sdk-nodejs / lib / util / signature.js View on Github external
signatureIsVerified(req) {
		try {
			const parsed = httpSignature.parseRequest(req)
			if (!httpSignature.verifySignature(parsed, publicKey)) {
				console.error('Forbidden - failed verifySignature')
				return false
			}
		} catch (error) {
			console.error(error)
			return false
		}

		return true
	}
}
github hisaacdelr / ColtSteele_WebDevCourse / Node / APIs / IntroToAPIs / node_modules / request / request.js View on Github external
Request.prototype.httpSignature = function (opts) {
  var self = this
  httpSignature.signRequest({
    getHeader: function(header) {
      return self.getHeader(header, self.headers)
    },
    setHeader: function(header, value) {
      self.setHeader(header, value)
    },
    method: self.method,
    path: self.path
  }, opts)
  debug('httpSignature authorization', self.getHeader('authorization'))

  return self
}
Request.prototype.hawk = function (opts) {
github silklabs / silk / node_modules / request / request.js View on Github external
Request.prototype.httpSignature = function (opts) {
  var self = this
  httpSignature.signRequest({
    getHeader: function(header) {
      return self.getHeader(header, self.headers)
    },
    setHeader: function(header, value) {
      self.setHeader(header, value)
    },
    method: self.method,
    path: self.path
  }, opts)
  debug('httpSignature authorization', self.getHeader('authorization'))

  return self
}
Request.prototype.hawk = function (opts) {

http-signature

Reference implementation of Joyent's HTTP Signature scheme.

MIT
Latest version published 6 months ago

Package Health Score

81 / 100
Full package analysis