Skip to content

auth: Add BearerChallengePolicy for MFA step-up challenges during subscription listing - #2231

Merged
Alex Weininger (alexweininger) merged 2 commits into
mainfrom
auth/bearer-challenge-policy
Mar 20, 2026
Merged

Alex Weininger (alexweininger) merged 2 commits into
mainfrom
auth/bearer-challenge-policy

Conversation

@alexweininger

Copy link
Copy Markdown
Member

Problem

The auth package creates SubscriptionClient instances to list tenants and subscriptions, but these clients had no challenge policy on their HTTP pipeline. When users hit an MFA step-up challenge (401 with WWW-Authenticate header) during tenant/subscription listing, the request simply fails.

The challenge policy previously only existed in the azure package (AzExtBearerChallengePolicy), applied only to clients created via createAzureClient().

Solution

  • New BearerChallengePolicy in auth/src/utils/BearerChallengePolicy.ts — intercepts 401 + WWW-Authenticate, retries once with a stepped-up token
  • Wired into AzureSubscriptionProviderBase.getSubscriptionClient() at the Sign phase with afterPolicies: ['bearerTokenAuthenticationPolicy']
  • Exported BearerChallengePolicy and getDefaultScopeFromEndpoint from the package
  • Version bumped to 6.0.0-alpha.6

Related

Follow-up

A separate PR will update the azure package to consume BearerChallengePolicy from auth instead of maintaining its own duplicate.

The auth package creates SubscriptionClient instances to list tenants and
subscriptions, but these clients had no challenge policy on their HTTP
pipeline. When users hit an MFA step-up challenge (401 with WWW-Authenticate
header) during tenant/subscription listing, the request simply fails.

Changes:
- Create BearerChallengePolicy in auth/src/utils/BearerChallengePolicy.ts
- Wire into SubscriptionClient pipeline in AzureSubscriptionProviderBase
- Export BearerChallengePolicy and getDefaultScopeFromEndpoint
- Add @azure/core-rest-pipeline as devDependency
- Bump version to 6.0.0-alpha.6

Co-authored-by: Copilot <[email protected]>

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.

Pull request overview

Adds an authentication pipeline policy to handle MFA “step-up” (401 + WWW-Authenticate) challenges during tenant/subscription listing, so SubscriptionClient requests can transparently retry with a stepped-up token instead of failing.

Changes:

  • Introduces BearerChallengePolicy + getDefaultScopeFromEndpoint utility exported from auth
  • Wires the policy into AzureSubscriptionProviderBase.getSubscriptionClient() after bearer token signing
  • Bumps @microsoft/vscode-azext-azureauth to 6.0.0-alpha.6 and adds an Azure pipeline dependency

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 5 comments.

File Description
auth/src/utils/BearerChallengePolicy.ts New pipeline policy to handle 401 challenges by acquiring a stepped-up token and retrying once
auth/src/providers/AzureSubscriptionProviderBase.ts Adds the new policy to the SubscriptionClient pipeline for subscription listing
auth/src/index.ts Exports the new policy and helper function from the package
auth/package.json Version bump and adds @azure/core-rest-pipeline dependency (currently as devDependency)
Files not reviewed (1)
  • auth/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread auth/package.json Resolved
Comment thread auth/src/utils/BearerChallengePolicy.ts Resolved
Comment thread auth/src/utils/BearerChallengePolicy.ts Resolved
Comment thread auth/src/utils/BearerChallengePolicy.ts Resolved
Comment thread auth/src/utils/BearerChallengePolicy.ts Resolved
- Move @azure/core-rest-pipeline back to regular dependencies since
  BearerChallengePolicy is exported and its .d.ts references pipeline types
- Replace HTTP header-based retry marker (x-azext-challenge-retry) with a
  WeakSet to track retried requests out-of-band, avoiding sending the
  marker over the wire

Co-authored-by: Copilot <[email protected]>
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.

3 participants