Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
9795395
first draft with tests
sadasant Feb 19, 2021
10f90df
changelog entry
sadasant Feb 20, 2021
f37ce5a
claims on core-auth
sadasant Feb 20, 2021
1f682a6
improvements
sadasant Mar 1, 2021
85d52c1
comments and exporting a missing type
sadasant Mar 1, 2021
8fcc45b
added parseCAEChallenges test
sadasant Mar 1, 2021
b1df5f9
moved this test to be node only
sadasant Mar 1, 2021
2cce476
Merge branch 'master' into core-https/CAE-support
sadasant Mar 1, 2021
8fa9ec1
fixing bad link in the CHANGELOG
sadasant Mar 1, 2021
ebbed8a
cleanups after talk with Jeff
sadasant Mar 2, 2021
272d240
claims to challengeClaims
sadasant Mar 2, 2021
fa0646c
formatting
sadasant Mar 2, 2021
a8a7a50
back to claims after Scott feedback
sadasant Mar 2, 2021
b0a8337
claims changelog entry
sadasant Mar 2, 2021
663d7eb
renamed the authentication context, reduced the number of requests on…
sadasant Mar 3, 2021
435776e
processing challenges even if we already have a token
sadasant Mar 3, 2021
480ac2c
removing getToken from the possible parameters
sadasant Mar 3, 2021
670ce25
Merge remote-tracking branch 'upstream/master' into core-https/CAE-su…
jeremymeng Mar 24, 2021
d6b32a2
Fix merging issues
jeremymeng Mar 24, 2021
87d4b55
Pass the whole tracingOptions to GetTokenOptions
jeremymeng Mar 24, 2021
dda4039
Fix linting errors
jeremymeng Mar 25, 2021
ee68f6c
Fix test failures on NodeJS v8 and v10
jeremymeng Mar 25, 2021
0a09732
Update to make it work for container registry
jeremymeng Mar 30, 2021
83720b2
wip
sadasant Mar 31, 2021
a68a673
tests passing
sadasant Mar 31, 2021
5e0a716
API review cleanup
sadasant Mar 31, 2021
10ca6e5
Alignment with .Net
sadasant Mar 31, 2021
c9e6c47
Merge pull request #21 from sadasant/core-https/CAE-support-proposal
sadasant Apr 1, 2021
9f31ecf
Removed console.log
sadasant Apr 1, 2021
a789c76
Merge remote-tracking branch 'Azure/master' into core-https/CAE-support
sadasant Apr 1, 2021
633dfe9
fixes after merging the token cycler
sadasant Apr 1, 2021
b300a51
lint fix and small changelog improvement
sadasant Apr 1, 2021
b44184a
Merge remote-tracking branch 'Azure/master' into core-https/CAE-support
sadasant Apr 1, 2021
b387796
Bug fix: error without challenge should be re-thrown
sadasant Apr 2, 2021
5a4d88b
sendRequest to shouldSendRequest, thanks to Deya
sadasant Apr 2, 2021
d260f63
Move CAE support into a new policy
jeremymeng Apr 7, 2021
9fe1712
Merge remote-tracking branch 'upstream/master' into core-https/CAE-su…
jeremymeng Apr 7, 2021
e4ec342
Restore original bearerTokenAuthenticationPolicy
jeremymeng Apr 7, 2021
ab1c2e4
Refactoring
jeremymeng Apr 7, 2021
892ee7c
Rename challenge callbacks
jeremymeng Apr 7, 2021
d54547c
Pass full response to authorizeRequestOnChallenge()
jeremymeng Apr 7, 2021
9da2dd6
Expose WWW-Authenticate challenge parsing support
jeremymeng Apr 7, 2021
6631d38
Keep properties of object implementing `challengeCallbacks`
jeremymeng Apr 8, 2021
9a3e758
Merge remote-tracking branch 'upstream/master' into core-https/CAE-su…
jeremymeng Apr 8, 2021
c1c1213
- Remove unnecessary condition
jeremymeng Apr 8, 2021
9c97a64
Make `scopes` to have type `string[]`
jeremymeng Apr 9, 2021
dbf2e1f
- Make default on-challenge callback to just return false
jeremymeng Apr 13, 2021
06e6854
Move www-authenticate parsing support to core-util
jeremymeng Apr 13, 2021
e28bb35
Fix lint error
jeremymeng Apr 13, 2021
373589d
- Remove default authorizeRequestOnChallenge call back
jeremymeng Apr 13, 2021
1f2d6a3
Split ChallengeCallbackOptions into two for the two callbacks
jeremymeng Apr 15, 2021
fa118af
Remove single string scope
jeremymeng Apr 15, 2021
ce29fbf
Update version and CHANGELOG text
jeremymeng Apr 19, 2021
e78d193
Merge remote-tracking branch 'upstream/master' into core-https/CAE-su…
jeremymeng Apr 19, 2021
5ff8119
Conform to versioning convention
jeremymeng Apr 19, 2021
4b14121
Merge remote-tracking branch 'upstream/master' into core-https/CAE-su…
jeremymeng Apr 19, 2021
0c2392a
Remove `claims` change as architects are re-visiting this
jeremymeng Apr 23, 2021
5314922
Undo formatting change
jeremymeng Apr 23, 2021
e9b8a8d
Fix test
jeremymeng Apr 23, 2021
0d89d9d
Address CR feedback
jeremymeng Apr 26, 2021
5b64e51
Type `cachedToken` as `AccessToken | null` for consistency
jeremymeng Apr 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions sdk/core/core-rest-pipeline/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Release History

## 1.0.4 (Unreleased)
## 1.1.0-beta.1 (Unreleased)

- Rewrote `bearerTokenAuthenticationPolicy` to use a new backend that refreshes tokens only when they're about to expire and not multiple times before. This is based on a similar fix implemented on `@azure/core-http@1.2.4` ([PR with the changes](https://github.com/Azure/azure-sdk-for-js/pull/14223)). This fixes the issue: [13369](https://github.com/Azure/azure-sdk-for-js/issues/13369).
- Add a new `bearerTokenChallengeAuthenticationPolicy` that provides a skeleton of handling challenge-based authorization. There are two extensible points: `authorizeRequest` and `authorizeRequestOnChallenge` callbacks.
- `authorizeRequest` allows customizing the policy to alter how it authorizes a request before sending it. By default when no callbacks are specified, this policy has the same behavior as `bearerTokenAuthenticationPolicy`. It will retrieve the token from the underlying token credential, and if it gets one, it will cache the token and set it to the outgoing request.
- `authorizeRequestOnChallenge`, which gets called only if we've found a challenge in the response. This callback has access to the original request and its response and is expected to handle the challenge. If this callback returns true, the request, usually updated after handling the challenge, will be sent again. If this call back returns false, no further actions will be taken.

## 1.0.3 (2021-03-30)

Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-rest-pipeline/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure/core-rest-pipeline",
"version": "1.0.4",
"version": "1.1.0-beta.1",
"description": "Isomorphic client library for making HTTP requests in node.js and browser.",
"sdk-type": "client",
"main": "dist/index.js",
Expand Down
36 changes: 36 additions & 0 deletions sdk/core/core-rest-pipeline/review/core-rest-pipeline.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
```ts

import { AbortSignalLike } from '@azure/abort-controller';
import { AccessToken } from '@azure/core-auth';
import { Debugger } from '@azure/logger';
import { GetTokenOptions } from '@azure/core-auth';
import { OperationTracingOptions } from '@azure/core-tracing';
import { TokenCredential } from '@azure/core-auth';

Expand All @@ -26,6 +28,21 @@ export interface Agent {
sockets: unknown;
}

// @public
export interface AuthorizeRequestOnChallengeOptions {
getAccessToken: (scopes: string[], options: GetTokenOptions) => Promise<AccessToken | null>;
request: PipelineRequest;
response: PipelineResponse;
scopes: string[];
}

// @public
export interface AuthorizeRequestOptions {
getAccessToken: (scopes: string[], options: GetTokenOptions) => Promise<AccessToken | null>;
request: PipelineRequest;
scopes: string[];
}

// @public
export function bearerTokenAuthenticationPolicy(options: BearerTokenAuthenticationPolicyOptions): PipelinePolicy;

Expand All @@ -38,6 +55,25 @@ export interface BearerTokenAuthenticationPolicyOptions {
scopes: string | string[];
}

// @public
export function bearerTokenChallengeAuthenticationPolicy(options: BearerTokenChallengeAuthenticationPolicyOptions): PipelinePolicy;
Comment thread
jeremymeng marked this conversation as resolved.

// @public
export const bearerTokenChallengeAuthenticationPolicyName = "bearerTokenChallengeAuthenticationPolicy";

// @public
export interface BearerTokenChallengeAuthenticationPolicyOptions {
challengeCallbacks?: ChallengeCallbacks;
Comment thread
xirzec marked this conversation as resolved.
credential: TokenCredential;
scopes: string[];
}

// @public
export interface ChallengeCallbacks {
authorizeRequest?(options: AuthorizeRequestOptions): Promise<void>;
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.

I wonder if we should rename this to authorizeRequestBeforeSend or something to make it clear when it gets called in the naming? Otherwise, it's difficult to know its function without reading dosc (which not all devs will do)

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.

This name is picked for x-language consistency. I think it's an advanced scenario to implement CAE so I'd expect developers to learn more about it.

authorizeRequestOnChallenge?(options: AuthorizeRequestOnChallengeOptions): Promise<boolean>;
}

// @public
export function createDefaultHttpClient(): HttpClient;

Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-rest-pipeline/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export const SDK_VERSION: string = "1.0.4";
export const SDK_VERSION: string = "1.1.0-beta.1";
8 changes: 8 additions & 0 deletions sdk/core/core-rest-pipeline/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,12 @@ export {
BearerTokenAuthenticationPolicyOptions,
bearerTokenAuthenticationPolicyName
} from "./policies/bearerTokenAuthenticationPolicy";
export {
bearerTokenChallengeAuthenticationPolicy,
BearerTokenChallengeAuthenticationPolicyOptions,
bearerTokenChallengeAuthenticationPolicyName,
ChallengeCallbacks,
AuthorizeRequestOptions,
AuthorizeRequestOnChallengeOptions
} from "./policies/bearerTokenChallengeAuthenticationPolicy";
export { ndJsonPolicy, ndJsonPolicyName } from "./policies/ndJsonPolicy";
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ export function bearerTokenAuthenticationPolicy(
// The options are left out of the public API until there's demand to configure this.
// Remember to extend `BearerTokenAuthenticationPolicyOptions` with `TokenCyclerOptions`
// in order to pass through the `options` object.
const getToken = createTokenCycler(credential, scopes /* , options */);
const cycler = createTokenCycler(credential /* , options */);

return {
name: bearerTokenAuthenticationPolicyName,
async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {
const { token } = await getToken({
const { token } = await cycler.getToken(scopes, {
abortSignal: request.abortSignal,
tracingOptions: request.tracingOptions
});
Expand Down
Loading