Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. // middleware.js
  2. const functions = require('firebase-functions');
  3. import * as crypto from 'crypto';
  4.  
  5. export const auth = (req, res, next) => {
  6. let hash = crypto.createHash('sha512');
  7. hash.update(config.starling.key + req.rawBody));
  8. req.hasha = hash.digest('base64');
  9.  
  10. // req.hasha is different from req.header('X-Hook-Signature')
  11.  
  12. next();
  13. }
  14.  
  15. import * as functions from 'firebase-functions';
  16. import * as express from 'express';
  17. import * as cors from 'cors';
  18. import * as middleware from './middleware';
  19. import bodyParser = require('body-parser');
  20.  
  21. const app = express();
  22. app.use(cors({ origin: true }));
  23. app.use(bodyParser.json());
  24. app.use(middleware.auth);
  25.  
  26. // Endpoints removed for brevity
  27.  
  28. export const hooks = functions.https.onRequest(app);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement