fastify-basic-auth
Advanced tools
Comparing version 0.0.1 to 0.1.0
{ | ||
"name": "fastify-basic-auth", | ||
"version": "0.0.1", | ||
"description": "", | ||
"version": "0.1.0", | ||
"description": "Fastify basic auth plugin", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "standard && tap test.js" | ||
}, | ||
@@ -13,3 +13,9 @@ "repository": { | ||
}, | ||
"keywords": [], | ||
"keywords": [ | ||
"fastify", | ||
"basic", | ||
"auth", | ||
"authentication", | ||
"plugin" | ||
], | ||
"author": "Tomas Della Vedova - @delvedor (http://delved.org)", | ||
@@ -20,3 +26,14 @@ "license": "MIT", | ||
}, | ||
"homepage": "https://github.com/fastify/fastify-basic-auth#readme" | ||
"homepage": "https://github.com/fastify/fastify-basic-auth#readme", | ||
"devDependencies": { | ||
"fastify": "^1.5.0", | ||
"fastify-auth": "^0.2.0", | ||
"standard": "^11.0.1", | ||
"tap": "^12.0.1" | ||
}, | ||
"dependencies": { | ||
"basic-auth": "^2.0.0", | ||
"fast-json-stringify": "^1.5.3", | ||
"fastify-plugin": "^1.0.1" | ||
} | ||
} |
102
README.md
@@ -1,1 +0,101 @@ | ||
# fastify-basic-auth | ||
# fastify-basic-auth | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) | ||
[![Build Status](https://travis-ci.org/fastify/fastify-basic-auth.svg?branch=master)](https://travis-ci.org/fastify/fastify-basic-auth) | ||
A simple basic auth plugin for Fastify. | ||
## Install | ||
``` | ||
npm i fastify-basic-auth | ||
``` | ||
## Usage | ||
This plugin decorates the fastifyinstance with a `basicAuth` function, which you can use inside a `preHandler` hook, in a `beforeHander` or with [`fastify-auth`](https://github.com/fastify/fastify-auth). | ||
```js | ||
const fastify = require('fastify')() | ||
fastify.register(require('fastify-basic-auth'), { validate }) | ||
function validate (username, password, req, reply, done) { | ||
if (username === 'Tyrion' && password === 'wine') { | ||
done() | ||
} else { | ||
done(new Error('Winter is coming')) | ||
} | ||
} | ||
fastify.after(() => { | ||
fastify.addHook('preHandler', fastify.basicAuth) | ||
fastify.get('/', (req, reply) => { | ||
reply.send({ hello: 'world' }) | ||
}) | ||
}) | ||
``` | ||
Promises and *async/await* are supported as well! | ||
```js | ||
const fastify = require('fastify')() | ||
fastify.register(require('fastify-basic-auth'), { validate }) | ||
async function validate (username, password, req, reply) { | ||
if (username !== 'Tyrion' || password !== 'wine') { | ||
return new Error('Winter is coming') | ||
} | ||
} | ||
``` | ||
Use with `beforeHander`: | ||
```js | ||
const fastify = require('fastify')() | ||
fastify.register(require('fastify-basic-auth'), { validate, disableHook: true }) | ||
async function validate (username, password, req, reply) { | ||
if (username !== 'Tyrion' || password !== 'wine') { | ||
return new Error('Winter is coming') | ||
} | ||
} | ||
fastify.after(() => { | ||
fastify.route({ | ||
method: 'GET', | ||
url: '/', | ||
beforeHandler: fastify.basicAuth, | ||
handler: async (req, reply) => { | ||
return { hello: 'world' } | ||
} | ||
}) | ||
}) | ||
``` | ||
Use with [`fastify-auth`](https://github.com/fastify/fastify-auth): | ||
```js | ||
const fastify = require('fastify')() | ||
fastify.register(require('fastify-auth')) | ||
fastify.register(require('fastify-basic-auth'), { validate, disableHook: true }) | ||
async function validate (username, password, req, reply) { | ||
if (username !== 'Tyrion' || password !== 'wine') { | ||
return new Error('Winter is coming') | ||
} | ||
} | ||
fastify.after(() => { | ||
// use preHandler to authenticate all the routes | ||
fastify.addHook('preHandler', fastify.auth([fastify.basicAuth])) | ||
fastify.route({ | ||
method: 'GET', | ||
url: '/', | ||
// use beforeHanderto authenticatejust this one | ||
beforeHandler: fastify.auth([fastify.basicAuth]), | ||
handler: async (req, reply) => { | ||
return { hello: 'world' } | ||
} | ||
}) | ||
}) | ||
``` | ||
## License | ||
Licensed under [MIT](./LICENSE). |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
12186
6
304
1
102
3
4
+ Addedbasic-auth@^2.0.0
+ Addedfast-json-stringify@^1.5.3
+ Addedfastify-plugin@^1.0.1
+ Addedajv@6.12.6(transitive)
+ Addedbasic-auth@2.0.1(transitive)
+ Addeddeepmerge@4.3.1(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfast-json-stringify@1.21.0(transitive)
+ Addedfastify-plugin@1.6.1(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsemver@6.3.1(transitive)
+ Addedstring-similarity@4.0.4(transitive)
+ Addeduri-js@4.4.1(transitive)