How to use the http-signature.sign function in http-signature

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 christopherbeck / OCI-Rest-APIs-nodejs / headers.js View on Github external
body = body || "";

    var shaObj = new jsSHA("SHA-256", "TEXT");
    shaObj.update(body);

    req.setHeader("Content-Length", body.length);
    req.setHeader("x-content-sha256", shaObj.getHash('B64'));

    headersToSign = headersToSign.concat([
      "content-type",
      "content-length",
      "x-content-sha256"
    ]);
  }

  httpSignature.sign(req, {
    key: auth.privateKey,
    keyId: apiKeyId,
    headers: headersToSign
  });

  var newAuthHeaderValue = 
    req.getHeader("Authorization").replace("Signature ", "Signature version=\"1\",");
  req.setHeader("Authorization", newAuthHeaderValue);
};

http-signature

Reference implementation of Joyent's HTTP Signature scheme.

MIT
Latest version published 12 months ago

Package Health Score

77 / 100
Full package analysis