3

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?

4
  • The client is an Ionic app
    – dariodip
    Commented May 8, 2016 at 12:55
  • LoopBack Example is using a cookie-parser package (see server/server.js). Cookies are signed but you have access to them via req.signedCookies. Commented May 9, 2016 at 6:36
  • Thank you @IvanSchwarz! I resolved using req.signedCookies
    – dariodip
    Commented May 18, 2016 at 9:55
  • You are welcome! I've added my comment in a form of an answer - in case you want to close this question by accepting an aswer. Commented May 18, 2016 at 10:39

1 Answer 1

1

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.