Skip to content
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

Use reject to prevent errors from being swallowed #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
44 changes: 25 additions & 19 deletions auth/auth0/src/auth0Authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const fromEvent = require('graphcool-lib').fromEvent

//Validates the request JWT token
const verifyToken = token =>
new Promise(resolve => {
new Promise((resolve, reject) => {
//Decode the JWT Token
const decoded = jwt.decode(token, { complete: true })
if (!decoded || !decoded.header || !decoded.header.kid) {
Expand All @@ -22,23 +22,29 @@ const verifyToken = token =>
})
//Retrieve the JKWS's signing key using the decode token's key identifier (kid)
jkwsClient.getSigningKey(decoded.header.kid, (err, key) => {
if (err) throw new Error(err)
const signingKey = key.publicKey || key.rsaPublicKey
//If the JWT Token was valid, verify its validity against the JKWS's signing key
jwt.verify(
token,
signingKey,
{
algorithms: ['RS256'],
audience: process.env.AUTH0_API_IDENTIFIER,
ignoreExpiration: false,
issuer: `https://${process.env.AUTH0_DOMAIN}/`
},
(err, decoded) => {
if (err) throw new Error(err)
return resolve(decoded)
}
)
if (err) {
reject(new Error(err))
} else {
const signingKey = key.publicKey || key.rsaPublicKey
//If the JWT Token was valid, verify its validity against the JKWS's signing key
jwt.verify(
token,
signingKey,
{
algorithms: ['RS256'],
audience: process.env.AUTH0_API_IDENTIFIER,
ignoreExpiration: false,
issuer: `https://${process.env.AUTH0_DOMAIN}/`
},
(err, decoded) => {
if (err) {
reject(new Error(err))
} else {
return resolve(decoded)
}
}
)
}
})
})

Expand Down Expand Up @@ -118,4 +124,4 @@ export default async event => {
console.log(err)
return { error: 'An unexpected error occured' }
}
}
}