Search code examples
sails.jspassport.jspassport-facebook

SailsJS: Transferring Facebook app secret to local.js file


I'm using Sails + Passport for Facebook authentication in my app.

I have a middleware file contains:

module.exports = {
    express: {
        customMiddleware: function (app) {
            passport.use(new FacebookStrategy({
                clientID: "123456",
                clientSecret: "123456",
                callbackURL: "http://myskills.co/auth/facebook/callback",
                passReqToCallback: true
            },

Since the app is open-sourced, I don't want to expose the client secret on GitHub.
Sails documentation recommends using a local.js file that is ignored by git.

I can't figure how to get the value back from the local.js file to this function.
Any help will be much appreciated.

The complete code is on GitHub: https://github.com/ronenteva/MySkills/blob/master/config/passport.js


Solution

  • Since, AFAIK, local.js is being loaded after all other config files, you will probably not be able to access your clientID and clientSecret through Sails.config from config/passport.js. But at the same time, the solution can be even simpler: since both files are in the same folder, you can just require your local.js and get the values you need. Something like that:

    ...
    var sm = require('sitemap');
    var locals = require('./local');
    
    ...
    passport.use(new FacebookStrategy({
      clientID: locals.facebook.clientID,
      clientSecret: locals.facebook.clientSecret,
      callbackURL: "http://dev.myskills.co/auth/facebook/callback",
      passReqToCallback: true
    },
    ...