fix social auth scheme

closes #1734
This commit is contained in:
Berkeley Martinez
2015-08-12 20:09:15 -07:00
parent eb07cbfea6
commit 4b0a9bef0a
3 changed files with 53 additions and 55 deletions

View File

@ -132,52 +132,54 @@ export default function(UserIdent) {
if (!userIdent) {
debug('no user identity instance found');
return next();
}
userIdent.user(function(err, user) {
let userChanged = false;
if (err) { return next(err); }
if (!user) {
debug('no user attached to identity!');
return next();
}
userIdent.user(function(err, user) {
let userChanged = false;
if (err) { return next(err); }
if (!user) {
debug('no user attached to identity!');
return next();
}
const { profile, provider } = userIdent;
const picture = getFirstImageFromProfile(profile);
const { profile, provider } = userIdent;
const picture = getFirstImageFromProfile(profile);
debug('picture', picture, user.picture);
// check if picture was found
// check if user has no picture
// check if user has default picture
// set user.picture from oauth provider
if (
picture &&
(!user.picture || user.picture === defaultProfileImage)
) {
debug('setting user picture');
user.picture = picture;
userChanged = true;
}
debug('picture', picture, user.picture);
// check if picture was found
// check if user has no picture
// check if user has default picture
// set user.picture from oauth provider
if (
picture &&
(!user.picture || user.picture === defaultProfileImage)
) {
debug('setting user picture');
user.picture = picture;
userChanged = true;
}
if (!(/github/).test(provider)) {
user[getSocialProvider(provider)] = profile.username;
}
if (!(/github/).test(provider)) {
debug('setting social', provider, (/github/g).test(provider));
debug('profile username', profile.username);
user[provider] = profile.username;
}
// if user signed in with github refresh their info
if (/github/.test(provider)) {
debug("user isn't github cool or username from github is different");
setProfileFromGithub(user, profile, profile._json);
userChanged = true;
}
// if user signed in with github refresh their info
if (/github/.test(provider)) {
debug("user isn't github cool or username from github is different");
setProfileFromGithub(user, profile, profile._json);
userChanged = true;
}
if (userChanged) {
return user.save(function(err) {
if (err) { return next(err); }
next();
});
}
debug('exiting after user identity before save');
next();
if (userChanged) {
return user.save(function(err) {
if (err) { return next(err); }
next();
});
}
debug('exiting after user identity before save');
next();
});
});
}

View File

@ -72,25 +72,20 @@
"type": "string",
"default": ""
},
"linkedinProfile": {
"type": "string",
"default": ""
"linkedin": {
"type": "string"
},
"githubProfile": {
"type": "string",
"default": ""
"codepen": {
"type": "string"
},
"codepenProfile": {
"type": "string",
"default": ""
"twitter": {
"type": "string"
},
"twitterHandle": {
"type": "string",
"default": ""
"facebook": {
"type": "string"
},
"facebookProfile": {
"type": "string",
"default": ""
"google": {
"type": "string"
},
"completedBonfires": {
"type": [

View File

@ -11,6 +11,7 @@ var uuid = require('node-uuid'),
passportProviders = require('./passport-providers');
var setProfileFromGithub = require('./utils/auth').setProfileFromGithub;
var getSocialProvider = require('./utils/auth').getSocialProvider;
var generateKey =
require('loopback-component-passport/lib/models/utils').generateKey;
@ -67,7 +68,7 @@ var passportOptions = {
}
if (!(/github/).test(provider)) {
userObj[provider.split('-')[0]] = profile.username;
userObj[getSocialProvider(provider)] = profile.username;
}
if (/github/.test(provider)) {