Node.js use Passport with Bearer Strategy
I'm going to demonstrate how to use Bearer Strategy and jsonwebtoken in this post. The workflow is shown as below picture. The client need to login first and get the token from the server. Then the client request another API service while embedded the token in the http request header. The server verify the token and respond the result to the client. The jsonwebtoken can encode a little information into the token, like user id and username (those isn't sensitive data). The jsonwebtoken can decode back the information on server side. We do not use Session to store in this example because the token also acts as authentication check. Starting with the code using passport with LocalStrategy and custom callback(v1.2) , we first install the Bearer Strategy and token generator module. npm install passport-http-bearer ...