botbuilder-js icon indicating copy to clipboard operation
botbuilder-js copied to clipboard

feat: msal for opt-in authentication

Open joshgummersall opened this issue 4 years ago • 3 comments

Fixes #2782

This PR is the JS analog of https://github.com/microsoft/botbuilder-dotnet/pull/5736. With this change, users can make a small runtime bot change to opt into MSAL authentication:

const { ConfidentialClientApplication } = require("@azure/msal-node");
const { getRuntimeServices } = require("botbuilder-dialogs-adaptive-runtime");

const {
  makeApp,
} = require("botbuilder-dialogs-adaptive-runtime-integration-express");

const {
  MsalServiceClientCredentialsFactory,
} = require("botframework-connector");

(async function () {
  try {
    const [services, configuration] = await getRuntimeServices(
      process.cwd(),
      "settings"
    );

    const serviceClientCredentialsFactory = new MsalServiceClientCredentialsFactory(
      configuration,
      new ConfidentialClientApplication({
        auth: {
          clientId: configuration.get(["MicrosoftAppId"]),
          clientSecret: configuration.get(["MicrosoftAppPassword"]),
        },
      })
    );

    services.addInstance(
      "serviceClientCredentialsFactory",
      serviceClientCredentialsFactory
    );

    const [, listen] = await makeApp(services, configuration, process.cwd());
    listen();
  } catch (err) {
    console.error(err);
    process.exit(1);
  }
})();

joshgummersall avatar Jul 06 '21 17:07 joshgummersall

Pull Request Test Coverage Report for Build 1008957180

  • 15 of 46 (32.61%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.1%) to 84.2%

Changes Missing Coverage Covered Lines Changed/Added Lines %
libraries/botbuilder-dialogs-adaptive-runtime-core/src/serviceCollection.ts 1 2 50.0%
libraries/botframework-connector/src/auth/msalServiceClientCredentialsFactory.ts 4 18 22.22%
libraries/botframework-connector/src/auth/msalAppCredentials.ts 8 24 33.33%
<!-- Total: 15 46
Totals Coverage Status
Change from base Build 1008943513: -0.1%
Covered Lines: 19686
Relevant Lines: 22174

💛 - Coveralls

coveralls avatar Jul 06 '21 19:07 coveralls

@carlosscastro, it looks like introducing @azure/msal-node breaks Typescript compilation in older Typescript versions. At the moment, we target version 3.3 and up, whereas @azure/msal-node only compiles for version 3.8 and up. This has actually come up quite a bit recently as there are several newer Typescript features that are not backward compatible. We probably need to rethink our Typescript support matrix as supporting old versions will only become more of a headache for us.

EDIT: Another option could be to introduce these types to a new package that is not backward compatible.

joshgummersall avatar Jul 07 '21 16:07 joshgummersall

Marked as draft until resolving the Typescript version issue.

joshgummersall avatar Jul 12 '21 19:07 joshgummersall