Skip to content

feat(authentication): add msal browser authentication provider - #2138

Open
RKS (rksharma-owg) wants to merge 12 commits into
microsoft:mainfrom
rksharma-owg:feat/msal-browser-auth-provider
Open

RKS (rksharma-owg) wants to merge 12 commits into
microsoft:mainfrom
rksharma-owg:feat/msal-browser-auth-provider

Conversation

@rksharma-owg

@rksharma-owg RKS (rksharma-owg) commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #186

Summary

Adds @microsoft/kiota-authentication-msal-browser, providing MsalBrowserAuthenticationProvider and MsalBrowserAccessTokenProvider for Kiota clients using a consumer-supplied MSAL Browser application.

  • Silent acquisition with popup or redirect fallback when interaction is required, including errors from another MSAL module instance.
  • Account and CAE claims forwarding; per-call inferred scopes when none are configured.
  • Allowed-host and target-protocol validation, bearer-header integration, and tracing.
  • Workspace, ESLint, and release-please registration; a README example that initializes the MSAL application.

Review follow-up

URL normalization now matches allowed-host handling for protocol-relative and bare-host URLs. Inferred scopes use the parsed URL host, excluding query strings and fragments and normalizing hostname case. Regression tests cover those five forms. HTTPS validation and localhost behavior remain intact.

The package retains the correlation-ID correction and release-please registration. The current-main merge aligns the package and linked-release manifest to preview.110 and preserves all upstream lockfile entries, including libc metadata. No generated changelog is included.

Validation

Current head: 7898b7c11924684f3a493140c4fed7859c06d298, merged with upstream main 935dda5d45f28a0f30e97a9611d8fa3fe603edf4.

  • Local Node 24.21.0: npm ci, build, ESLint, Prettier, integrated build, repository tests, and coverage passed.
  • Exact merged-head preflight passed all 13 jobs: Node 20/22/24 build, lint, format, integrated build and repository tests, nine coverage jobs, and the matrix gate. Each test lane reports 472 passes and one existing skip; the repository test command invokes two lanes per runtime.
  • Real Chromium over HTTPS passed all 21 MSAL tests on each of Node 20/22/24. The repository's existing browser command does not enable browser mode under Vitest 5; these separate checks supply actual browser execution without changing shared configuration or dependencies.
  • The five URL regressions previously failed before the parsing correction; that regression coverage is retained. This refresh changes release/lock metadata and incorporates current main, with no auth source or test changes.

All 15 jobs that check out source verify the full tested SHA; the final matrix gate checks their results. Workflow revision: 789ca5aacd57022379e6b79a3af52407bb94b897. Skipped tests and upstream-only approvals are not counted as passed. No platform snapshots, assertions, or coverage gates were weakened.

HTTPS test and CI review correction

The HTTPS correction in 0ee30741a0ba0dff5b8ec40efbd19ba66cc8cc56 includes main 0e84ef8f49c77aab851ba720c0e02e1cd401e2d5 and its supported Node.js 22/24/26 matrix. The browser regression now asserts the actual HTTPS page protocol; it does not attempt to override window.location or ignore setup failures. The workflow runs all 21 MSAL tests in actual Chromium on each supported Node version, generates temporary localhost TLS certificates, includes MSAL distribution artifacts and coverage, and requires the browser jobs to pass in the aggregate gate. Browser-provider tooling is installed separately in the runner's temporary directory; library dependencies are unchanged by this correction.

Validation: exact-head/merged-head fork run, all 17 jobs passed: three build/test jobs, ten coverage jobs, three actual Chromium jobs, and the aggregate. Node suites pass 471 tests with two skips per invocation, including the explicitly browser-only regression; Chromium executes all 21 MSAL tests with no skips. Local build, lint, formatting, integrated build, Node tests, coverage, and HTTPS Chromium passed. The regression fails on an HTTP page; removing the provider's protocol guard also makes it fail on HTTPS, and restoring the guard passes. Upstream approval and private-feed publication checks are separate from this fork validation.

README and project-reference follow-up

Head 41231ee282ae23fca80ec2595fac2e7b7e545faa adds the MSAL Browser library link and npm version badge to the main README, explicitly installs both packages used by the sample, and adds the package to tsconfig.base.json project references. No runtime implementation or dependencies changed in this follow-up.

Local build, lint, integrated build, and Node tests passed; documentation paths, package names, and project references were checked. Refreshed exact-head cloud validation passed all 17 jobs, including the build/coverage matrix and all 21 actual HTTPS Chromium tests on each Node 22/24/26 runtime. Node suites retain the two documented skips. Upstream approval and private-feed checks remain separate.

This comment was marked as outdated.

…ecycle, account propagation, and scope immutability

This comment was marked as outdated.

@rksharma-owg

Copy link
Copy Markdown
Contributor Author

Updated in commit 7eee002:

  1. Release Automation Registration: Added packages/authentication/msal-browser to release-please-config.json (packages and linked-versions component list) and .release-please-manifest.json (1.0.0-preview.107).
  2. README Example Initialization: Added await msalInstance.initialize(); in README.md per MSAL 5.x requirements.
  3. Cross-Module Error Handling: Added isInteractionRequired in MsalBrowserAccessTokenProvider to inspect both InteractionRequiredAuthError and error codes/names (InteractionRequiredAuthErrorCodes), ensuring popup and redirect fallbacks work reliably even if the consumer uses a separate MSAL bundle/version. Added regression test coverage in msalBrowserAuthenticationTest.ts.

All 16 unit tests pass locally in Node and headless Chrome.

This comment was marked as outdated.

Comment thread .release-please-manifest.json Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Add publication artifact exclusions and document the direct MSAL dependency.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
Resolved since last review (1)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Resolve the lockfile libc metadata issue and correct inferred scope parsing for supported URL forms.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
Resolved since last review (1)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The HTTPS regression test does not reliably establish HTTPS, and package coverage is missing from the CI matrix.

0 open findings

1 resolved since last review

🧠 Review effort: Lite

@baywet

Copy link
Copy Markdown
Member

RKS (@rksharma-owg) would you mind addressing this please?

The HTTPS regression test does not reliably establish HTTPS, and package coverage is missing from the CI matrix.

@rksharma-owg

Copy link
Copy Markdown
Contributor Author

Addressed in 0ee30741. The regression now asserts the real page protocol is HTTPS, with no window.location override or swallowed setup error. CI generates a temporary localhost certificate and runs all 21 MSAL tests in actual Chromium on Node 22/24/26. MSAL now has a coverage-matrix entry and dist artifact, and the aggregate requires the browser jobs to succeed.

The test fails when served over HTTP and also fails on HTTPS if the provider's explicit HTTP guard is removed. All 17 fork validation jobs passed, including the three Chromium jobs and MSAL coverage. Node skips the browser-only case explicitly. No library dependencies changed in this correction.

@baywet Vincent Biret (baywet) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making the changes!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The package is missing the root TypeScript project reference; the README should also document installing MSAL Browser explicitly.

0 open findings

🧠 Review effort: Lite

@baywet

Copy link
Copy Markdown
Member

RKS (@rksharma-owg) can you add references to this sub project + badge in the main readme please?

@rksharma-owg

Copy link
Copy Markdown
Contributor Author

Added the MSAL Browser entry and npm badge to the main README in 41231ee2. I also addressed the latest review summary: tsconfig.base.json now references the package, and its README explicitly installs both the Kiota provider and @azure/msal-browser used by the example.

Local build, lint, integrated build, and Node tests passed. All 17 refreshed fork jobs passed, including 21 actual HTTPS Chromium tests on each Node 22/24/26 runtime.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Broad authentication, packaging, and CI changes warrant final human review despite successful validation.

0 open findings

🧠 Review effort: Lite

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress 🚧

Development

Successfully merging this pull request may close these issues.

Add msal browser kiota authentication provider

3 participants