microsoftarchive/botauth

Add capability to run behind pass through API gateway.

Opened this issue · 0 comments

I have to run my bots in a kubernetes cluster behind a software gateway (not on a public host).

This software gateway simply proxies requests for my bot, it accepts requests at https://bot.domain.com and relays them to http://mybot. This works well enough for messages.

The problem comes in when we add botauth: the options.basePath value is used for both route creation and as well as the generation of the callbackUrl and authUrl. So this means that our service endpoints can't be different from our auth and callback urls. Note that I can already do this with the code page by using options.successRedirect.

I'm sure this is by design (as the documentation always says your bot has to be running on a public host), but I'd find it useful if you added another botAuth option, say options.baseServicePath that can be used to define the routes on the server that do not necessarily match the externally exposed routes.

So for instance:

  let options = {
    baseUrl : 'https://bot.domain.com',
    basePath: '/botauth',
    baseServicePath:  '/mybot',
    //...,
    successRedirect: `https://bot.domain.com/botauth/providerId/code`
  };

  let botAuth = new botauth.BotAuthenticator(server, bot, options);
  //...
  server.get(`/${server.name}/botauth/providerId/code`, serveStatic({'directory': path.join(__dirname, 'public'), 'file': 'code.html'}));

Would give me the following external URLS:

Which could easily be mapped in my gateway to my service routes:

Obviously, issue 61 not withstanding, I think this could easily be done with:

  // botauth/lib/index.js

  // .. line 40
  if (!this.options.baseServicePath) {
    this.options.baseServiceUrl = this.options.baseUrl
  }
 // update these three lines. (around line 59)
  this.server.get(`/${this.options.baseServicePath}/:providerId`, this.options.resumption.persistHandler(), this.passport_redirect());
  this.server.get(`/${this.options.baseServicePath}/:providerId/callback`, this.passport_callback(), this.options.resumption.restoreHandler(), this.credential_callback());
  this.server.post(`/${this.options.baseServicePath}/:providerId/callback`, this.passport_callback(), this.options.resumption.restoreHandler(), this.credential_callback());

In any event, happy to contribute if that would work.