Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/TritonDataCenter/node-http-signature
Reference implementation of Joyent's HTTP Signature Scheme
https://github.com/TritonDataCenter/node-http-signature
Last synced: 3 months ago
JSON representation
Reference implementation of Joyent's HTTP Signature Scheme
- Host: GitHub
- URL: https://github.com/TritonDataCenter/node-http-signature
- Owner: TritonDataCenter
- License: mit
- Created: 2011-07-14T17:58:00.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2023-11-16T18:34:24.000Z (about 1 year ago)
- Last Synced: 2024-11-13T00:00:17.004Z (3 months ago)
- Language: JavaScript
- Homepage: https://tritondatacenter.com
- Size: 205 KB
- Stars: 404
- Watchers: 59
- Forks: 118
- Open Issues: 34
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
- awesome-npm - http-signature - Reference implementation of Joyent's HTTP Signature Scheme (1. 后端开发 / 1.1 HTTP)
README
# node-http-signature
node-http-signature is a node.js library that has client and server components
for Joyent's [HTTP Signature Scheme](http_signing.md).## Usage
Note the example below signs a request with the same key/cert used to start an
HTTP server. This is almost certainly not what you actually want, but is just
used to illustrate the API calls; you will need to provide your own key
management in addition to this library.### Client
```js
var fs = require('fs');
var https = require('https');
var httpSignature = require('http-signature');var key = fs.readFileSync('./key.pem', 'ascii');
var options = {
host: 'localhost',
port: 8443,
path: '/',
method: 'GET',
headers: {}
};// Adds a 'Date' header in, signs it, and adds the
// 'Authorization' header in.
var req = https.request(options, function(res) {
console.log(res.statusCode);
});httpSignature.sign(req, {
key: key,
keyId: './cert.pem',
keyPassphrase: 'secret' // (optional)
});req.end();
```### Server
```js
var fs = require('fs');
var https = require('https');
var httpSignature = require('http-signature');var options = {
key: fs.readFileSync('./key.pem'),
cert: fs.readFileSync('./cert.pem')
};https.createServer(options, function (req, res) {
var rc = 200;
var parsed = httpSignature.parseRequest(req);
var pub = fs.readFileSync(parsed.keyId, 'ascii');
if (!httpSignature.verifySignature(parsed, pub))
rc = 401;res.writeHead(rc);
res.end();
}).listen(8443);
```## Installation
npm install http-signature
## License
MIT.
## Bugs
See .