source: trip-planner-front/node_modules/http-signature/README.md@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.6 KB
Line 
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>.
Note: See TracBrowser for help on using the repository browser.