Skip to content

Update tap #275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ on:
jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x, 22.x]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- run: npm ci
- run: npm run lint
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ dist

# TernJS port file
.tern-port

# tap
.tap
3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

module.exports = require('neostandard')({})
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async function fastifyUser (app, options) {
const {
webhook,
jwt,
authStrategies
authStrategies,
} = options

const strategies = []
Expand All @@ -21,15 +21,15 @@ async function fastifyUser (app, options) {
await app.register(require('./lib/jwt'), { jwt })
strategies.push({
name: 'jwt',
createSession: (req) => req.createJWTSession()
createSession: (req) => req.createJWTSession(),
})
}

if (webhook) {
await app.register(require('./lib/webhook'), { webhook })
strategies.push({
name: 'webhook',
createSession: (req) => req.createWebhookSession()
createSession: (req) => req.createWebhookSession(),
})
}

Expand Down Expand Up @@ -80,7 +80,7 @@ async function fastifyUser (app, options) {

module.exports = fp(fastifyUser, {
fastify: '4.x',
name: 'fastify-user'
name: 'fastify-user',
})

module.exports.default = fastifyUser
Expand Down
15 changes: 11 additions & 4 deletions lib/jwt.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const buildGetJwks = require('get-jwks')

module.exports = fp(async function (app, pluginOpts) {
const {
jwt: opts
jwt: opts,
} = pluginOpts

const namespace = opts?.namespace
Expand All @@ -29,18 +29,25 @@ module.exports = fp(async function (app, pluginOpts) {
: user => user

if (opts.jwks) {
const getJwks = buildGetJwks(typeof opts.jwks === 'object' ? opts.jwks : {})
let jwks = opts.jwks
if (typeof jwks === 'boolean') {
jwks = {}
} else if (jwks.allowedDomains) {
jwks.issuersWhitelist = jwks.allowedDomains
delete jwks.allowedDomains
}
const getJwks = buildGetJwks(jwks)
app.register(jwt, {
formatUser,
...opts,
decode: { complete: true },
secret: function (request, token) {
const {
header: { kid, alg },
payload: { iss }
payload: { iss },
} = token
return getJwks.getPublicKey({ kid, domain: iss, alg })
}
},
})
} else {
app.register(jwt, { formatUser, ...opts })
Expand Down
6 changes: 3 additions & 3 deletions lib/webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const createError = require('@fastify/error')
const notAllowed = new Set([
'content-length',
'host',
'connection'
'connection',
])

module.exports = fp(async function (app, pluginOpts) {
Expand All @@ -28,9 +28,9 @@ module.exports = fp(async function (app, pluginOpts) {
method: 'POST',
headers: {
...headers,
'accept-encoding': 'identity'
'accept-encoding': 'identity',
},
body
body,
})

if (res.statusCode > 299) {
Expand Down
Loading
Loading