@fastify/basic-auth
Advanced tools
Comparing version 3.0.0 to 3.0.1
{ | ||
"name": "@fastify/basic-auth", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Fastify basic auth plugin", | ||
@@ -28,5 +28,5 @@ "main": "index.js", | ||
"devDependencies": { | ||
"@fastify/auth": "^2.0.0", | ||
"@types/node": "^17.0.0", | ||
"fastify": "^3.0.0", | ||
"fastify-auth": "^1.0.0", | ||
"standard": "^17.0.0", | ||
@@ -33,0 +33,0 @@ "tap": "^16.0.0", |
@@ -1,5 +0,5 @@ | ||
# fastify-basic-auth | ||
# @fastify/basic-auth | ||
![CI](https://github.com/fastify/fastify-basic-auth/workflows/CI/badge.svg?branch=master) | ||
[![NPM version](https://img.shields.io/npm/v/fastify-basic-auth.svg?style=flat)](https://www.npmjs.com/package/fastify-basic-auth) | ||
[![NPM version](https://img.shields.io/npm/v/@fastify/basic-auth.svg?style=flat)](https://www.npmjs.com/package/@fastify/basic-auth) | ||
[![Known Vulnerabilities](https://snyk.io/test/github/fastify/fastify-basic-auth/badge.svg)](https://snyk.io/test/github/fastify/fastify-basic-auth) | ||
@@ -12,6 +12,6 @@ [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/) | ||
``` | ||
npm i fastify-basic-auth | ||
npm i @fastify/basic-auth | ||
``` | ||
## Usage | ||
This plugin decorates the fastify instance with a `basicAuth` function, which you can use inside any hook before your route handler, or with [`fastify-auth`](https://github.com/fastify/fastify-auth). | ||
This plugin decorates the fastify instance with a `basicAuth` function, which you can use inside any hook before your route handler, or with [`@fastify/auth`](https://github.com/fastify/fastify-auth). | ||
@@ -21,3 +21,3 @@ ```js | ||
const authenticate = {realm: 'Westeros'} | ||
fastify.register(require('fastify-basic-auth'), { validate, authenticate }) | ||
fastify.register(require('@fastify/basic-auth'), { validate, authenticate }) | ||
// `this` inside validate is `fastify` | ||
@@ -45,3 +45,3 @@ function validate (username, password, req, reply, done) { | ||
const authenticate = {realm: 'Westeros'} | ||
fastify.register(require('fastify-basic-auth'), { validate, authenticate }) | ||
fastify.register(require('@fastify/basic-auth'), { validate, authenticate }) | ||
async function validate (username, password, req, reply) { | ||
@@ -58,3 +58,3 @@ if (username !== 'Tyrion' || password !== 'wine') { | ||
const authenticate = {realm: 'Westeros'} | ||
fastify.register(require('fastify-basic-auth'), { validate, authenticate }) | ||
fastify.register(require('@fastify/basic-auth'), { validate, authenticate }) | ||
async function validate (username, password, req, reply) { | ||
@@ -78,8 +78,8 @@ if (username !== 'Tyrion' || password !== 'wine') { | ||
Use with [`fastify-auth`](https://github.com/fastify/fastify-auth): | ||
Use with [`@fastify/auth`](https://github.com/fastify/fastify-auth): | ||
```js | ||
const fastify = require('fastify')() | ||
const authenticate = {realm: 'Westeros'} | ||
fastify.register(require('fastify-auth')) | ||
fastify.register(require('fastify-basic-auth'), { validate, authenticate }) | ||
fastify.register(require('@fastify/auth')) | ||
fastify.register(require('@fastify/basic-auth'), { validate, authenticate }) | ||
async function validate (username, password, req, reply) { | ||
@@ -109,6 +109,6 @@ if (username !== 'Tyrion' || password !== 'wine') { | ||
On failed authentication, *fastify-basic-auth* will call the Fastify | ||
On failed authentication, *@fastify/basic-auth* will call the Fastify | ||
[generic error | ||
handler](https://www.fastify.io/docs/latest/Server/#seterrorhandler) with an error. | ||
*fastify-basic-auth* sets the `err.statusCode` property to `401`. | ||
*@fastify/basic-auth* sets the `err.statusCode` property to `401`. | ||
@@ -153,3 +153,3 @@ In order to properly `401` errors: | ||
```js | ||
fastify.register(require('fastify-basic-auth'), { | ||
fastify.register(require('@fastify/basic-auth'), { | ||
validate, | ||
@@ -159,3 +159,3 @@ authenticate: true // WWW-Authenticate: Basic | ||
fastify.register(require('fastify-basic-auth'), { | ||
fastify.register(require('@fastify/basic-auth'), { | ||
validate, | ||
@@ -171,3 +171,3 @@ authenticate: false // no authenticate header, same as omitting authenticate option | ||
```js | ||
fastify.register(require('fastify-basic-auth'), { | ||
fastify.register(require('@fastify/basic-auth'), { | ||
validate, | ||
@@ -181,3 +181,3 @@ authenticate: {realm: 'example'} // WWW-Authenticate: Basic realm="example" | ||
```js | ||
fastify.register(require('fastify-basic-auth'), { | ||
fastify.register(require('@fastify/basic-auth'), { | ||
validate, | ||
@@ -198,3 +198,3 @@ authenticate: { | ||
```js | ||
fastify.register(require('fastify-basic-auth'), { | ||
fastify.register(require('@fastify/basic-auth'), { | ||
validate, | ||
@@ -201,0 +201,0 @@ header: 'x-forwarded-authorization' |
@@ -6,3 +6,3 @@ 'use strict' | ||
const basicAuth = require('./index') | ||
const fastifyAuth = require('fastify-auth') | ||
const fastifyAuth = require('@fastify/auth') | ||
const { Unauthorized } = require('http-errors') | ||
@@ -359,3 +359,3 @@ | ||
test('With fastify-auth - 401', t => { | ||
test('With @fastify/auth - 401', t => { | ||
t.plan(3) | ||
@@ -404,3 +404,3 @@ | ||
test('Hook with fastify-auth- 401', t => { | ||
test('Hook with @fastify/auth- 401', t => { | ||
t.plan(3) | ||
@@ -407,0 +407,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31628
3