# buzzard

> Buzzard Protocol implementation

Latest version **0.1.3** (published 2014-02-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install buzzard
pnpm add buzzard
yarn add buzzard
bun add buzzard
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2014-02-11 |
| First published | 2013-12-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | pgte |
| Maintainers | pgte |

## Links

- npm: https://www.npmjs.com/package/buzzard
- Repository: https://github.com/pgte/node-buzzard
- Issues: https://github.com/pgte/node-buzzard/issues
- npm.io page: https://npm.io/package/buzzard

## Dependencies (2)

- [boom](https://npm.io/package/boom.md) ~1.2.1
- [xtend](https://npm.io/package/xtend.md) ~2.1.1

## Recent versions

- 0.1.3 (latest) — 2014-02-11
- 0.1.2 — 2014-01-24
- 0.1.1 — 2013-12-18
- 0.1.0 — 2013-12-18
- 0.0.3 — 2013-12-17
- 0.0.2 — 2013-12-17
- 0.0.1 — 2013-12-17

## README

# Buzzard

[![Build Status](https://travis-ci.org/pgte/node-buzzard.png?branch=master)](https://travis-ci.org/pgte/node-buzzard)

Authentication protocol for HTTPS services.

## Features

Uses an `Authorization` header containing, `nonce`, timestamp and authentication code, produced by the client.

Also supports URL-based authentication.

The client holds a secret key that it uses to craft the authentication code from the nonce and the timestamp.

The server gets the nonce so that it can validate if the nonce is repeated.

Supports browserify.


## JS Client

### Node.js

In Node.js you can get a reference to the Buzzard client library like this:

```javascript
var Client = require('buzzard').client;
```

### Browser

On the browser, using browserify you can get a reference to the client library simply like this: (the server part of buzzard is not included for a smaller bundle size)

```javascript
var Client = require('buzzard');
```

### Client.header

Creates a header given a credential:

```javascript
var Client = require('buzzard').client;

var credentials = {
  id: 'iiiidddd',
  key: 'kkkeeeyyy',
  algorithm: 'sha1'
};

var header = Client.header(credentials);

// use request, jquery or whatvs, just be sure to send the HTTP header:

'Authorization': header
```

### Client.url

Creates a URL given a base URL and a credential:

```javascript
var Client = require('buzzard').client;

var credentials = {
  id: 'iiiidddd',
  key: 'kkkeeeyyy',
  algorithm: 'sha1'
};

var baseURL = 'http://cats.cat/purr?a=1'
var url = Client.url(baseURL, credentials);
```

## Server

### Construct the server validator

Construct a server validator by providing a function that fetches the credentials given a credential id;

```javascript
var Buzzard = require('buzzard').server;
var buzzard = Buzzard(getCredentials);

// stupid example

var credentials = {

  'user1': {
    id: 'user1',
    key: 'kkkeeeyyy1',
    algorithm: 'sha1'
  },

  'user2': {
    id: 'user2',
    key: 'kkkeeeyyy2',
    algorithm: 'sha1'
  }
}

/// cb is error-first
function getCredentials(id, cb) {
  cb(null, credentials[id]);
};

```

### Server.authenticate

Authenticates a request object, either using authorization header or URL.

```javascript
server.on('request', authenticate);

function authenticate(req) {
  buzzard.authenticate(req, authenticated);

  function authenticated(err, credentials, attributes) {
    if (err) {
      res.statusCode = err.response.code;
      res.end(err.message);
    } else {
      console.log('user id %s used nonce %s', credentials.id, attributes.nonce);

      // validate nonce...

      res.end('You have access!!!');
    }
  }
}
```

## Middleware

Connect and Restify-compatible middleware:

```javascript
var BuzzardMiddleware = require('buzzard').server.middleware;
var buzzardMiddleware = BuzzardMiddleware(credentialsFunc);

app.use(buzzardMiddleware);
```

## License

MIT

---
_Source: https://npm.io/package/buzzard · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
