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

Initializing PassportJS #26

Closed
nomanurrehman opened this issue Aug 25, 2014 · 16 comments
Closed

Initializing PassportJS #26

nomanurrehman opened this issue Aug 25, 2014 · 16 comments

Comments

@nomanurrehman
Copy link

I am trying but failing to register PassportJS middleware in the config file. Here is the config file code for meddleware:

// passportjs
"passport": {
   "enabled": true,
   "priority": 92,
   "module": {
      "name": "passport",
      "method": "initialize"
   }
},
// passportjs
"passport": {
   "enabled": true,
   "priority": 93,
   "module": {
      "name": "passport",
      "method": "session"
   }
}

What am I doing wrong ?

@aredridel
Copy link
Contributor

@tlivings
Copy link
Member

Are you receiving an error message? Can you post additional details?

@nomanurrehman
Copy link
Author

I have actually seen the KrakenJS passport example and how the code is put in there to initialize it with the event hooks but do not you think that is a bit anti-productive to the whole 'middleware in config' idea as that scatters the code a bit ?

There is no way to do it purely using the config file ?

Here is the error:

TypeError: Object #<Object> has no method 'authenticate'
    at Authenticator.session (/home/noman/Projects/NodeJS/FileUploadService/node_modules/passport/lib/authenticator.js:237:15)
    at resolveImpl (/home/noman/Projects/NodeJS/FileUploadService/node_modules/kraken-js/node_modules/meddleware/index.js:98:20)
    at resolve (/home/noman/Projects/NodeJS/FileUploadService/node_modules/kraken-js/node_modules/meddleware/index.js:53:18)
    at register (/home/noman/Projects/NodeJS/FileUploadService/node_modules/kraken-js/node_modules/meddleware/index.js:206:22)
    at Array.forEach (native)
    at Function.onmount (/home/noman/Projects/NodeJS/FileUploadService/node_modules/kraken-js/node_modules/meddleware/index.js:203:14)
    at Function.g (events.js:180:16)
    at Function.emit (events.js:117:20)
    at /home/noman/Projects/NodeJS/FileUploadService/node_modules/express/lib/application.js:196:8
    at Array.forEach (native)

@tlivings
Copy link
Member

The vast majority of middleware is configured simply through a single call and these cases are handled. Passport's requirement to not only add middleware, but add strategies to passport itself make a purely configuration driven setup hard. This is just the situation that the middleware event hooks were designed for.

@luizfilipe
Copy link
Contributor

Passport needs the module as scope of factory function how we can see here but this is not able, because of that line.

My thought about this:

return factory.apply(module, args);

@luizfilipe
Copy link
Contributor

@tlivings The strategies can be loaded on an event passport:before or not?

@tlivings
Copy link
Member

I don't see why not.

@luizfilipe
Copy link
Contributor

@tlivings I made a two days ago a PR, to improve the problem with this issue, when someone will review the changes?

@aredridel
Copy link
Contributor

Taking a look at that pr now!

@luizfilipe
Copy link
Contributor

@totherik The #29 solves this issue? Thoughts?

@aredridel
Copy link
Contributor

LGTM!

@totherik
Copy link
Member

Yep, as far as I can tell #29 solves this.

@luizfilipe
Copy link
Contributor

@totherik When #29 go to npm registry?

@totherik
Copy link
Member

Hey sorry @luizfilipe, I'll try to get this published today. Looking like it'll be meddleware@3.0 due to the breaking changes.

@hanric
Copy link

hanric commented Oct 25, 2016

Hi, I know it's been a while, but could you explain how this fix works with Passport? Thank you.

@totherik
Copy link
Member

My understanding was just that Passport internally depend on instance methods. Due to context not being set correctly the object instance upon which methods were being called was not the correct or expected one.

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

6 participants