Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fastify/bearer-auth

Package Overview
Dependencies
Maintainers
0
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/bearer-auth - npm Package Compare versions

Comparing version 10.0.1 to 10.0.2

eslint.config.js

2

examples/example.js

@@ -9,3 +9,3 @@ 'use strict'

fastify.register(bearerAuthPlugin, { keys })
fastify.get('/foo', (req, reply) => {
fastify.get('/foo', (_req, reply) => {
reply.send({ authenticated: true })

@@ -12,0 +12,0 @@ })

@@ -11,3 +11,3 @@ 'use strict'

if (
Object.prototype.hasOwnProperty.call(fastify.log, 'error') === false ||
Object.hasOwn(fastify.log, 'error') === false ||
typeof fastify.log.error !== 'function'

@@ -22,3 +22,3 @@ ) {

typeof options.verifyErrorLogLevel !== 'string' ||
Object.prototype.hasOwnProperty.call(fastify.log, options.verifyErrorLogLevel) === false ||
Object.hasOwn(fastify.log, options.verifyErrorLogLevel) === false ||
typeof fastify.log[options.verifyErrorLogLevel] !== 'function'

@@ -25,0 +25,0 @@ )

{
"name": "@fastify/bearer-auth",
"version": "10.0.1",
"description": "An authentication plugin for Fastify",
"version": "10.0.2",
"description": "A Bearer authentication plugin for Fastify",
"main": "index.js",

@@ -9,4 +9,4 @@ "type": "commonjs",

"scripts": {
"lint": "standard",
"lint:fix": "standard --fix",
"lint": "eslint",
"lint:fix": "eslint --fix",
"test": "npm run test:unit && npm run test:typescript",

@@ -29,2 +29,21 @@ "test:typescript": "tsd",

"author": "James Sumners <james.sumners@gmail.com>",
"contributors": [
{
"name": "Matteo Collina",
"email": "hello@matteocollina.com"
},
{
"name": "Manuel Spigolon",
"email": "behemoth89@gmail.com"
},
{
"name": "Aras Abbasi",
"email": "aras.abbasi@gmail.com"
},
{
"name": "Frazer Smith",
"email": "frazer.dev@icloud.com",
"url": "https://github.com/fdawgs"
}
],
"license": "MIT",

@@ -35,2 +54,12 @@ "bugs": {

"homepage": "https://github.com/fastify/fastify-bearer-auth#readme",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/fastify"
},
{
"type": "opencollective",
"url": "https://opencollective.com/fastify"
}
],
"devDependencies": {

@@ -41,4 +70,5 @@ "@fastify/auth": "^5.0.0",

"c8": "^10.1.2",
"eslint": "^9.17.0",
"fastify": "^5.0.0",
"standard": "^17.1.0",
"neostandard": "^0.12.0",
"tsd": "^0.31.0"

@@ -45,0 +75,0 @@ },

# @fastify/bearer-auth
![CI](https://github.com/fastify/fastify-bearer-auth/workflows/CI/badge.svg)
[![CI](https://github.com/fastify/fastify-bearer-auth/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fastify-bearer-auth/actions/workflows/ci.yml)
[![npm version](https://img.shields.io/npm/v/@fastify/bearer-auth)](https://www.npmjs.com/package/@fastify/bearer-auth)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)
*@fastify/bearer-auth* provides a simple request hook for the [Fastify][fastify]
*@fastify/bearer-auth* provides a simple Bearer auth request hook for the [Fastify][fastify]
web framework.

@@ -12,2 +12,22 @@

## Install
```
npm i @fastify/bearer-auth
```
### Compatibility
| Plugin version | Fastify version |
| ---------------|-----------------|
| `^10.x` | `^5.x` |
| `^8.x` | `^4.x` |
| `^5.x` | `^3.x` |
| `^4.x` | `^2.x` |
| `^1.x` | `^1.x` |
Please note that if a Fastify version is out of support, then so are the corresponding versions of this plugin
in the table above.
See [Fastify's LTS policy](https://github.com/fastify/fastify/blob/main/docs/Reference/LTS.md) for more details.
## Example

@@ -40,3 +60,3 @@

you to register the plugin within scoped paths. Therefore, you could have some
paths that are not protected by the plugin and others that are. See the [Fastify](https://fastify.dev/docs/latest)
paths not protected by the plugin and others that are. See the [Fastify](https://fastify.dev/docs/latest)
documentation and examples for more details.

@@ -63,10 +83,10 @@

one of these values. If the function returns or resolves to any other value,
rejects, or throws, a HTTP status of `500` will be sent. `req` is the Fastify
rejects, or throws, an HTTP status of `500` will be sent. `req` is the Fastify
request object. If `auth` is a function, `keys` will be ignored. If `auth` is
not a function, or `undefined`, `keys` will be used.
* `addHook`: If `false`, this plugin will not register `onRequest` hook automatically,
instead it provide two decorations `fastify.verifyBearerAuth` and
instead it provides two decorations `fastify.verifyBearerAuth` and
`fastify.verifyBearerAuthFactory` for you.
* `verifyErrorLogLevel`: An optional string specifying the log level when there is a verification error.
It must be a valid log level supported by fastify, otherwise an exception will be thrown
It must be a valid log level supported by fastify, otherwise, an exception will be thrown
when registering the plugin. By default, this option is set to `error`.

@@ -97,4 +117,4 @@

[fplugin]: https://github.com/fastify/fastify/blob/master/docs/Plugins.md
[prehook]: https://github.com/fastify/fastify/blob/master/docs/Hooks.md
[fplugin]: https://github.com/fastify/fastify/blob/main/docs/Reference/Plugins.md
[prehook]: https://github.com/fastify/fastify/blob/main/docs/Reference/Hooks.md

@@ -146,4 +166,5 @@ ## Integration with `@fastify/auth`

If `verifyBearerAuth` is the last hook in the list, `fastify.auth` will reply with `Unauthorized`.
## License
[MIT License](https://jsumners.mit-license.org/)
Licensed under [MIT](./LICENSE).

@@ -13,3 +13,3 @@ 'use strict'

const destination = new stream.Writable({
write: function (chunk, encoding, next) {
write: function (chunk, _encoding, next) {
logs.push(JSON.parse(chunk))

@@ -27,3 +27,3 @@ next()

]
}, async (request, reply) => {
}, async (_request, _reply) => {
return { message: 'ok' }

@@ -30,0 +30,0 @@ })

@@ -9,3 +9,3 @@ 'use strict'

fastify.get('/test', (req, res) => {
fastify.get('/test', (_req, res) => {
res.send({ hello: 'world' })

@@ -60,3 +60,3 @@ })

test('integration with @fastify/auth', async (t) => {
test('integration with @fastify/auth', async () => {
const fastify = require('fastify')()

@@ -120,6 +120,6 @@ await fastify.register(plugin, { addHook: false, keys: new Set(['123456']) })

test('integration with @fastify/auth; not the last auth option', async (t) => {
test('integration with @fastify/auth; not the last auth option', async () => {
const fastify = require('fastify')()
await fastify.register(plugin, { addHook: false, keys: new Set(['123456']) })
fastify.decorate('alwaysValidAuth', function (request, _, done) {
fastify.decorate('alwaysValidAuth', function (_request, _, done) {
return done()

@@ -126,0 +126,0 @@ })

@@ -9,3 +9,3 @@ 'use strict'

fastify.get('/test', (req, res) => {
fastify.get('/test', (_req, res) => {
res.send({ hello: 'world' })

@@ -12,0 +12,0 @@ })

@@ -9,3 +9,3 @@ 'use strict'

fastify.get('/test', (req, res) => {
fastify.get('/test', (_req, res) => {
res.send({ hello: 'world' })

@@ -12,0 +12,0 @@ })

@@ -285,3 +285,3 @@ 'use strict'

function send (body) {
function send (_body) {
t.assert.ifError('should not happen')

@@ -313,3 +313,3 @@ }

function send (body) {
function send (_body) {
t.assert.ifError('should not happen')

@@ -316,0 +316,0 @@ }

@@ -35,3 +35,3 @@ import {

declare function fastifyBearerAuth(...params: Parameters<FastifyBearerAuth>): ReturnType<FastifyBearerAuth>
declare function fastifyBearerAuth (...params: Parameters<FastifyBearerAuth>): ReturnType<FastifyBearerAuth>
export = fastifyBearerAuth
import fastify, { FastifyRequest } from 'fastify'
import { expectAssignable, expectType } from 'tsd'
import { default as bearerAuth, FastifyBearerAuthOptions, verifyBearerAuth, verifyBearerAuthFactory } from '..'
import bearerAuth, { FastifyBearerAuthOptions, verifyBearerAuth, verifyBearerAuthFactory } from '..'
const pluginOptions: FastifyBearerAuthOptions = {
keys: new Set(['foo']),
auth: (key: string, req: FastifyRequest) => { return true },
auth: (_key: string, _req: FastifyRequest) => { return true },
errorResponse: (err: Error) => { return { error: err.message } },

@@ -16,3 +16,3 @@ contentType: '',

keys: new Set(['foo']),
auth: (key: string, req: FastifyRequest) => { return Promise.resolve(true) },
auth: (_key: string, _req: FastifyRequest) => { return Promise.resolve(true) },
errorResponse: (err: Error) => { return { error: err.message } },

@@ -25,3 +25,3 @@ contentType: '',

keys: ['foo'],
auth: (key: string, req: FastifyRequest) => { return Promise.resolve(true) },
auth: (_key: string, _req: FastifyRequest) => { return Promise.resolve(true) },
errorResponse: (err: Error) => { return { error: err.message } },

@@ -46,2 +46,11 @@ contentType: '',

bearerType?: string;
addHook?: boolean;
}>(pluginOptionsKeyArray)
expectAssignable<{
keys: Set<string> | string[];
auth?: (key: string, req: FastifyRequest) => boolean | Promise<boolean>;
errorResponse?: (err: Error) => { error: string };
contentType?: string;
bearerType?: string;
}>(pluginOptionsAuthPromise)

@@ -56,3 +65,3 @@

specCompliance?: 'rfc6749' | 'rfc6750';
verifyErrorLogLevel? : string;
verifyErrorLogLevel?: string;
}>(pluginOptionsAuthPromise)

@@ -62,4 +71,5 @@

fastify().register(bearerAuth, pluginOptionsAuthPromise)
fastify().register(bearerAuth, pluginOptionsKeyArray)
expectType<verifyBearerAuth | undefined>(fastify().verifyBearerAuth)
expectType<verifyBearerAuthFactory | undefined>(fastify().verifyBearerAuthFactory)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc