Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.3.0 is not working #400

Closed
4auvar opened this issue Aug 21, 2015 · 60 comments
Closed

0.3.0 is not working #400

4auvar opened this issue Aug 21, 2015 · 60 comments

Comments

@4auvar
Copy link

4auvar commented Aug 21, 2015

Hey people,

Just for your information, your latest version (0.3.3) is not working for me.

I am using its simpleLocalStrategy and getting user is undefined.

so I reverted to previous release (0.2.2) which is working for me.

@jaredhanson
Copy link
Owner

Can you provide any more information? LocalStrategy is working fine with 0.3.0 for me.

Sent from my iPhone

On Aug 21, 2015, at 12:23 AM, Gaurav Nayak notifications@github.com wrote:

Hey people,

Just for your information, your latest version (0.3.3) is not working for me.

I am using its simpleLocalStrategy and getting user is undefined.

so I reverted to previous release (0.2.2) which is working for me.


Reply to this email directly or view it on GitHub.

@embrown30
Copy link

I get this issue as well
CONSOLE_DEBUG LOG (Fri, 21 Aug 2015 18:38:31 GMT) Error logging in: [TypeError: Cannot set property 'user' of undefined] stack: TypeError: Cannot set property 'user' of undefined
at /Users/ericabr/panoconsole/dist/node_modules/passport-ibmid-oauth2/node_modules/passport-oauth/node_modules/passport/lib/passport/http/request.js:45:35
at pass (/Users/ericabr/panoconsole/dist/node_modules/passport/lib/authenticator.js:267:43)
at serialized (/Users/ericabr/panoconsole/dist/node_modules/passport/lib/authenticator.js:276:7)
at /Users/ericabr/panoconsole/dist/config/passportLocal.js:38:3
at pass (/Users/ericabr/panoconsole/dist/node_modules/passport/lib/authenticator.js:284:9)
at Authenticator.serializeUser (/Users/ericabr/panoconsole/dist/node_modules/passport/lib/authenticator.js:289:5)
at IncomingMessage.req.login.req.logIn (/Users/ericabr/panoconsole/dist/node_modules/passport-ibmid-oauth2/node_modules/passport-oauth/node_modules/passport/lib/passport/http/request.js:43:29)
at /Users/ericabr/panoconsole/dist/routes/login.js:120:8
at Strategy.strategy.success (/Users/ericabr/panoconsole/dist/node_modules/passport/lib/middleware/authenticate.js:194:18)
at verified (/Users/ericabr/panoconsole/dist/node_modules/passport-local/lib/strategy.js:83:10)
at /Users/ericabr/panoconsole/dist/config/passportLocal.js:68:16
at findByUsername (/Users/ericabr/panoconsole/dist/config/passportLocal.js:30:14)
at /Users/ericabr/panoconsole/dist/config/passportLocal.js:62:7
at process._tickCallback (node.js:355:11)

However, authentication was successful, the user was returned..
When I call req.logIn, I get that error.
If I revert to 0.2.2 I am able to login
Glad I found this from googling ... :-)

@jaredhanson
Copy link
Owner

passport-ibmid-oauth2 needs to update its dependency on passport-oauth to 1.0.0, here: https://github.com/osipov/passport-ibmid-oauth2/blob/master/package.json#L24

@gkoberger
Copy link

Same error, however I only get it when in Chrome Private Browsing mode.

@sahat
Copy link

sahat commented Aug 24, 2015

Getting this error as well when using https://github.com/sahat/hackathon-starter with passport 0.3.0 and passport-local.

@4auvar
Copy link
Author

4auvar commented Aug 24, 2015

@jaredhanson ,
I have entry in package.json like below
"passport": "*", "passport-local": "*",
so when I did npm install, npm installed latest package of passport, after successful installation when I started my server and tried to login in my app I got below error :

TypeError: Cannot read property 'user' of undefined at Object.exports.login [as handle] (D:\foo\Services\controllers\usercontroller.js:147:29) at next_layer (D:\foo\node_modules\express\lib\router\route.js:103:13) at Route.dispatch (D:\foo\node_modules\express\lib\router\route.js:107:5) at D:\foo\node_modules\express\lib\router\index.js:205:24 at Function.proto.process_params (D:\foo\node_modules\express\lib\router\index.js:269:12) at next (D:\foo\node_modules\express\lib\router\index.js:199:19) at next (D:\foo\node_modules\express\lib\router\index.js:176:38) at next (D:\foo\node_modules\express\lib\router\index.js:176:38) at next (D:\foo\node_modules\express\lib\router\index.js:176:38) at next (D:\foo\node_modules\express\lib\router\index.js:176:38) GET /login 500 55ms - 1.18kb

so, I reverted to previous release and change my package.json as "passport": "^0.2.2","passport-local": "*",`

And its working correctly, Hope that above information is enough to repro the issue.

@PanicIsReal
Copy link

Has this been addressed yet, just beat my head off the wall wondering why this wasn't working, sure works now that I've reverted to 0.2.2

@area
Copy link

area commented Aug 24, 2015

Yeah, I'm seeing this too using passport-local.

@jaredhanson
Copy link
Owner

Are you guys using any other strategies besides passport-local? Any strategies that depend on old versions of passport core will cause this problem. They should be updated to depend on passport-strategy, rather than passport itself.

@sahat
Copy link

sahat commented Aug 25, 2015

✅ Solution

Upgrading passport-github and passport-instagram to 1.0.0 has fixed the issue for me.
(Thanks @jaredhanson)

@julianlam
Copy link

@jaredhanson we're only using your passport local package. Does this need to be updated?

@jaredhanson
Copy link
Owner

@julianlam Can't hurt. What version are you using?

@julianlam
Copy link

Thanks for your attention on the matter!

https://github.com/NodeBB/NodeBB/blob/master/package.json

0.3.x of passport, and 1.0.0 of passport local

@jaredhanson
Copy link
Owner

Is the problem reproducible with a clean install? If not, I suspect the npm cache for updates might be giving old versions

Sent from my iPhone

On Aug 26, 2015, at 12:28 PM, Julian Lam notifications@github.com wrote:

Thanks for your attention on the matter!

https://github.com/NodeBB/NodeBB/blob/master/package.json

0.3.x of passport, and 1.0.0 of passport local


Reply to this email directly or view it on GitHub.

@julianlam
Copy link

The problem only occurs to users on new sessions. For example, my main browser has an existing session from passport 0.2.x, so req.session.passport exists, but on 0.3.x, req.session.passport doesn't exist, and so we get an error when the user object is saved or serialised into that object (which is now undefined).

Not sure if that's completely off the mark. @barisusakli, can you confirm we have passport local v1.x on production?

@julianlam
Copy link

Sorry, to clarify, my old session has req.session.passport whereas brand new sessions do not. I only have it because it is not erased on logout.

@barisusakli
Copy link

Yeah passport-local@1.0.0

@jaredhanson
Copy link
Owner

The main change in passport@0.3.0 is that req.session.passport is now lazy-initialized when a user logs in. If no login has happenend, req.session.passport will not exist. You can see this code here:
https://github.com/jaredhanson/passport/blob/master/lib/http/request.js#L50

This rationale for this is discussed in #320.

If you have any dependencies (or dependencies of dependencies) that pull in older versions of Passport, the HttpRequest#login method will get overwritten, causing this conflict.

@julianlam Can you verify that the new code (linked to above) is what is getting executed on login? A full stack trace of any error will help diagnose the issue.

@julianlam
Copy link

Thanks for the write up! Unfortunately I'm only seeing this on our production build and not my dev environment (isn't that how it always is?). So I'm going to have to do-it-live:tm: and try to repro there.

So fingers crossed it is an npm cache issue we both won't have to do anything.

@julianlam
Copy link

@jaredhanson Identified the issue, submitting a PR against passport-totp shortly. (Assuming I can figure out how to use passport-strategy.....)

@julianlam
Copy link

This PR should fix the problem. As you suggested, it was an issue with a dependency of a dependency using passport itself (in this case, passport-totp):

jaredhanson/passport-totp#5

@jaredhanson
Copy link
Owner

I've published passport@0.3.1, which was patched by #435. The fix addresses issues when using older strategies that overwrite the improved, lazy session creation added in passport@0.3.x.

It should now be possible to use any strategy with passport@0.3.x, including those that have a dependency on passport@0.2.x or passport@0.1.x. It is still my recommendation that strategies migrate to a dependency on passport-strategy@1.x.x, rather than passport itself.

Martii pushed a commit to Martii/OpenUserJS.org that referenced this issue Nov 11, 2015
* Also trying out *chalk* dep to see if the VPS pro logs can handle this without too much visual interference... nicer in development and debug modes... if not will remove.

Applies to Code Migrations, OpenUserJS#430,  and jaredhanson/passport#400 (comment)

Still getting `username is taken` with *passport*@0.3.2 and *passport-github*@1.0.0
but **not** *passport*@0.2.2 with *passport-github*@0.1.5
@Martii
Copy link

Martii commented Nov 11, 2015

@jaredhanson
Help please... AFAIK we aren't a strategy although @sizzlemctwizzle appears stumped (just an assumption... he might be doing other things too) in private as to why we can't upgrade our deps.

It is still my recommendation that strategies migrate to a dependency on passport-strategy@1.x.x, rather than passport itself.

I am not entirely sure if our usage is considered a "strategy" or not since we appear to be doing some unusual things to passport starting here... as this is my least familiar portion of our code (not to mention authentication in general with passport). I am currently at a loss on what to do. What I am able to do. I've done my best to clean up the code in our project controller here to make it more readable but still hitting the proverbial brick wall. Any insight would be greatly appreciated.

@Martii
Copy link

Martii commented Nov 11, 2015

@jaredhanson Cc: @sizzlemctwizzle
... and magically it just started working... nothing was changed on our end to my knowledge and I'm using our projects same checkout with fixed deps with the bump on passport and passport-github. I was in the middle of adding some console messages into our dev environment and it magically logged me in... so I did a hard reset (minus the dep bumps) and it still let me login to our development. (reinstalled the deps just to be sure and still okay)

I sure would like to know what changed so I can learn what was happening. Only thing I can vaguely conclude is GH literally just changed something in the last half hour with their OAuth session generation... I currently have no reference to their repository with this and https://github.com/github shows no activity in the last 30 minutes. :\

@Martii
Copy link

Martii commented Nov 11, 2015

@jaredhanson Cc: @sizzlemctwizzle

Another followup note here... when I did this most recent testing I upped just the passport@0.3.2, logged into our dev environment... that worked okay as expected... then I updated the passport-github@1.0.0 ... it failed a few times then magically, out of nowhere, it worked.

So going backwards in testing... I did a complete reset of our repo (locally) and removed all deps and reinstalled them from scratch, e.g. passport@0.2.2 with passport-github@0.1.5 ... now with those dep versions it won't let me log in anymore... this could indicate that passport/passport-github and/or GH itself migrated my account silently in the background.

In summary this could prove to be a very difficult migration with 0.3.2 since not all of our users may log in for months... so they'll be locked out after our production goes to 0.3.2 and 1.0.0 respectively. I'm now locked out of our dev environment for the time being... I can recreate my account there manually but we have a few thousand users and I'd rather not let them have this user experience in our production.

Any ideas?

@jaredhanson
Copy link
Owner

@Martii: There's nothing in passport-github or passport (any versions) that would change the behavior of someone logging in to your website. You should be able to upgrade either dependency to any version without consequence.

This issue is discussing a particular issue where sessions were lazily initialized in passport@0.3.0, and some older strategies were incompatible with that change, and caused req.login to always fail. This has been addressed in passport@0.3.2, which can now use all strategies, including older ones that depend on a legacy version of passport.

I honestly don't follow what you are describing, but from the sound of it seems like some issue with higher-level application logic. If you can isolate an issue with passport specifically, please file an issue.

@Martii
Copy link

Martii commented Nov 11, 2015

@jaredhanson
I will see if I can find any bugs in our code but there is a low probability of this since I've been migrating passport and all the related deps for almost a year now every bump and it's worked fine until 0.3.0, which is what this issue is subjected as, and 1.0.0.

I'll create an issue if I don't find anything but most likely it will be titled similarly. I just revoked my authorized applications too at https://github.com/settings/applications and no such luck there. This bug doesn't really follow any discernible pattern yet other than matching a handful of comments in this issue here. Thanks.

@jaredhanson
Copy link
Owner

0.3.0 may not work. 0.3.2 introduces the fix. If you upgrade to passport@0.3.2, you shouldn't see any issues with any strategies, GitHub included.

@Martii
Copy link

Martii commented Nov 11, 2015

Unfortunately I am experiencing it with 0.3.2 as denoted up here. I even recorded my sh-session logs and forwarded them off to @sizzlemctwizzle as to the magic working of 0.3.2 ... but now downgrading doesn't work now... this would indicate there's going to be a huge problem with upgrading passport and passport-github since our users don't log in daily... could be months or years down the line.

I'll try clearing our stored sessions as alluded to in #400 (comment) ... perhaps the session id is messing with this.

@jaredhanson
Copy link
Owner

this would indicate there's going to be a huge problem with upgrading passport and passport-github since our users don't log in daily

This is what I don't follow. Passport itself hasn't changed how sessions are stored from version to version. The only change is that an authentication session is not initialized until necessary, rather than ahead of time.

There's no issue with upgrading passport or its strategies, and session behavior, as far as a user is concerned, is not impacted. It doesn't matter what version of a strategy you use yesterday, and what version you use a year from now. Authentication itself will proceed the same way.

@jaredhanson
Copy link
Owner

@Martii I notice in the code above, you are using custom callbacks with Passport. Does that callback get invoked. If it gets invoked, is the failure afterwards?

@Martii
Copy link

Martii commented Nov 11, 2015

Re: #400 (comment)

For some reason, beyond my current understanding at this time, we store the session ids here in our model MongoDB. This is what I have to manually clear out and see if those are interfering with upgrading and downgrading.

Here's a gist of what I just did with downgrading in our dev environment... you can see:

  • here is where I removed all deps
  • here is where it installed our current aging 0.2.x dep
  • here is where it installed our current aging 0.1.x dep
  • here is me attempting to login ... this worked two hours ago and I had this issue with passport@0.3.2 and passport-github@1.0.0. ... the message of username is taken is one of ours here.

@jaredhanson
Copy link
Owner

I have no idea why a user model would have a session ID on it, but that's not something Passport does. This error you encounter is clearly in application-specific code, here: https://github.com/OpenUserJs/OpenUserJS.org/blob/aa1529a6d3b3e098257b0eb98b316fae75efbe45/libs/passportVerify.js#L77

At this point, I don't see any evidence that Passport itself has regressed, at least so far in its publicly exposed API. If you have overridden internals at a higher layer, that I can't control for. If you can isolate those details, please post here.

@Martii
Copy link

Martii commented Nov 11, 2015

Does that callback get invoked.

Both the exports.callback callback and the exports.verify are getting called according to the gist I just referenced... the issue appears that aLoggedIn is undefined.

I appreciate your patience with me, especially since I'm not fully versed with passport yet.

This error you encounter is clearly in application-specific code

That is because the verify callback is returning not logged in in the parameter... otherwise we wouldn't be capturing the verify error of the strategy.

@jaredhanson
Copy link
Owner

From the looks of it, you have overridden Passport internals here:
https://github.com/OpenUserJs/OpenUserJS.org/blob/98584fbd27376de79c53d6eb5510a280b66491d9/controllers/auth.js#L201-L205

I don't know why that was done or why it was necessary. It appears to me that is the cause of your issue. Passport 0.3.x may have exacerbated your issue, but since internals shouldn't have been hijacked in the first place, there's not much guidance I can give you at this point.

I'm closing this issue now, because I consider it fixed. If you want to discuss the behavior you are experiencing (which I'm confident is caused by problems other than those in this issue), please open a new issue.

@Martii
Copy link

Martii commented Nov 12, 2015

No problem... I am guessing that passport-github, or other strategy, currently has weak encryption support which is why the prior maintainers overloaded the "private" method. I'll do some more tinkering and see if I can work around this commented deficiency in the strategy and see if I can validate it under todays standards with passport and affected strategies.

Thanks again.

@Martii
Copy link

Martii commented Nov 12, 2015

Here is the breaking change for the issue we are having... GH usually sends a Number for this field but that commit type casts it to a String... so for over a year we've been storing it as a Number as returned by your packages and passport-github@1.0.0 now returns a String... so this appears to be not passport itself nor is it our implementation. The latest passport-github@1.0.0 has a breaking change that will cause DB issues and a Denial of Service (DoS) from your strategy if unchecked. ;)

phew Thank you again for your repsonses... at least I can fix our DB with a migration (or un-type-cast it) and we can work past this "correction" from that package.

Hope this helps someone else out who may have this issue but hasn't spoken up yet. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests