Auth0 Home Blog Docs

Token verification in aws lambda (or non express) node js application

jwt
auth0
login

#1

In all the node js examples given, to validate the access_token, we use the express-jwt middleware. But how do we validate the access token in case of applications that do not use express, like aws lambda.

// create timesheets API endpoint
app.post(’/timesheets/upload’, checkJwt, function(req, res){
var timesheet = req.body;

// Save the timesheet entry to the database…

//send the response
res.status(201).send(timesheet);
})

Above is how all examples use in express. But I have a handler in aws lambda like this:

handler: (event, context, callback) => {
// handling code here
// event.headers would contain the appropriate access token in appropriate header

}

So how do I validate the access token in such case? Are there any libraries that will help?


#2

Hi @rahulserver

You can use the jsonwebtoken and jwks-rsa npm packages to validate the token.

You get the token from the Authorization header and strip out the Bearer portion to give you just the JWT.

Hope this helps!