oauth-2.0passport.jsloopbackjspassport-github2

Maintaining oath callback URLs


I'm developing a Loopback-based NodeJS app that uses GitHub Passport auth. For my development, I use localhost in my callbackURL setting in providers.json, but I have to change it to the published URL every time I deploy. At the same time, I have to change the same setting on GitHub.

How do you handle such scenarios? Is it possible to put a setting in providers.json? Is it possible to use two applications on GitHub and switch between them?


Solution

  • Probably you are loading the providers.json file in your server.js like in documentation: (https://loopback.io/doc/en/lb3/Configuring-providers.json.html)

    var config = {};
    try {
      config = require('../providers.json');
    } catch (err) {
      console.trace(err);
      process.exit(1); // fatal
    }
    

    So you can create two separate providers.json files (e.g. providers.dev.json providers.prod.json) and load a proper one according to e.g. NODE_ENV environment variable