Loopback-Component-Passport link account not working

447 views
Skip to first unread message

Michael Lee

unread,
Jul 13, 2014, 4:57:17 PM7/13/14
to loopb...@googlegroups.com
Hi,

To my understanding, social account linking is for the scenario when you already have a LoopBack user account created with email and password, and then you want to link your Facebook account with your LoopBack account under the same email address. 

I created the LoopBack user, logged in, and then tried '/link/facebook'. Upon successful Facebook login, I got the profile returned. However, the 'req.user' is undefined, and I got done('No user is logged in') at line 297 of passport-configurator.js. Any idea why the 'user' is not there?

loopback-component-passport/lib/passport-configurator.js:
292          if (link) {
293            if (req.user) {
294              self.userCredentialModel.link(req.user.id, name, authScheme, profile,
295                {accessToken: accessToken, refreshToken: refreshToken}, options, done);
296            } else {
297              done('No user is logged in');
298            }
299          } else {


Thanks,
Michael

Raymond Feng

unread,
Jul 16, 2014, 1:26:14 AM7/16/14
to Michael Lee, loopb...@googlegroups.com
Did you try https://github.com/strongloop/loopback-example-passport?

Thanks,

---
Raymond Feng
Co-Founder and Architect @ StrongLoop, Inc.

StrongLoop makes it easy to develop APIs in Node, plus get DevOps capabilities like monitoring, debugging and clustering.

--
You received this message because you are subscribed to the Google Groups "LoopbackJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to loopbackjs+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Lee

unread,
Jul 19, 2014, 2:09:41 AM7/19/14
to loopb...@googlegroups.com, topf...@gmail.com
Raymond,

I can reproduce it with loopback-example-passport. It gives the exact same problem.

First, I create a LoopBack user:
curl -X POST -H "Content-Type:application/json" -d '{"email": "some...@gmail.com", "password": "somepass"}' http://localhost:3000/api/users

and sign in with a Facebook account under the email "some...@gmail.com"

Then it goes to
done('No user is logged in'); and redirects to "failureRedirect".


Thanks,
Michael

Jens Winter

unread,
Oct 22, 2015, 5:16:16 AM10/22/15
to LoopbackJS, topf...@gmail.com


Hello there,

is there a solution for this problem? I'm also running into this issue.

Thanks!

Best regards,
Jens

Ahmed Abdul Moniem

unread,
Aug 24, 2016, 3:56:31 AM8/24/16
to LoopbackJS
Guys the same problem for me until now!

Any solution?

Alex Megalokonomos

unread,
Aug 24, 2016, 4:33:46 AM8/24/16
to loopb...@googlegroups.com
Hi everyone,

I haven't actually tested to see if there is indeed a bug but the discussion leads me to believe that you're forgetting a crucial step (the way I understand it)

You HAVE to be logged in to the local account for linking to work. The email is irrelevant.. LB does not link accounts based on email but based on the fact that it's the same person/token that has access to both accounts

i.e. create a LOCAL user with so...@email.com
local log in as that user 
go to /link/facebook with the access token set as a logged in local user and log in with FB

that way the local and FB accounts are linked even if the fb account has a different email....it's completely irrelevant

The code above is clear as day with regards to the fact:

if (link)  { //if this is a linking log in request
   if (req.user) { // and this user is logged in already with some account X
       self.userCredentialModel.link(req.user.id, name, authScheme, profile, {accessToken: accessToken, refreshToken: refreshToken}, options, done);  //link the logged in user with the profile of the new login 
    } else {
       done('No user is logged in'); //no user is already logged in, so there is nothing to link with....it does NOT search by email
}


--
You received this message because you are subscribed to the Google Groups "LoopbackJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to loopbackjs+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/loopbackjs/04648d2d-3dbb-4dbc-aa26-999524f8c7dc%40googlegroups.com.

Ahmed Abdul Moniem

unread,
Aug 24, 2016, 12:04:43 PM8/24/16
to LoopbackJS
I don't understand the Local account?

Already I have a model inherit from User and I created a new user in this new model

I have a collection (in mongo) contains this user and I can log in using the login end point using email/pass of this user

I am logged in in my application and trying to call this link/facebook and always req.user is undefined!
To unsubscribe from this group and stop receiving emails from it, send an email to loopbackjs+...@googlegroups.com.

Alex Megalokonomos

unread,
Aug 24, 2016, 3:06:32 PM8/24/16
to loopb...@googlegroups.com
Are you sure you're sending the access token with the request?



To unsubscribe from this group and stop receiving emails from it, send an email to loopbackjs+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/loopbackjs/2e0f73bd-2173-4c30-9d5e-7b8c6c55e230%40googlegroups.com.

Ahmed Abdul Moniem

unread,
Aug 24, 2016, 4:21:34 PM8/24/16
to LoopbackJS

Ahmed Abdul Moniem

unread,
Aug 25, 2016, 12:55:12 AM8/25/16
to LoopbackJS
Any clue?

Danny Colceag

unread,
Oct 31, 2016, 6:37:35 AM10/31/16
to LoopbackJS
Any updates on this issue? 

Do you know if we can hook into loopback-component-passport events or operations to augment them with additional functionality?

Thanks!

Regev Brody

unread,
May 8, 2017, 3:30:55 PM5/8/17
to loopb...@googlegroups.com
Also looking for a solution
Reply all
Reply to author
Forward
0 new messages