azure: Use BearerChallengePolicy from auth instead of local duplicate#2232
azure: Use BearerChallengePolicy from auth instead of local duplicate#2232alexweininger merged 3 commits intomainfrom
Conversation
Replace AzExtBearerChallengePolicy and getDefaultScopeFromEndpoint in the azure package with imports from @microsoft/vscode-azext-azureauth. The telemetry properties (challenge, challengeSuccess) are preserved by wrapping the callback at the call site with try/catch for robustness. This adds @microsoft/vscode-azext-azureauth as a dependency of the azure package, consolidating the challenge policy logic in one place. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR consolidates Azure bearer challenge handling by replacing a locally duplicated challenge policy with BearerChallengePolicy from @microsoft/vscode-azext-azureauth.
Changes:
- Replaced local
AzExtBearerChallengePolicy/getDefaultScopeFromEndpointwithBearerChallengePolicyfrom@microsoft/vscode-azext-azureauth - Added try/catch around the challenge callback and precomputed the challenge handler
- Added
@microsoft/vscode-azext-azureauth@^6.0.0-alpha.6dependency
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| azure/src/createAzureClient.ts | Swaps in shared BearerChallengePolicy, adds telemetry + error handling around challenge callback, removes local duplicate policy/helpers |
| azure/package.json | Adds dependency on @microsoft/vscode-azext-azureauth for the shared challenge policy |
💡 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.
| const handleChallenge = getChallengeHandlerFromCredential(context.createCredentialsForScopes); | ||
| addAzExtPipeline( | ||
| context, | ||
| client.pipeline, | ||
| context.environment.resourceManagerEndpointUrl, | ||
| undefined, | ||
| undefined, | ||
| new AzExtBearerChallengePolicy( | ||
| context, | ||
| getChallengeHandlerFromCredential(context.createCredentialsForScopes), | ||
| context.environment.resourceManagerEndpointUrl | ||
| new BearerChallengePolicy( | ||
| async (challenge) => { | ||
| context.telemetry.properties.challenge = 'true'; | ||
| try { | ||
| const token = await handleChallenge(challenge); | ||
| context.telemetry.properties.challengeSuccess = token ? 'true' : 'false'; | ||
| return token; | ||
| } catch { | ||
| context.telemetry.properties.challengeSuccess = 'false'; | ||
| return undefined; | ||
| } | ||
| }, | ||
| context.environment.resourceManagerEndpointUrl, | ||
| ) | ||
| ); |
| } catch { | ||
| context.telemetry.properties.challengeSuccess = 'false'; | ||
| return undefined; | ||
| } |
| const handleChallenge = getChallengeHandlerFromCredential(context.createCredentialsForScopes); | ||
| addAzExtPipeline( | ||
| context, | ||
| client.pipeline, | ||
| context.environment.resourceManagerEndpointUrl, | ||
| undefined, | ||
| undefined, | ||
| new AzExtBearerChallengePolicy( | ||
| context, | ||
| getChallengeHandlerFromCredential(context.createCredentialsForScopes), | ||
| context.environment.resourceManagerEndpointUrl | ||
| new BearerChallengePolicy( | ||
| async (challenge) => { | ||
| context.telemetry.properties.challenge = 'true'; | ||
| try { | ||
| const token = await handleChallenge(challenge); | ||
| context.telemetry.properties.challengeSuccess = token ? 'true' : 'false'; | ||
| return token; | ||
| } catch { | ||
| context.telemetry.properties.challengeSuccess = 'false'; | ||
| return undefined; | ||
| } | ||
| }, | ||
| context.environment.resourceManagerEndpointUrl, | ||
| ) | ||
| ); |
- Extract createBearerChallengePolicy() helper to deduplicate policy creation between createAzureClient and createAzureSubscriptionClient - Rethrow errors from challenge handler instead of swallowing them - Log parseError(err).message to telemetry as challengeError on failure Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bwateratmsft
left a comment
There was a problem hiding this comment.
LGTM, though of course we need the new package version released
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bwateratmsft
left a comment
There was a problem hiding this comment.
With all these new packages added to the lockfile, we should try to install this package in, e.g., the Resources extension and make sure the bundle size hasn't gone haywire.
Summary
Replaces the local
AzExtBearerChallengePolicyandgetDefaultScopeFromEndpointin the azure package with imports from@microsoft/vscode-azext-azureauth, consolidating the challenge policy logic in one place.Changes
BearerChallengePolicyfrom@microsoft/vscode-azext-azureauthAzExtBearerChallengePolicyclass andgetDefaultScopeFromEndpointfunctionchallengeSuccess = 'false'on failure)@microsoft/vscode-azext-azureauth: ^6.0.0-alpha.6as dependencyDepends on
@microsoft/vscode-azext-azureauth@6.0.0-alpha.6published first.