Search code examples
node.jsopenshiftpassport.jspassport-facebook

Facebook authentication don't work properly (deployed on OpenShift)


I built an application that uses Facebook authentication and it works as expected when running from localhost. However, after deploying the application to OpenShift and testing it with the right domain name, the server don't save the user.

Facebook settings in Development: 1

Facebook settings in Production: 2

OpenShift settings:

rhc set-env FACEBOOK_ID=id -a <appname-id>
rhc set-env FACEBOOK_SECRET=secret -a <appname-secret>

On documentation it says that I need to add this but it doesn't work: You will also need to set DOMAIN environment variable

rhc config:set DOMAIN=<appname>.rhcloud.com

I restarted the server but always the same:

rhc app-restart -a <appname>

I would appreciate any suggestions or even any thoughts on what questions I should be asking.


UPDATE 1

So I check the logs and the only diference on GET is:

OpenShift

GET /auth/facebook 302 3ms - 510b
GET /<appname>.rhcloud.com/auth/facebook/callback?code=XXXXXX 200 5ms

Localhost

GET /auth/facebook 302 10ms - 444b
GET /auth/facebook/callback?code=XXXXXXXX 302 1360ms - 58b

On OpenShift it adds the domain, any thoughts?


Solution

  • The problem was the callbackURL of FacebookStrategy on production mode.

    The right configuration is:

    clientID:     process.env.FACEBOOK_ID || 'id',
    clientSecret: process.env.FACEBOOK_SECRET || 'secret',
    callbackURL:  '/auth/facebook/callback'