Skip to content

Commit

Permalink
PR Update
Browse files Browse the repository at this point in the history
  • Loading branch information
dpbackes committed Jan 8, 2019
1 parent 1ef5739 commit ff1cc6f
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const jwks = require('jwks-rsa')
const jwt = require('jsonwebtoken')

const {
applyTo: thrush, curryN, dissoc, partialRight, prop, replace
applyTo: thrush, composeP, curryN, dissoc, partialRight, prop, replace
} = require('ramda')

const { promisify, rename, tapP } = require('@articulate/funky')
Expand All @@ -27,7 +27,7 @@ const chooseKey = key =>
const decode = partialRight(jwt.decode, [{ complete: true }])

const enforce = token =>
token || Promise.reject(new Error('null token not allowed'))
token || Promise.reject(Boom.unauthorized('null token not allowed'))

const stripBearer =
replace(/^Bearer /i, '')
Expand Down Expand Up @@ -62,13 +62,9 @@ const factory = opts => {
.then(getSigningKey)
.then(chooseKey)
.then(verify(token))

return token =>
Promise.resolve(token)
.then(tapP(enforce))
.then(stripBearer)
.then(authentic)
.catch(unauthorized)

return composeP(authentic, stripBearer, tapP(enforce))
}

module.exports = factory

0 comments on commit ff1cc6f

Please sign in to comment.