Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
lib/ | 12-May-2024 | - | 950 | 572 | ||
.dir-locals.el | D | 12-May-2024 | 178 | 6 | 6 | |
.npmignore | D | 12-May-2024 | 54 | 7 | 7 | |
CHANGES.md | D | 12-May-2024 | 1.3 KiB | 47 | 32 | |
LICENSE | D | 12-May-2024 | 1 KiB | 19 | 16 | |
README.md | D | 12-May-2024 | 1.6 KiB | 80 | 57 | |
http_signing.md | D | 12-May-2024 | 13.5 KiB | 364 | 254 | |
package.json | D | 12-May-2024 | 1.8 KiB | 78 | 77 |
README.md
1# node-http-signature 2 3node-http-signature is a node.js library that has client and server components 4for Joyent's [HTTP Signature Scheme](http_signing.md). 5 6## Usage 7 8Note the example below signs a request with the same key/cert used to start an 9HTTP server. This is almost certainly not what you actually want, but is just 10used to illustrate the API calls; you will need to provide your own key 11management in addition to this library. 12 13### Client 14 15```js 16var fs = require('fs'); 17var https = require('https'); 18var httpSignature = require('http-signature'); 19 20var key = fs.readFileSync('./key.pem', 'ascii'); 21 22var options = { 23 host: 'localhost', 24 port: 8443, 25 path: '/', 26 method: 'GET', 27 headers: {} 28}; 29 30// Adds a 'Date' header in, signs it, and adds the 31// 'Authorization' header in. 32var req = https.request(options, function(res) { 33 console.log(res.statusCode); 34}); 35 36 37httpSignature.sign(req, { 38 key: key, 39 keyId: './cert.pem' 40}); 41 42req.end(); 43``` 44 45### Server 46 47```js 48var fs = require('fs'); 49var https = require('https'); 50var httpSignature = require('http-signature'); 51 52var options = { 53 key: fs.readFileSync('./key.pem'), 54 cert: fs.readFileSync('./cert.pem') 55}; 56 57https.createServer(options, function (req, res) { 58 var rc = 200; 59 var parsed = httpSignature.parseRequest(req); 60 var pub = fs.readFileSync(parsed.keyId, 'ascii'); 61 if (!httpSignature.verifySignature(parsed, pub)) 62 rc = 401; 63 64 res.writeHead(rc); 65 res.end(); 66}).listen(8443); 67``` 68 69## Installation 70 71 npm install http-signature 72 73## License 74 75MIT. 76 77## Bugs 78 79See <https://github.com/joyent/node-http-signature/issues>. 80