New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Email #15
Comments
Password is not yet available in the profile response received. Existing issue with passport-github: jaredhanson/passport-github#15
http://developer.github.com/v3/users/emails/ is a good source of real emails |
To add, the email that is currently fetched is the one that displays on a users profile page, which doesn't have to exist. Using the /emails endpoint should always have something defined. |
I run exactly into the same problem. If you request the profile: https://developer.github.com/v3/users/#get-a-single-user (this is what |
@createproblem you mean that passport-github should be patched to get email? How did you solve the problem? |
@iliakan No, in my eyes this is not an issue what |
Author of Passport-Github do not maintain module for a long time, and features(e.g., email issue) in this module doesn't work since Github upgrades their API to version 3.0, so that we fork its project and re-publish it to NPM with a new name Here is the git repo of the new module: |
Actually, not a problem for me. I implemented everything, works well. In open source btw. |
👍 |
The code is like: module.exports = new GithubStrategy({
clientID: config.authProviders.github.appId,
clientSecret: config.authProviders.github.appSecret,
callbackURL: config.server.siteHost + "/auth/callback/github",
passReqToCallback: true
},
function(req, accessToken, refreshToken, profile, done) {
// this may be a default avatar, or a real user pic, can't be sure
/* jshint -W106 */
profile.photos = [
{
value: profile._json.avatar_url
}
];
var options = {
headers: {
'User-Agent': 'JavaScript.ru',
'Authorization': 'token ' + accessToken
},
json: true,
url: 'https://api.github.com/user/emails'
};
// get emails using oauth token
request(options, function(error, response, body) {
if (error || response.statusCode != 200) {
req.log.error(error, body);
done(null, false, {message: "Ошибка связи с сервером github."});
return;
}
// [ { email: 'iliakan@gmail.com', primary: true, verified: true } ],
var emails = body.filter(function(email) {
return email.verified;
});
if (!emails.length) {
return done(null, false, {message: "Почта на github должна быть подтверждена."});
}
profile.emails = [
{value: emails[0].email }
];
authenticateByProfile(req, profile, done);
});
}
); |
Thanks iliakan, I was having the same problem (email: null) I used your code to get the email address successfully. |
For those who see this in the future, the latest way to accomplish this is: new GitHubStrategy(
{
clientID: ...,
clientSecret: ...,
callbackURL: ...,
scope: 'user:email',
},
...
); An extra API call will automatically be made to fetch the email. Would be great if the documentation could be updated. |
@sunjay it still doesnt work for me... |
I have tried |
@gapsong @oliviertassinari It was not working, because at Using this for
which would be returning
depending upon the emails attached to their profile. Alternatively, you can |
@sunjay thank you man, it really helps 👍 |
You are a life saver, @sunjay ... much thanks! |
Thank you @sunjay! Saved me a lot of headaches. |
To anyone reading this - don't waste your time - just use Ref: https://github.com/jaredhanson/passport-github/blob/master/lib/strategy.js#L159-L169 vs. https://github.com/cfsghost/passport-github/blob/master/lib/strategy.js#L145-L150 |
For me passport-github is working much better thatn |
@itswadesh please back up your statement with information as how it is working much better? |
|
You just need to set scopes to get that information. This is not related to the package as far as I know. TypeScript is completely outside the scope of the package, and not many authors I know on npm support it. Furthermore I highly recommend you do not use it, as it is bad for open-source and it is unnecessary convolution. Look at all the time wasted trying to get TypeScript working.. |
@niftylettuce I tried without success |
@itswadesh see https://github.com/ladjs/passport/blob/master/index.js for working implementation. This is used on https://forwardemail.net and https://lad.sh with success. |
@sunjay Thanks a ton! 👍🏻 |
I get this:
emails: [ { value: undefined } ],
in response... so is it valid? because I need email info...
this is request:
app.get('/auth/github', passport.authenticate('github', { scope : "user:email"}));
and this is callback:
app.get('/auth/github/callback', passport.authenticate('github', { failureRedirect: '/login' }), function (req, res) { res.redirect('/'); });
The text was updated successfully, but these errors were encountered: