Skip to content

Commit 4f43009

Browse files
authored
[core-rest-pipeline] make CAE policy options' credential optional (Azure#15134)
Azure Container Registry allows anonymous pull access, in which case, TokenCredential is not required for its challenge-based auth flow. This PR makes credential optional in the bearer token challenge auth policy options so that an undefined value is allowed. ACR SDK library would send an unauthorized initial request to ACR Api endpoint, get a challenge back then continue to handle the challenge.
1 parent e825c59 commit 4f43009

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

sdk/core/core-rest-pipeline/review/core-rest-pipeline.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const bearerTokenChallengeAuthenticationPolicyName = "bearerTokenChalleng
6464
// @public
6565
export interface BearerTokenChallengeAuthenticationPolicyOptions {
6666
challengeCallbacks?: ChallengeCallbacks;
67-
credential: TokenCredential;
67+
credential?: TokenCredential;
6868
scopes: string[];
6969
}
7070

sdk/core/core-rest-pipeline/src/policies/bearerTokenChallengeAuthenticationPolicy.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export interface BearerTokenChallengeAuthenticationPolicyOptions {
7676
/**
7777
* The TokenCredential implementation that can supply the bearer token.
7878
*/
79-
credential: TokenCredential;
79+
credential?: TokenCredential;
8080
/**
8181
* The scopes for which the bearer token applies.
8282
*/
@@ -136,7 +136,9 @@ export function bearerTokenChallengeAuthenticationPolicy(
136136
// The options are left out of the public API until there's demand to configure this.
137137
// Remember to extend `BearerTokenChallengeAuthenticationPolicyOptions` with `TokenCyclerOptions`
138138
// in order to pass through the `options` object.
139-
const cycler = createTokenCycler(credential /* , options */);
139+
const getAccessToken = credential
140+
? createTokenCycler(credential /* , options */).getToken
141+
: () => Promise.resolve(null);
140142

141143
return {
142144
name: bearerTokenChallengeAuthenticationPolicyName,
@@ -157,7 +159,7 @@ export function bearerTokenChallengeAuthenticationPolicy(
157159
await callbacks.authorizeRequest({
158160
scopes,
159161
request,
160-
getAccessToken: cycler.getToken
162+
getAccessToken
161163
});
162164

163165
let response: PipelineResponse;
@@ -179,7 +181,7 @@ export function bearerTokenChallengeAuthenticationPolicy(
179181
scopes,
180182
request,
181183
response,
182-
getAccessToken: cycler.getToken
184+
getAccessToken
183185
});
184186

185187
if (shouldSendRequest) {

0 commit comments

Comments
 (0)