Closed collinforrester closed 10 years ago
I'll also mention that I've updated my model-config.json to try pulling in the node_modules models directory:
"_meta": {
"sources": [
"../common/models",
"./models",
"./node_modules/loopback-component-passport/lib/models"
]
}
But I'm guessing that doesn't matter since those models aren't defined in .json files like the 2.0 models are..
Well I've been able to get it to at least include the models without issue. The trick was to run
var loopbackPassport = require('loopback-component-passport');
var PassportConfigurator = loopbackPassport.PassportConfigurator;
var passportConfigurator = new PassportConfigurator(app);
before running the code in boot/
which makes sense now that I know what the problem was.
I'm still going to leave this open so I can find out what is causing a few other issues that I'm guessing is related to 1.x vs 2.0.
console.log(app.get('cookieSecret'));
prints out undefined even those I have cookieSecret
defined in server/config.json
I have my routes /auth/facebook
set up in the same fashion that this example has it set up. I am successfully redirected to facebook where I am asked to link the app, when I get redirected back the calls to ensureLoggedIn() always fails. Any idea why?
Edit: sorry for the bombard of comments on this one issue. I'm more or less just updating it as I tinker around with it some more.
I recently went through this as well in getting a 2.0 project to work with passport-3rd-party login/ensureloggedin - what error(s) are you seeing on the redirect back to your app?
Can you share your project somewhere so that I can do some troubleshooting?
I'm not seeing any errors, ensuredLoggedIn() will constantly return false. I'm guessing its something wrong with my model set up.
@raymondfeng Here is a copy of my project - https://github.com/collinforrester/loopback-passport-issue Took me a bit, just created a demo/sample facebook app to go along with it.
I just noticed I don't have any of the push related models added to my project. Would that make a difference?
The cookieSecret is set after boot(app, __dirname);
I debugged https://github.com/collinforrester/loopback-passport-issue and it seemed that Express 4.x somehow doesn't work with passport session. The other steps are working well. I still have to figure out what's going on.
No luck after following this answer either: http://stackoverflow.com/questions/23171249/express-4-0-and-passport-redirect-to-facebook-not-working
@raymondfeng We're going to be building a mobile app. We'd like to authenticate users into our mobile app with facebook but its not really RESTful at that point is it? Or are sessions typically the only way to go about 3rd party auth with REST APIs regardless.
I'm a little confused - when I run it and try to go to /auth/account it correctly recognizes that you're not logged in, and you have it immediately go to '/fail'. How is it supposed to be directed to try to talk to facebook? The original loopback/passport example has it redirect to a simple "login.html" page if you're not logged in, and that page includes the line (I stripped out html brackets)
a href="/auth/facebook" Login with Facebook
What happens when you type in the path /auth/facebook when you have it running? I don't have my facebook credentials handy atm.
Let me know if I'm missing something here.
This repo https://github.com/collinforrester/loopback-passport-issue is missing some configuration for the static HTML files and EJS views. I had to port them from 1.x locally. I can share what I have so far if @collinforrester can grant me the permission.
I'm having similar problems trying to integrate loopback-passport with Loopback 2.0. I've tried this example successfully (previous version), but obviously it's not running with loopback 2.0. It'd be great an update of the examples and documentation's examples.
My example I just didn't copy over the ejs files. To reproduce the error I go to /auth/facebook which the first time there it redirects to facebook and auths the account. The second time there it will always fail at ensureLoggedIn
and when it fails it redirects to /fail
. If it was ever successful it would output the user object in json.
@raymondfeng You should have permission by now. Not sure if github notified you or not when I gave it to you yesterday.
I've found that if I use passport-facebook directly, it works fine. Still trying to narrow down the differences between my implementation and what loopback-component-passport adds and where the break down is.
I don't see remoteMethod()
call for UserIdentity.Login()
, how do you access it remotely?
Not in the code I have posted. In another project I've dropped loopback-example-passport and the redirect back from Facebook works with all the session details intact.
I pushed the working code into https://github.com/collinforrester/loopback-passport-issue. The main issue is the code you added to https://github.com/collinforrester/loopback-passport-issue/blob/f6e1ffc7304e48c82c3aecbf288af91fbbdb33fd/server/boot/root.js. It completely bypassed the middlewares required to restore the user object so that ensure-logged-in can pass.
I'm working to add this to a 2.0 project and when I'm following the example code in this project, I'm getting the error:
Error: Model not found: UserCredential
Running with debug I get:
I was able to change the model definitions from the 1.x format to 2.0 but I'm guessing there is still something I'm missing as far as getting loopback to inherit the models that this project includes?