src/mandrill-webhook-authenticator.js
function(req, res, next) {

      var signature = req.headers[MANDRILL_SIGNATURE_HEADER];
      var fullUrl = options.domain + req.url;
      var isValid = validator(fullUrl, req.body, signature);
      var respondWith = responder(res);

      if (!signature) {
        respondWith(401, NOT_AUTHORIZED);
      }else if (req.body && req.body.mandrill_events === '[]' && isValid('test-webhook')) {
        respondWith(200, OK);
      }else if (!isValid(options.webhookAuthKey)) {
        respondWith(403, FORBIDDEN);
      } else {
        next();
      }
    }
function(req, res, next) {

      var signature = req.headers[MANDRILL_SIGNATURE_HEADER];
      var fullUrl = options.domain + req.url;
      var isValid = validator(fullUrl, req.body, signature);
      var respondWith = responder(res);

      if (!signature) {
        respondWith(401, NOT_AUTHORIZED);
      }else if (req.body && req.body.mandrill_events === '[]' && isValid('test-webhook')) {
        respondWith(200, OK);
      }else if (!isValid(options.webhookAuthKey)) {
        respondWith(403, FORBIDDEN);
      } else {
        next();
      }
    }
function ( req , res , next ) { var signature = req . headers [ MANDRILL_SIGNATURE_HEADER ] ; var fullUrl = options . domain + req . url ; var isValid = validator ( fullUrl , req . body , signature ) ; var respondWith = responder ( res ) ; if ( ! signature ) { respondWith ( 401 , NOT_AUTHORIZED ) ; } else if ( req . body && req . body . mandrill_events === '[]' && isValid ( 'test-webhook' ) ) { respondWith ( 200 , OK ) ; } else if ( ! isValid ( options . webhookAuthKey ) ) { respondWith ( 403 , FORBIDDEN ) ; } else { next ( ) ; } }
Express middleware compatible function to process requests and only continure if the signature is valid. Will return 200 if the request is a test request. It does not update the request.
@param { Request } req
@param { Response } res
@param { function } next
Express middleware compatible function to process requests and only continure if the signature is valid . Will return 200 if the request is a test request . It does not update the request .