feathersjs-ecosystem / authentication-oauth2

[MOVED] OAuth 2 plugin for feathers-authentication
https://github.com/feathersjs/feathers
MIT License
26 stars 15 forks source link

Callback URL problem in production when using oauth #53

Closed ImreC closed 6 years ago

ImreC commented 7 years ago

Steps to reproduce

Please check https://stackoverflow.com/questions/47000788/oauth2-github-connection-with-feathersjs-hosted-on-ec2.

Expected behavior

In my opinion, in production mode the callbackURL should be created from the host setting in production.json, not the one in default .json, but maybe there is a good reason not to do this.

Actual behavior

The callback URL gets created from default.json

System configuration

package.json: "engines": { "node": ">= 6.0.0", "npm": ">= 3.0.0" }, "scripts": { "test": "npm run eslint && npm run mocha", "eslint": "eslint src/. test/. --config .eslintrc.json", "start": "node src/", "mocha": "mocha test/ --recursive" }, "dependencies": { "aws-sdk": "^2.141.0", "body-parser": "^1.18.2", "compression": "^1.7.1", "cors": "^2.8.4", "dauria": "^2.0.0", "feathers": "^2.2.2", "feathers-authentication": "^1.3.0", "feathers-authentication-hooks": "^0.1.5", "feathers-authentication-jwt": "^0.3.2", "feathers-authentication-local": "^0.4.4", "feathers-authentication-oauth2": "^0.3.2", "feathers-blob": "^1.3.1", "feathers-configuration": "^0.4.1", "feathers-errors": "^2.9.2", "feathers-hooks": "^2.1.0", "feathers-hooks-common": "^3.7.3", "feathers-mongodb": "^2.9.1", "feathers-rest": "^1.8.0", "feathers-socketio": "^2.0.0", "helmet": "^3.8.2", "mongodb": "^2.2.33", "multer": "^1.3.0", "passport-facebook": "^2.1.1", "passport-github": "^1.1.0", "s3-blob-store": "^2.1.0", "serve-favicon": "^2.4.5", "winston": "^2.4.0" }, "devDependencies": { "eslint": "^4.8.0", "mocha": "^4.0.1", "request": "^2.83.0", "request-promise": "^4.2.2" }

daffl commented 7 years ago

If you set NODE_ENV=production it will always load production.json. Are you sure the NODE_ENV environment variable is set to production?

ImreC commented 7 years ago

Yes, I am absolutely sure. To complete the technical information above I am using PM2 to run the node instance with the following ecosystem.json { "apps" : [{ "name" : "myapp", "script" : "src/index.js", "env": { "NODE_ENV": "development" }, "env_production" : { "NODE_ENV": "production" }, "env_staging" : { "NODE_ENV" : "staging", "TEST" : true } }] }

The environment is set to production and the log says it is running at the host as defined in production.json. However, callback of github (and facebook) goes wrong if the host is not set in default.json too. Somehow the callback URL is generated from default.json. I am quite sure about this.

daffl commented 7 years ago

What does the console output on the server look like when setting DEBUG=feathers:configuration?

ImreC commented 6 years ago

Ok, I had the same problem again with a new app. Ran in production mode, but the host was taken from default.json. Changed the default.json host to the production parameter. Then back to localhost. After that, it all worked. Debug output was also normal. Tried to reproduce it with a newly created test app. Wasn't able to reproduce the error with that. I have no clue what went wrong. Maybe close the issue. I will request a reopen if I ever find out what the problem was.