-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add passport.findStrategy() #379
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
base: master
Are you sure you want to change the base?
Conversation
any comments on this?!? |
Could you post an example of how this feature would be used by a developer? I understand the use case, and think its worth supporting, but I haven't had a chance to thoroughly review and think about alternative approaches. |
To clarify, I mean an example other than that in the source code. That example isn't doing anything that Passport offers simpler mechanisms for already. |
If I have a server where the strategy is stored in the database (because the different users can configure their own specific login mechanisms) a possible implementation could look like the following (in a real implementation with caching and so on...): passort.findStrategy(function(name, done) {
// Start lookup in database...
Strategy.findOne({name: name}, function(err, item) {
if (err)
return done(err);
if (item.type === 'facebook')
return done(null, new FacebookStrategy(item.config));
if (item.type === 'google')
return done(null, new GoogleStrategy(item.config));
if (item.type === 'twitter')
return done(null, new TwitterStrategy(item.config));
return done(null, null);
});
}); and something like app.get('/auth/:strategy', function(req, res, next) {
return passport.authenticate(req.params.strategy)(req, res, next);
}); The code changes should be minimal. |
Yep. I've got a similar use case. Quick question, do you primarily use this with OAuth providers (and other redirect-based IdPs). Do you use this with API authentication mechanisms like Bearer, Basic, etc? |
Mainly with OAuth, since the usual use case is that a user will register his/her application at Facebook/Google/Twitter and configures the client ID and secret on my server. Providing different Basic implementation should be possible too (e.g. depending on the hostname for virtual host) but is not a real use case for me ATM. |
Right, I have a OAuth implementation that looks up configuration at run time, rather than passing into strategies. I'll try to clean that up and publish it, and let you know. Agreed that this approach is more flexible. |
Since I have to get the user infos from the OAuth providers too and not all of them support OpenID Connect ATM the configuration lookup at run time would not solve all of my requirements. Making those callbacks somehow configureable or duplication the already existing code in the strategies does not sound like a good way to go for me. |
Yes. I'm catching up on the backlog now. Give me a week or two, and I'll get this (or something close to it) merged in. Sorry for the delay, but I prefer to move slow and consider security-related stuff from all angles. And thanks for the patch! |
No stress. I agree on the security point. Just wanted to know if this idea will work out or if I have to find an alternative solution for my problem... |
ping? |
Is the findStrategy going to be merged into the master branch? Just looking for this exact solution for passport. |
Was a different solution merged? I see references in the source code to "Strategy augmentation". Maybe that is related? |
Any update on this? |
This allows us to have strategies depending on e.g. req.headers.host.