![neverstew avatar](https://secure.gravatar.com/avatar/109fa713caf4e083c57622b7c6dad365.jpg?s=200&d=identicon)
neverstew
safeAssertBearerToken
Script
safeAssertBearerToken A safe version of assertBearerToken that handles errors and presents them as a property on the returned object instead. Example const handler = (req, res) => {
const authorization = req.get('authorization');
const { error, data: token } = @neverstew.safeAssertBearerToken(@me.secrets.superSecret, authorization);
if (error) {
res.status(401).send("Unauthorized");
return;
}
res.json(token);
}
0
![neverstew avatar](https://secure.gravatar.com/avatar/109fa713caf4e083c57622b7c6dad365.jpg?s=200&d=identicon)
neverstew
assertBearerToken
Script
assertBearerToken This val can be used to assert that a valid bearer token exists and has been signed by the secret provided. Example const handler = (req, res) => {
const authorization = req.get('authorization');
// throws if invalid
const token = @neverstew.assertBearerToken(@me.secrets.superSecret, authorization);
res.json(token);
}
0
Updated: October 23, 2023