Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loopbackjs social login with Facebook

I have a simple web service and I want to add social login with Facebook and Google using Loopbackjs.

I've already done parts of this editing the example found at this link: https://github.com/strongloop/loopback-example-passport and following the instructions at this one: https://docs.strongloop.com/display/public/LB/Third-party+login+using+Passport.
My problem now is that I need to retrieve user information after login, so that every following editing request on the User model can be direct to the owning User entity.

e.g. The User X want to access to my application:

  1. X request for "example_site_address/auth/facebook";
  2. X will redirect to "www.facebook.com/dialog/oauth?response_type=code&redirect_uri=example_site_address/auth/facebook/callback&scope=email&client_id=XXXXXXX";
  3. After his acceptation, he will redirect to "example_site_address/auth/facebook/callback&scope=email&client_id=XXXXXXX";
  4. Then he will again redirect to "example_site_address/success_fb", this link should give to the client the User entity with which he is logged in.

Using Google this problem is solved because I could retrieve AccessToken information from the cookies, find the User who's owning that, and then send back it to the client, so he can store the UserId and every a following request could be like on this User.
Using Facebook I'm not able to do this, because cookies concern login are encrypted.

I'm a really beginner on this kind of application, so it is possible that my strategy is wrong. Could you help me to do this?

like image 450
dariodip Avatar asked Feb 12 '26 09:02

dariodip


1 Answers

LoopBack Example is using a cookie-parser package (see server/server.js). Cookies are signed but you have an access to them via req.signedCookies property.

like image 113
Ivan Schwarz Avatar answered Feb 15 '26 21:02

Ivan Schwarz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!