Skip to content
Browse files

Use Auto-generated email

Using auto-generated email for 3rd party accounts & update version#
  • Loading branch information...
1 parent 399da70 commit 5a8d31478264a2a9fc235fd97ab8e7e5c566e8fa @loay loay committed
Showing with 13 additions and 35 deletions.
  1. +4 −22 README.md
  2. +1 −5 lib/models/user-identity.js
  3. +1 −1 package.json
  4. +7 −7 test/model.user-identity.test.js
View
26 README.md
@@ -2,7 +2,7 @@
**NOTE: This module supersedes [loopback-passport](https://www.npmjs.org/package/loopback-passport). Please update your package.json accordingly.**
-The module provides integration between [LoopBack](http://loopback.io) and
+The module provides integration between [LoopBack](http://loopback.io) and
[Passport](http://passportjs.org) to support third-party login and account
linking for LoopBack applications.
@@ -12,27 +12,9 @@ linking for LoopBack applications.
## All local accounts requires verification
-In order to let third party accounts to login with an email of `uniqueID@loopback.provider.com` example `123456@loopback.twitter.com`
+### All third party accounts will login with an email of `uniqueID@loopback.provider.com` example `123456@loopback.facebook.com`
-In `./lib/models/user-identity.js`, replace:
-
-```
-var email = profile.emails && profile.emails[0] && profile.emails[0].value;
-if (!email && !options.emailOptional) {
- // Fake an e-mail
- email = (profile.username || profile.id) + '@loopback.' +
- (profile.provider || provider) + '.com';
-}
-```
-
-with
-
-```
-var email = (profile.username || profile.id) + '@loopback.' +
- (profile.provider || provider) + '.com';
-```
-
-which will allow the user to link the social media accounts that they want as well as the users could sign up with the same email account that is used for facebook/twitter/google/local if they wish to keep them separate.
+which will allow the user to link the social media accounts that they want as well as the users could sign up with the same email account that is used for facebook/twitter/google/local if they wish to keep them separate.
If more info is required from the Facebook profile such as email, it could still be obtained. In `node_modules\passport-facebook\lib\strategy.js`, replace:
@@ -40,7 +22,7 @@ If more info is required from the Facebook profile such as email, it could still
this._profileURL = options.profileURL || 'https://graph.facebook.com/me';
```
-with
+with
```
this._profileURL = options.profileURL ||
View
6 lib/models/user-identity.js
@@ -44,12 +44,8 @@
function profileToUser(provider, profile, options) {
// Let's create a user for that
- var email = profile.emails && profile.emails[0] && profile.emails[0].value;
- if (!email && !options.emailOptional) {
- // Fake an e-mail
- email = (profile.username || profile.id) + '@loopback.' +
+ var email = (profile.username || profile.id) + '@loopback.' +
(profile.provider || provider) + '.com';
- }
var username = provider + '.' + (profile.username || profile.id);
var password = utils.generateKey('password');
var userObj = {
View
2 package.json
@@ -9,7 +9,7 @@
"security"
],
"homepage": "https://github.com/strongloop/loopback-component-passport",
- "version": "1.6.0",
+ "version": "2.0.0",
"engines": {
"node": ">=0.10.0"
},
View
14 test/model.user-identity.test.js
@@ -14,7 +14,7 @@ describe('UserIdentity', function () {
var ds = loopback.createDataSource({
connector: 'memory'
});
-
+
UserIdentity.attachTo(ds);
User.attachTo(ds);
UserIdentity.belongsTo(User);
@@ -30,7 +30,7 @@ describe('UserIdentity', function () {
function (err, user, identity, token) {
assert(!err, 'No error should be reported');
assert.equal(user.username, 'facebook.xyz');
- assert.equal(user.email, 'foo@bar.com');
+ assert.equal(user.email, 'xyz@loopback.facebook.com');
assert.equal(identity.externalId, 'f123');
assert.equal(identity.provider, 'facebook');
@@ -44,7 +44,7 @@ describe('UserIdentity', function () {
identity.user(function (err, user) {
assert(!err, 'No error should be reported');
assert.equal(user.username, 'facebook.xyz');
- assert.equal(user.email, 'foo@bar.com');
+ assert.equal(user.email, 'xyz@loopback.facebook.com');
done();
});
});
@@ -104,8 +104,8 @@ describe('UserIdentity', function () {
], id: 'f789', username: 'ttt'
}, {accessToken: 'at3', refreshToken: 'rt3'}, function (err, user, identity, token) {
assert(!err, 'No error should be reported');
- assert.equal(user.username, 'facebook.789');
- assert.equal(user.email, '789@facebook.com');
+ assert.equal(user.username, 'facebook.ttt');
+ assert.equal(user.email, 'ttt@loopback.facebook.com');
assert.equal(identity.externalId, 'f789');
assert.equal(identity.provider, 'facebook');
@@ -118,8 +118,8 @@ describe('UserIdentity', function () {
// Follow the belongsTo relation
identity.user(function (err, user) {
assert(!err, 'No error should be reported');
- assert.equal(user.username, 'facebook.789');
- assert.equal(user.email, '789@facebook.com');
+ assert.equal(user.username, 'facebook.ttt');
+ assert.equal(user.email, 'ttt@loopback.facebook.com');
done();
});
});

0 comments on commit 5a8d314

Please sign in to comment.
Something went wrong with that request. Please try again.