I've written many many Node.js applications, and whenever I add Github as the auth process, I find that even though I'm asking for scope:email there's often a number of users that end up without an email address.

This happens when the github user doesn't have a public email address. But…we just completed a full auth and this isn't a public profile we're after, so surely we should have the email? The answer is no, but here's how to fix that.

After

Inside the auth callback, I'll check if I actually have an email address, and if not, I'll immediately make a https://api.github.com/user/emails call (with the newly captured access token) which now includes private email addresses so I can properly use this as a unique identifier in my application.

And that's it, it'll ensure that you'll get an email address which is what I tend to use as the unique identifier for users.

Follow up

Of course whilst writing this post, I decided to check out the source code to passport-github and discovered by sifting through the source that there's a helper function called .userProfile which does exactly this. Oddly though, it's not documented (which I may send a PR for).