-
-
Notifications
You must be signed in to change notification settings - Fork 130
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
This is a great library but how you handle subdomains? #59
Comments
It's actually quite possible to handle subdomains by Passport. While Passport itself is fine with that, it's the examples given in Passport's documentation that are too simplified and thus they cannot handle several subdomains. These examples declare their passport.use(new passportTwitterStrategy(
{
consumerKey: 'XXXXXXXXXXXXXXXXXXXXXXXXX',
consumerSecret: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
callbackURL: 'http://' + someOptions.subdomain + '/callbackTwitter'
},
function(token, tokenSecret, profile, done){
done(null, profile);
}
)); There are two problems with that. Problem 1. Most of us tend to require Node.js modules at the very beginning of our scripts. Here we'd expect to drop However, if your script declares a function that accepts some parameters (such as the desired name of a subdomain) and returns, for example, an Express app for that subdomain, then you'd design your script ( var express = require('express');
var vhost = require('vhost');
var app = express();
app.use(vhost(
'subX.domain.com',
require('./yourSubdomainGenerator.js')({
subdomain: 'subX.domain.com'
})
));
app.use(vhost(
'subY.domain.com',
require('./yourSubdomainGenerator.js')({
subdomain: 'subY.domain.com'
})
)); Therefore you'd want to keep Problem 2. Node.js module system is a caching system. You may call There is a two-step solution that works around both of these two problems:
|
That exported |
I also believe that the above solution might help most people that experience the issue #12 in the case where it's |
The same problem is also seen in jaredhanson/passport#27, jaredhanson/passport#286, jaredhanson/passport#402. |
Thanks a bunch @Mithgol ! My express app (nuxt) serves multiple domains, now I can authenticate with any strategy configuration depending on the req.hostname (or x-forwarded-host) |
I have an app where a use could login on: subX.domain.com
and another user could login on subY.domain.com
The fact that the callbackURL is setup initially and bound to the app, makes it impossible for passport to authenticate a user correctly. Ideally, the twitter strategy handler (your second function passed into TwitterStrategy) should be set by user.
I guess this is not easy change or might not even be possible with passport.
Damiano
The text was updated successfully, but these errors were encountered: