This is the same dilemma I was dealing with. This is how I do it now. In my application, the client can directly or through another service, such as facebook, which is my main and, therefore, the one that I focus on.
Facebook can redirect through POST (desktop applications) or GET (mobile).
I check the original request to see if there is a service identifier - for example, facebook GET.
app.get('/', function(req, res) { var paraUrl = URL.parse(req.url,true).query; //The fb_source is shown - //i need to go striaght to the facebook authorization since //its coming from //from a mobile device. if (paraUrl.fb_source){ res.redirect('/auth/facebook'); //this is the passport part return; } res.sendfile('index.html'); }
On Facebook POST, it’s a little different that you get the access code for tokens in base64url. GET gives you a code that you can exchange for an access token, but I had problems with it, and I just chose the binding to the passport system.
If the client comes directly, I check the session or the encrypted cookie that is associated with the local strategy. Then it checks the db for the access token, which can be used, for example, to access the facebook api.
If the client is not recognized, it is given the opportunity to authenticate via facebook, google, etc.
The main thing is that only 2 pieces of information, the passport session identifier and the application user identifier are stored with the client
connect.sid - encypted cookie
userId - encypted cookie
I would be interested to know how other people face the problem.