Giter VIP home page Giter VIP logo

Comments (5)

cadesalaberry avatar cadesalaberry commented on September 28, 2024

To achieve what you want you should look at overriding the profileToUser(provider, profile) function.

The default one does the following:

function profileToUser(provider, profile, options) {
var password, userObj;
if (!options.profileMapping) {
// Let's create a user for that
var profileEmail =
profile.emails && profile.emails[0] && profile.emails[0].value;
var generatedEmail =
(profile.username || profile.id) +
'@loopback.' +
(profile.provider || provider) +
'.com';
var email = provider === 'ldap' ? profileEmail : generatedEmail;
var username = provider + '.' + (profile.username || profile.id);
password = utils.generateKey('password');
userObj = {
username: username,
password: password,
};
if (email) {
userObj.email = email;
}
return userObj;
} else {
password = utils.generateKey('password');
userObj = {
password: password,
};
// if profileMapping exists, map each provider field to the appropriate user field
options.profileMapping.forEach(function(field) {
userObj[field.userField] = stringToRef(profile, field.providerField);
});
}
return userObj;
}

If you replace it with a function that looks like this:

function profileToUser(provider, profile, options) {
  return {
    firstName: profile.name.givenName,
    lastName: profile.name.familyName,
    email: profile.email,
  }
}

The passport component will properly match the player with its email and not duplicate the account.

from loopback-component-passport.

 avatar commented on September 28, 2024

To achieve what you want you should look at overriding the profileToUser(provider, profile) function.

The default one does the following:
loopback-component-passport/lib/models/user-identity.js

Lines 58 to 92 in 74abd78

function profileToUser(provider, profile, options) {
var password, userObj;

if (!options.profileMapping) {
// Let's create a user for that
var profileEmail =
profile.emails && profile.emails[0] && profile.emails[0].value;
var generatedEmail =
(profile.username || profile.id) +
'@loopback.' +
(profile.provider || provider) +
'.com';
var email = provider === 'ldap' ? profileEmail : generatedEmail;
var username = provider + '.' + (profile.username || profile.id);
password = utils.generateKey('password');
userObj = {
username: username,
password: password,
};
if (email) {
userObj.email = email;
}
return userObj;
} else {
password = utils.generateKey('password');
userObj = {
password: password,
};
// if profileMapping exists, map each provider field to the appropriate user field
options.profileMapping.forEach(function(field) {
userObj[field.userField] = stringToRef(profile, field.providerField);
});
}
return userObj;
}
If you replace it with a function that looks like this:

function profileToUser(provider, profile, options) {
  return {
    firstName: profile.name.givenName,
    lastName: profile.name.familyName,
    email: profile.email,
  }
}

The passport component will properly match the player with its email and not duplicate the account.

this is not working fine, suggest something else to do this manually when new user registered.

from loopback-component-passport.

shubhddn01 avatar shubhddn01 commented on September 28, 2024

Looking for the solution... :(

from loopback-component-passport.

stale avatar stale commented on September 28, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from loopback-component-passport.

stale avatar stale commented on September 28, 2024

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

from loopback-component-passport.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.