Express.js is one of the popular web application framework for Node.js. To implement Github authentication passport module seems to really flexible.
To start, register a new application on Github goto Account > Applications > Register new application. This will yield you a client id and client secret for your application which we will use later. While registering new appplication they will ask for a callback url, let it be http://localhost:3000/auth/callback.
After creating new express.js project install the passport and passport-github Strategy.
To configure, start with require passport and passport-github strategy into your application.
Github doen’t have a refreshToken so we don’t care about it. The object we passed to done() method will be received by serializeUser.
In order to maintain the users session, Passport will serialize and deserialize user instances to and from the session. we need to configure those methods as our needs.
The serializeUser will store the user id in the session and deserializeUser will get the user from our database and store it in req.user.
We need to configure the routes for auth callback and error.
The implementation of the routes are upto you.
// or if not you many need to create user.
Thats it, you successfully implemented the github authentication for you express.js app with passport. In this I just skipped the usage of models and store the data to make it short. Consider this as a steeping stone and if you have any issues on implementing this in a real app, lemme know via comments. I will try my best to address it.