mashery/iodocs — pull request #138 by rowanhill (2013-12-03 00:32:18+00:00)
Title: Extensible request signing

Hi,

In issue #134 I asked about extension points in iodocs - specifically I was interested in providing my own request signing logic (although I was a bit imprecise and called this an 'authentication mechanism'). I haven't seen anything suggesting this is currently possible, so I've quickly put something together - hopefully it's useful.

This change pulls out some of the existing signing code into a `signers` directory, and dynamically requires these signers at run time. (I've also commonised some of the existing code). This allows users of iodocs to use a custom signing method by just writing a new signer, popping it in the signers directory, and adding the appropriate signature type in apiconfig.json.

This also helps keep things clean - no need to change app.js, so pulling in upstream updates in the future is easier.

Note that the data I'm passing to signRequest is more than the existing signers want - this is because the new signer I want to write needs a few more bits of data. I can't think of anything else any future signer would want, so hopefully this will do for now. Note also that because I need these extra bits of information, I've moved signing slightly later in the process; I don't believe this will cause any issues, though.

If #137 gets any traction, I'll do something similar for configuring the `signers` directory (although that seems a bit doubtful, so I've not bothered for now).

Thanks,
Rowan