Skip to content

fix(auth): use OAuth2 v2 authorize URL for browser login - #7718

Open
mujakayadan wants to merge 2 commits into
pnp:mainfrom
mujakayadan:mujakayadan/fix/browser-auth-v2-authorize
Open

mujakayadan wants to merge 2 commits into
pnp:mainfrom
mujakayadan:mujakayadan/fix/browser-auth-v2-authorize

Conversation

@mujakayadan

Copy link
Copy Markdown

Summary

  • Change AuthServer browser login from the legacy v1 /oauth2/authorize?…&resource= URL to /oauth2/v2.0/authorize with scope so the auth code matches MSAL acquireTokenByCode (v2 token endpoint).
  • Fixes personal Microsoft account sign-in failing with AADSTS500202 after the localhost success page.
  • Adds a unit test that asserts the opened URL is v2 and uses scope (not resource).

Fixes #7717

Test plan

  • npm run build && npx mocha --grep AuthServer (7 passing)
  • Manual: m365 login --authType browser --appId <msa-enabled-app> --tenant common with a personal Outlook.com account completes without AADSTS500202

AuthServer built a v1 authorize URL with resource=, then MSAL redeemed the code at the v2 token endpoint. That mix fails personal Microsoft accounts with AADSTS500202. Use /oauth2/v2.0/authorize with scopes instead. Fixes pnp#7717

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

Human validation against Entra/MSA is still needed because the failure occurs during live authorization-code redemption, which the separately mocked browser-authorization and token-exchange tests do not cover.

No open issues 🎉

What changed in this PR

Aligns CLI browser authentication with MSAL’s OAuth2 v2 token exchange to address personal Microsoft account sign-in failures reported in #7717.

Changes:

  • Replaces the v1 authorization URL and resource parameter with the v2 endpoint and scopes.
  • Encodes the scopes and redirect URI.
  • Adds a regression test checking the v2 endpoint, resource scope, and absence of resource.

Build, tests, and lint were not run during this review. Manual personal-account sign-in validation remains pending.

File Description
src/​AuthServer.ts Constructs the v2 authorization URL with encoded scopes and redirect URI.
src/​AuthServer.spec.ts Adds regression coverage for the updated authorization URL.

Review effort: Balanced

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

None yet

Development

Successfully merging this pull request may close these issues.

Browser auth uses v1 authorize URL; MSA token exchange fails with AADSTS500202

2 participants