@azure/core-client 1.3.3-alpha.20211026.1 → 1.4.0-alpha.20211206.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -1
- package/README.md +1 -1
- package/dist/index.js +81 -1
- package/dist/index.js.map +1 -1
- package/dist-esm/src/authorizeRequestOnClaimChallenge.js +70 -0
- package/dist-esm/src/authorizeRequestOnClaimChallenge.js.map +1 -0
- package/dist-esm/src/base64.browser.js +7 -0
- package/dist-esm/src/base64.browser.js.map +1 -1
- package/dist-esm/src/base64.js +8 -0
- package/dist-esm/src/base64.js.map +1 -1
- package/dist-esm/src/index.js +1 -0
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/interfaces.js.map +1 -1
- package/dist-esm/src/urlHelpers.js +4 -1
- package/dist-esm/src/urlHelpers.js.map +1 -1
- package/package.json +3 -2
- package/types/3.1/core-client.d.ts +205 -2
- package/types/latest/core-client.d.ts +206 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
# Release History
|
|
2
2
|
|
|
3
|
-
## 1.
|
|
3
|
+
## 1.4.0 (Unreleased)
|
|
4
4
|
|
|
5
5
|
### Features Added
|
|
6
6
|
|
|
7
|
+
- Added a new function `authorizeRequestOnClaimChallenge`, that can be used with the `@azure/core-rest-pipeline`'s `bearerTokenAuthenticationPolicy` to support [Continuous Access Evaluation (CAE) challenges](https://docs.microsoft.com/azure/active-directory/conditional-access/concept-continuous-access-evaluation).
|
|
8
|
+
- Call the `bearerTokenAuthenticationPolicy` with the following options: `bearerTokenAuthenticationPolicy({ authorizeRequestOnChallenge: authorizeRequestOnClaimChallenge })`. Once provided, the `bearerTokenAuthenticationPolicy` policy will internally handle Continuous Access Evaluation (CAE) challenges. When it can't complete a challenge it will return the 401 (unauthorized) response from ARM.
|
|
9
|
+
|
|
7
10
|
### Breaking Changes
|
|
8
11
|
|
|
9
12
|
### Bugs Fixed
|
|
10
13
|
|
|
11
14
|
### Other Changes
|
|
12
15
|
|
|
16
|
+
## 1.3.3 (2021-12-02)
|
|
17
|
+
|
|
18
|
+
### Bugs Fixed
|
|
19
|
+
|
|
20
|
+
- Added a check to handle undefined value during the parsing of query parameters. Please refer to [PR #18621](https://github.com/Azure/azure-sdk-for-js/pull/18621) for further details.
|
|
21
|
+
|
|
13
22
|
## 1.3.2 (2021-10-25)
|
|
14
23
|
|
|
15
24
|
### Bugs Fixed
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Azure Core Service client library for JavaScript
|
|
1
|
+
# Azure Core Service client library for JavaScript
|
|
2
2
|
|
|
3
3
|
This library is primarily intended to be used in code generated by [AutoRest](https://github.com/Azure/Autorest) and [`autorest.typescript`](https://github.com/Azure/autorest.typescript).
|
|
4
4
|
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var coreRestPipeline = require('@azure/core-rest-pipeline');
|
|
6
|
+
var logger = require('@azure/logger');
|
|
6
7
|
require('@azure/core-asynciterator-polyfill');
|
|
7
8
|
|
|
8
9
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -140,6 +141,14 @@ function encodeByteArray(value) {
|
|
|
140
141
|
function decodeString(value) {
|
|
141
142
|
return Buffer.from(value, "base64");
|
|
142
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Decodes a base64 string into a string.
|
|
146
|
+
* @param value - the base64 string to decode
|
|
147
|
+
* @internal
|
|
148
|
+
*/
|
|
149
|
+
function decodeStringToString(value) {
|
|
150
|
+
return Buffer.from(value, "base64").toString();
|
|
151
|
+
}
|
|
143
152
|
|
|
144
153
|
// Copyright (c) Microsoft Corporation.
|
|
145
154
|
// Licensed under the MIT license.
|
|
@@ -1346,12 +1355,15 @@ function appendQueryParams(url, queryParams, sequenceParams, noOverwrite = false
|
|
|
1346
1355
|
if (typeof value === "string") {
|
|
1347
1356
|
searchPieces.push(`${name}=${value}`);
|
|
1348
1357
|
}
|
|
1349
|
-
else {
|
|
1358
|
+
else if (Array.isArray(value)) {
|
|
1350
1359
|
// QUIRK: If we get an array of values, include multiple key/value pairs
|
|
1351
1360
|
for (const subValue of value) {
|
|
1352
1361
|
searchPieces.push(`${name}=${subValue}`);
|
|
1353
1362
|
}
|
|
1354
1363
|
}
|
|
1364
|
+
else {
|
|
1365
|
+
searchPieces.push(`${name}=${value}`);
|
|
1366
|
+
}
|
|
1355
1367
|
}
|
|
1356
1368
|
// QUIRK: we have to set search manually as searchParams will encode comma when it shouldn't.
|
|
1357
1369
|
parsedUrl.search = searchPieces.length ? `?${searchPieces.join("&")}` : "";
|
|
@@ -1883,10 +1895,78 @@ function getCredentialScopes(options) {
|
|
|
1883
1895
|
return undefined;
|
|
1884
1896
|
}
|
|
1885
1897
|
|
|
1898
|
+
// Copyright (c) Microsoft Corporation.
|
|
1899
|
+
const defaultLogger = logger.createClientLogger("authorizeRequestOnClaimChallenge");
|
|
1900
|
+
/**
|
|
1901
|
+
* Converts: `Bearer a="b", c="d", Bearer d="e", f="g"`.
|
|
1902
|
+
* Into: `[ { a: 'b', c: 'd' }, { d: 'e', f: 'g' } ]`.
|
|
1903
|
+
*
|
|
1904
|
+
* @internal
|
|
1905
|
+
*/
|
|
1906
|
+
function parseCAEChallenge(challenges) {
|
|
1907
|
+
const bearerChallenges = `, ${challenges.trim()}`.split(", Bearer ").filter((x) => x);
|
|
1908
|
+
return bearerChallenges.map((challenge) => {
|
|
1909
|
+
const challengeParts = `${challenge.trim()}, `.split('", ').filter((x) => x);
|
|
1910
|
+
const keyValuePairs = challengeParts.map((keyValue) => (([key, value]) => ({ [key]: value }))(keyValue.trim().split('="')));
|
|
1911
|
+
// Key-value pairs to plain object:
|
|
1912
|
+
return keyValuePairs.reduce((a, b) => (Object.assign(Object.assign({}, a), b)), {});
|
|
1913
|
+
});
|
|
1914
|
+
}
|
|
1915
|
+
/**
|
|
1916
|
+
* This function can be used as a callback for the `bearerTokenAuthenticationPolicy` of `@azure/core-rest-pipeline`, to support CAE challenges:
|
|
1917
|
+
* [Continuous Access Evaluation](https://docs.microsoft.com/azure/active-directory/conditional-access/concept-continuous-access-evaluation).
|
|
1918
|
+
*
|
|
1919
|
+
* Call the `bearerTokenAuthenticationPolicy` with the following options:
|
|
1920
|
+
*
|
|
1921
|
+
* ```ts
|
|
1922
|
+
* import { bearerTokenAuthenticationPolicy } from "@azure/core-rest-pipeline";
|
|
1923
|
+
* import { authorizeRequestOnClaimChallenge } from "@azure/core-client";
|
|
1924
|
+
*
|
|
1925
|
+
* const bearerTokenAuthenticationPolicy = bearerTokenAuthenticationPolicy({
|
|
1926
|
+
* authorizeRequestOnChallenge: authorizeRequestOnClaimChallenge
|
|
1927
|
+
* });
|
|
1928
|
+
* ```
|
|
1929
|
+
*
|
|
1930
|
+
* Once provided, the `bearerTokenAuthenticationPolicy` policy will internally handle Continuous Access Evaluation (CAE) challenges.
|
|
1931
|
+
* When it can't complete a challenge it will return the 401 (unauthorized) response from ARM.
|
|
1932
|
+
*
|
|
1933
|
+
* Example challenge with claims:
|
|
1934
|
+
*
|
|
1935
|
+
* ```
|
|
1936
|
+
* Bearer authorization_uri="https://login.windows-ppe.net/", error="invalid_token",
|
|
1937
|
+
* error_description="User session has been revoked",
|
|
1938
|
+
* claims="eyJhY2Nlc3NfdG9rZW4iOnsibmJmIjp7ImVzc2VudGlhbCI6dHJ1ZSwgInZhbHVlIjoiMTYwMzc0MjgwMCJ9fX0="
|
|
1939
|
+
* ```
|
|
1940
|
+
*/
|
|
1941
|
+
async function authorizeRequestOnClaimChallenge(onChallengeOptions) {
|
|
1942
|
+
const { scopes, response } = onChallengeOptions;
|
|
1943
|
+
const logger = onChallengeOptions.logger || defaultLogger;
|
|
1944
|
+
const challenge = response.headers.get("WWW-Authenticate");
|
|
1945
|
+
if (!challenge) {
|
|
1946
|
+
logger.info(`The WWW-Authenticate header was missing. Failed to perform the Continuous Access Evaluation authentication flow.`);
|
|
1947
|
+
return false;
|
|
1948
|
+
}
|
|
1949
|
+
const challenges = parseCAEChallenge(challenge) || [];
|
|
1950
|
+
const parsedChallenge = challenges.find((x) => x.claims);
|
|
1951
|
+
if (!parsedChallenge) {
|
|
1952
|
+
logger.info(`The WWW-Authenticate header was missing the necessary "claims" to perform the Continuous Access Evaluation authentication flow.`);
|
|
1953
|
+
return false;
|
|
1954
|
+
}
|
|
1955
|
+
const accessToken = await onChallengeOptions.getAccessToken(parsedChallenge.scope ? [parsedChallenge.scope] : scopes, {
|
|
1956
|
+
claims: decodeStringToString(parsedChallenge.claims)
|
|
1957
|
+
});
|
|
1958
|
+
if (!accessToken) {
|
|
1959
|
+
return false;
|
|
1960
|
+
}
|
|
1961
|
+
onChallengeOptions.request.headers.set("Authorization", `Bearer ${accessToken.token}`);
|
|
1962
|
+
return true;
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1886
1965
|
exports.MapperTypeNames = MapperTypeNames;
|
|
1887
1966
|
exports.ServiceClient = ServiceClient;
|
|
1888
1967
|
exports.XML_ATTRKEY = XML_ATTRKEY;
|
|
1889
1968
|
exports.XML_CHARKEY = XML_CHARKEY;
|
|
1969
|
+
exports.authorizeRequestOnClaimChallenge = authorizeRequestOnClaimChallenge;
|
|
1890
1970
|
exports.createClientPipeline = createClientPipeline;
|
|
1891
1971
|
exports.createSerializer = createSerializer;
|
|
1892
1972
|
exports.deserializationPolicy = deserializationPolicy;
|