Header Picks The Key
This middleware guards a resource server. The authorization server signs with RS256 and publishes the matching public key at a JWKS endpoint that anyone can fetch. The service has been on the same pinned dependency since 2021.
// package.json: "jsonwebtoken": "8.5.1"
import jwt from 'jsonwebtoken'
import fs from 'node:fs'
const RSA_PUBLIC = fs.readFileSync('/etc/keys/auth-public.pem')
export function verify(token) {
const header = JSON.parse(
Buffer.from(token.split('.')[0], 'base64url').toString()
)
return jwt.verify(token, RSA_PUBLIC, { algorithms: [header.alg] })
}
What can someone who holds only the published public key do here?
Sign in to answer questions and track your progress
Sign In