jwt-secret
Version:
Bruteforce a JWT against a list of passwords
25 lines (19 loc) • 525 B
JavaScript
const jws = require('jws')
const jwa = require('jwa')
const through = require('through2')
module.exports = token => {
const decoded = jws.decode(token)
if (!decoded) {
throw new Error('Invalid token')
}
const content = token.replace(/\.[^.]+$/, '')
const sign = jwa(decoded.header.alg).sign
return through(function (chunk, encoding, callback) {
const signature = sign(content, chunk)
if (signature === decoded.signature) {
this.push(chunk)
this.push(null)
}
callback()
})
}