@azure/keyvault-admin 4.3.0-alpha.20220520.1 → 4.3.0
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/README.md +25 -145
- package/dist/index.js +53 -29
- package/dist/index.js.map +1 -1
- package/dist-esm/keyvault-admin/src/accessControlClient.js +8 -6
- package/dist-esm/keyvault-admin/src/accessControlClient.js.map +1 -1
- package/dist-esm/keyvault-admin/src/accessControlModels.js.map +1 -1
- package/dist-esm/keyvault-admin/src/backupClient.js +7 -5
- package/dist-esm/keyvault-admin/src/backupClient.js.map +1 -1
- package/dist-esm/keyvault-admin/src/backupClientModels.js.map +1 -1
- package/dist-esm/keyvault-admin/src/constants.js +1 -5
- package/dist-esm/keyvault-admin/src/constants.js.map +1 -1
- package/dist-esm/keyvault-admin/src/generated/keyVaultClientContext.js +1 -1
- package/dist-esm/keyvault-admin/src/generated/keyVaultClientContext.js.map +1 -1
- package/dist-esm/keyvault-common/src/challengeBasedAuthenticationPolicy.js +82 -146
- package/dist-esm/keyvault-common/src/challengeBasedAuthenticationPolicy.js.map +1 -1
- package/package.json +4 -4
- package/types/keyvault-admin.d.ts +13 -3
- package/dist-esm/keyvault-admin/src/challengeAuthenticationCallbacks.js +0 -81
- package/dist-esm/keyvault-admin/src/challengeAuthenticationCallbacks.js.map +0 -1
package/README.md
CHANGED
|
@@ -26,110 +26,6 @@ Install the Azure Key Vault administration client library for JavaScript and Typ
|
|
|
26
26
|
npm install @azure/keyvault-admin
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
### Currently supported environments
|
|
30
|
-
|
|
31
|
-
- [LTS versions of Node.js](https://nodejs.org/about/releases/)
|
|
32
|
-
|
|
33
|
-
### Prerequisites
|
|
34
|
-
|
|
35
|
-
- An [Azure subscription](https://azure.microsoft.com/free/)
|
|
36
|
-
- A [Key Vault resource](https://docs.microsoft.com/azure/key-vault/quick-create-portal)
|
|
37
|
-
|
|
38
|
-
#### Getting Azure credentials
|
|
39
|
-
|
|
40
|
-
Use the [Azure CLI][azure-cli] snippet below to create/get client secret credentials.
|
|
41
|
-
|
|
42
|
-
- Create a service principal and configure its access to Azure resources:
|
|
43
|
-
```PowerShell
|
|
44
|
-
az ad sp create-for-rbac -n <your-application-name> --skip-assignment
|
|
45
|
-
```
|
|
46
|
-
Output:
|
|
47
|
-
```json
|
|
48
|
-
{
|
|
49
|
-
"appId": "generated-app-ID",
|
|
50
|
-
"displayName": "some-app-name",
|
|
51
|
-
"name": "http://some-app-name",
|
|
52
|
-
"password": "random-password",
|
|
53
|
-
"tenant": "tenant-ID"
|
|
54
|
-
}
|
|
55
|
-
```
|
|
56
|
-
- Take note of the service principal objectId
|
|
57
|
-
```PowerShell
|
|
58
|
-
az ad sp show --id <appId> --query objectId
|
|
59
|
-
```
|
|
60
|
-
Output:
|
|
61
|
-
```
|
|
62
|
-
"<your-service-principal-object-id>"
|
|
63
|
-
```
|
|
64
|
-
- Use the returned credentials above to set **AZURE_CLIENT_ID** (appId), **AZURE_CLIENT_SECRET** (password), and **AZURE_TENANT_ID** (tenant) environment variables.
|
|
65
|
-
|
|
66
|
-
#### Get or create an Azure Managed HSM with the Azure CLI
|
|
67
|
-
|
|
68
|
-
- Create the Managed HSM and grant the above mentioned service principal authorization to perform administrative operations on the Azure Key Vault (replace `<your-resource-group-name>` and `<your-key-vault-name>` with your own, unique names and `<your-service-principal-object-id>` with the value from above):
|
|
69
|
-
|
|
70
|
-
```PowerShell
|
|
71
|
-
az keyvault create --hsm-name <your-key-vault-name> --resource-group <your-resource-group-name> --administrators <your-service-principal-object-id> --location <your-azure-location>
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
This service principal is automatically added to the "Managed HSM Administrators" [built-in role][built_in_roles].
|
|
75
|
-
|
|
76
|
-
- Use the above mentioned Azure Key Vault name to retrieve details of your Vault which also contains your Azure Key Vault URL:
|
|
77
|
-
```PowerShell
|
|
78
|
-
az keyvault show --hsm-name <your-key-vault-name>
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
#### Activate your managed HSM
|
|
82
|
-
|
|
83
|
-
All data plane commands are disabled until the HSM is activated. You will not be able to create keys or assign roles. Only the designated administrators that were assigned during the create command can activate the HSM. To activate the HSM you must download the security domain.
|
|
84
|
-
|
|
85
|
-
To activate your HSM you need:
|
|
86
|
-
|
|
87
|
-
- Minimum 3 RSA key-pairs (maximum 10)
|
|
88
|
-
- Specify minimum number of keys required to decrypt the security domain (quorum)
|
|
89
|
-
|
|
90
|
-
To activate the HSM you send at least 3 (maximum 10) RSA public keys to the HSM. The HSM encrypts the security domain with these keys and sends it back. Once this security domain is successfully downloaded, your HSM is ready to use. You also need to specify quorum, which is the minimum number of private keys required to decrypt the security domain.
|
|
91
|
-
|
|
92
|
-
The example below shows how to use openssl to generate 3 self signed certificate.
|
|
93
|
-
|
|
94
|
-
```PowerShell
|
|
95
|
-
openssl req -newkey rsa:2048 -nodes -keyout cert_0.key -x509 -days 365 -out cert_0.cer
|
|
96
|
-
openssl req -newkey rsa:2048 -nodes -keyout cert_1.key -x509 -days 365 -out cert_1.cer
|
|
97
|
-
openssl req -newkey rsa:2048 -nodes -keyout cert_2.key -x509 -days 365 -out cert_2.cer
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
Use the az keyvault security-domain download command to download the security domain and activate your managed HSM. The example below, uses 3 RSA key pairs (only public keys are needed for this command) and sets the quorum to 2.
|
|
101
|
-
|
|
102
|
-
```PowerShell
|
|
103
|
-
az keyvault security-domain download --hsm-name <your-key-vault-name> --sd-wrapping-keys ./certs/cert_0.cer ./certs/cert_1.cer ./certs/cert_2.cer --sd-quorum 2 --security-domain-file ContosoMHSM-SD.json
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
#### Controlling access to your managed HSM
|
|
107
|
-
|
|
108
|
-
The designated administrators assigned during creation are automatically added to the "Managed HSM Administrators" [built-in role][built_in_roles],
|
|
109
|
-
who are able to download a security domain and [manage roles for data plane access][access_control], among other limited permissions.
|
|
110
|
-
|
|
111
|
-
To perform other actions on keys, you need to assign principals to other roles such as "Managed HSM Crypto User", which can perform non-destructive key operations:
|
|
112
|
-
|
|
113
|
-
```PowerShell
|
|
114
|
-
az keyvault role assignment create --hsm-name <your-key-vault-name> --role "Managed HSM Crypto User" --scope / --assignee-object-id <principal-or-user-object-ID> --assignee-principal-type <principal-type>
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
Please read [best practices][best_practices] for properly securing your managed HSM.
|
|
118
|
-
|
|
119
|
-
#### Get or create an Azure Storage Account with the Azure CLI
|
|
120
|
-
|
|
121
|
-
A storage account is necessary to generate the backup of a Key Vault.
|
|
122
|
-
|
|
123
|
-
To generate Key Vault backups, you will need to point the `KeyVaultBackupClient` to an existing Storage account.
|
|
124
|
-
|
|
125
|
-
To create a new Storage Account, you can use the [Azure Portal][storage-account-create-portal],
|
|
126
|
-
[Azure PowerShell][storage-account-create-ps], or the [Azure CLI][storage-account-create-cli].
|
|
127
|
-
Here's an example using the Azure CLI:
|
|
128
|
-
|
|
129
|
-
```Powershell
|
|
130
|
-
az storage account create --name MyStorageAccount --resource-group MyResourceGroup --location westus --sku Standard_LRS
|
|
131
|
-
```
|
|
132
|
-
|
|
133
29
|
### Configure TypeScript
|
|
134
30
|
|
|
135
31
|
TypeScript users need to have Node type definitions installed:
|
|
@@ -140,21 +36,24 @@ npm install @types/node
|
|
|
140
36
|
|
|
141
37
|
You also need to enable `compilerOptions.allowSyntheticDefaultImports` in your tsconfig.json. Note that if you have enabled `compilerOptions.esModuleInterop`, `allowSyntheticDefaultImports` is enabled by default. See [TypeScript's compiler options handbook][compiler-options] for more information.
|
|
142
38
|
|
|
143
|
-
###
|
|
39
|
+
### Currently supported environments
|
|
40
|
+
|
|
41
|
+
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
|
|
42
|
+
|
|
43
|
+
### Prerequisites
|
|
144
44
|
|
|
145
|
-
|
|
45
|
+
- An [Azure subscription](https://azure.microsoft.com/free/)
|
|
46
|
+
- An existing [Key Vault Managed HSM][azure_keyvault_mhsm]. If you need to create a Managed HSM, you can do so using the Azure CLI by following the steps in [this document][azure_keyvault_mhsm_cli].
|
|
146
47
|
|
|
147
|
-
|
|
48
|
+
## Authenticate the client
|
|
148
49
|
|
|
149
|
-
In the
|
|
50
|
+
In order to interact with the Azure Key Vault service, you will need to create an instance of either the [`KeyVaultAccessControlClient`](#create-keyvaultaccesscontrolclient) class or the [`KeyVaultBackupClient`](#create-keyvaultbackupclient) class, as well as a **vault url** (which you may see as "DNS Name" in the Azure Portal) and a credential object. The examples shown in this document use a credential object named [`DefaultAzureCredential`][default_azure_credential], which is appropriate for most scenarios, including local development and production environments. Additionally, we recommend using a [managed identity][managed_identity] for authentication in production environments.
|
|
150
51
|
|
|
151
|
-
|
|
152
|
-
npm install @azure/identity
|
|
153
|
-
```
|
|
52
|
+
You can find more information on different ways of authenticating and their corresponding credential types in the [Azure Identity documentation][azure_identity].
|
|
154
53
|
|
|
155
|
-
|
|
54
|
+
### Create KeyVaultAccessControlClient
|
|
156
55
|
|
|
157
|
-
Once you've
|
|
56
|
+
Once you've authenticated with [the authentication method that suits you best][default_azure_credential], you can create a `KeyVaultAccessControlClient` as follows, substituting in your Managed HSM URL in the constructor:
|
|
158
57
|
|
|
159
58
|
```javascript
|
|
160
59
|
const { DefaultAzureCredential } = require("@azure/identity");
|
|
@@ -162,13 +61,12 @@ const { KeyVaultAccessControlClient } = require("@azure/keyvault-admin");
|
|
|
162
61
|
|
|
163
62
|
const credentials = new DefaultAzureCredential();
|
|
164
63
|
|
|
165
|
-
const
|
|
166
|
-
const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
|
|
64
|
+
const client = new KeyVaultAccessControlClient(`<your Managed HSM URL>`, credentials);
|
|
167
65
|
```
|
|
168
66
|
|
|
169
|
-
|
|
67
|
+
### Create KeyVaultBackupClient
|
|
170
68
|
|
|
171
|
-
Once you've
|
|
69
|
+
Once you've authenticated with [the authentication method that suits you best][default_azure_credential], you can create a `KeyVaultBackupClient` as follows, substituting in your Managed HSM URL in the constructor:
|
|
172
70
|
|
|
173
71
|
```javascript
|
|
174
72
|
const { DefaultAzureCredential } = require("@azure/identity");
|
|
@@ -176,8 +74,7 @@ const { KeyVaultBackupClient } = require("@azure/keyvault-admin");
|
|
|
176
74
|
|
|
177
75
|
const credentials = new DefaultAzureCredential();
|
|
178
76
|
|
|
179
|
-
const
|
|
180
|
-
const client = new KeyVaultBackupClient(vaultUrl, credentials);
|
|
77
|
+
const client = new KeyVaultBackupClient(`<your Managed HSM URL>`, credentials);
|
|
181
78
|
```
|
|
182
79
|
|
|
183
80
|
## Key concepts
|
|
@@ -188,7 +85,7 @@ A Role Definition is a collection of permissions. A role definition defines the
|
|
|
188
85
|
|
|
189
86
|
Role definitions can be listed and specified as part of a `KeyVaultRoleAssignment`.
|
|
190
87
|
|
|
191
|
-
### KeyVaultRoleAssignment
|
|
88
|
+
### KeyVaultRoleAssignment
|
|
192
89
|
|
|
193
90
|
A Role Assignment is the association of a Role Definition to a service principal. They can be created, listed, fetched individually, and deleted.
|
|
194
91
|
|
|
@@ -235,9 +132,9 @@ setLogLevel("info");
|
|
|
235
132
|
|
|
236
133
|
You can find more code samples through the following links:
|
|
237
134
|
|
|
238
|
-
- [
|
|
239
|
-
- [
|
|
240
|
-
- [
|
|
135
|
+
- [Key Vault Administration Samples (JavaScript)](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/keyvault/keyvault-admin/samples/v4/javascript)
|
|
136
|
+
- [Key Vault Administration Samples (TypeScript)](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/keyvault/keyvault-admin/samples/v4/typescript)
|
|
137
|
+
- [Key Vault Administration Test Cases](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/keyvault/keyvault-admin/test/)
|
|
241
138
|
|
|
242
139
|
## Contributing
|
|
243
140
|
|
|
@@ -247,34 +144,17 @@ If you'd like to contribute to this library, please read the [contributing guide
|
|
|
247
144
|
|
|
248
145
|
<!-- LINKS -->
|
|
249
146
|
|
|
250
|
-
[dac]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/README.md
|
|
251
|
-
[jwk]: https://tools.ietf.org/html/rfc7517
|
|
252
|
-
[access_control]: https://docs.microsoft.com/azure/key-vault/managed-hsm/access-control
|
|
253
|
-
[api-rest]: https://docs.microsoft.com/rest/api/keyvault/
|
|
254
|
-
[azure-cli]: https://docs.microsoft.com/cli/azure
|
|
255
|
-
[azure-identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity
|
|
256
|
-
[azure-sub]: https://azure.microsoft.com/free/
|
|
257
|
-
[backup_client]: ./src/KeyVaultBackupClient.cs
|
|
258
|
-
[best_practices]: https://docs.microsoft.com/azure/key-vault/managed-hsm/best-practices
|
|
259
|
-
[built_in_roles]: https://docs.microsoft.com/azure/key-vault/managed-hsm/built-in-roles
|
|
260
|
-
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
|
|
261
147
|
[compiler-options]: https://www.typescriptlang.org/docs/handbook/compiler-options.html
|
|
262
148
|
[core-lro]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/core-lro
|
|
263
|
-
[docs-overview]: https://docs.microsoft.com/azure/key-vault/key-vault-overview
|
|
264
149
|
[docs-service]: https://azure.microsoft.com/services/key-vault/
|
|
265
150
|
[docs]: https://docs.microsoft.com/javascript/api/@azure/keyvault-admin
|
|
266
|
-
|
|
267
|
-
[dotenv]: https://www.npmjs.com/package/dotenv]
|
|
268
|
-
[identity-npm]: https://www.npmjs.com/package/@azure/identity
|
|
269
|
-
[keyvault_docs]: https://docs.microsoft.com/azure/key-vault/
|
|
270
|
-
[logging]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/Diagnostics.ts.com/Azure/azure-sdk-for-net/blob/main/sdk/keyvault/Microsoft.Azure.KeyVault/CONTRIBUTING.md
|
|
271
151
|
[managedhsm]: https://docs.microsoft.com/azure/key-vault/managed-hsm/overview
|
|
272
152
|
[npm]: https://www.npmjs.com/
|
|
273
153
|
[package-gh]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/keyvault/keyvault-admin
|
|
274
154
|
[package-npm]: https://www.npmjs.com/package/@azure/keyvault-admin
|
|
275
155
|
[samples]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/keyvault/keyvault-admin/samples
|
|
276
|
-
[
|
|
277
|
-
[
|
|
278
|
-
[
|
|
279
|
-
|
|
280
|
-
|
|
156
|
+
[azure_keyvault_mhsm]: https://docs.microsoft.com/azure/key-vault/managed-hsm/overview
|
|
157
|
+
[azure_keyvault_mhsm_cli]: https://docs.microsoft.com/azure/key-vault/managed-hsm/quick-create-cli
|
|
158
|
+
[default_azure_credential]: https://docs.microsoft.com/java/api/overview/azure/identity-readme?view=azure-java-stable#defaultazurecredential
|
|
159
|
+
[managed_identity]: https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/overview
|
|
160
|
+
[azure_identity]: https://docs.microsoft.com/java/api/overview/azure/identity-readme?view=azure-java-stable
|
package/dist/index.js
CHANGED
|
@@ -30,21 +30,6 @@ function _interopNamespace(e) {
|
|
|
30
30
|
|
|
31
31
|
var coreClient__namespace = /*#__PURE__*/_interopNamespace(coreClient);
|
|
32
32
|
|
|
33
|
-
// Copyright (c) Microsoft Corporation.
|
|
34
|
-
// Licensed under the MIT license.
|
|
35
|
-
/**
|
|
36
|
-
* Current version of the Key Vault Admin SDK.
|
|
37
|
-
*/
|
|
38
|
-
const SDK_VERSION = "4.3.0-beta.1";
|
|
39
|
-
/**
|
|
40
|
-
* The latest supported Key Vault service API version.
|
|
41
|
-
*/
|
|
42
|
-
const LATEST_API_VERSION = "7.3";
|
|
43
|
-
/**
|
|
44
|
-
* Authentication scopes
|
|
45
|
-
*/
|
|
46
|
-
const authenticationScopes = ["https://managedhsm.azure.net/.default"];
|
|
47
|
-
|
|
48
33
|
/*
|
|
49
34
|
* Copyright (c) Microsoft Corporation.
|
|
50
35
|
* Licensed under the MIT License.
|
|
@@ -1260,7 +1245,7 @@ class KeyVaultClientContext extends coreClient__namespace.ServiceClient {
|
|
|
1260
1245
|
const defaults = {
|
|
1261
1246
|
requestContentType: "application/json; charset=utf-8"
|
|
1262
1247
|
};
|
|
1263
|
-
const packageDetails = `azsdk-js-keyvault-admin/4.3.0
|
|
1248
|
+
const packageDetails = `azsdk-js-keyvault-admin/4.3.0`;
|
|
1264
1249
|
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
1265
1250
|
? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
|
|
1266
1251
|
: `${packageDetails}`;
|
|
@@ -1430,6 +1415,17 @@ const selectiveKeyRestoreOperationOperationSpec = {
|
|
|
1430
1415
|
serializer
|
|
1431
1416
|
};
|
|
1432
1417
|
|
|
1418
|
+
// Copyright (c) Microsoft Corporation.
|
|
1419
|
+
// Licensed under the MIT license.
|
|
1420
|
+
/**
|
|
1421
|
+
* Current version of the Key Vault Admin SDK.
|
|
1422
|
+
*/
|
|
1423
|
+
const SDK_VERSION = "4.3.0";
|
|
1424
|
+
/**
|
|
1425
|
+
* The latest supported Key Vault service API version.
|
|
1426
|
+
*/
|
|
1427
|
+
const LATEST_API_VERSION = "7.3";
|
|
1428
|
+
|
|
1433
1429
|
// Copyright (c) Microsoft Corporation.
|
|
1434
1430
|
// Licensed under the MIT license.
|
|
1435
1431
|
/**
|
|
@@ -1483,6 +1479,19 @@ function parseWWWAuthenticate(wwwAuthenticate) {
|
|
|
1483
1479
|
}
|
|
1484
1480
|
|
|
1485
1481
|
// Copyright (c) Microsoft Corporation.
|
|
1482
|
+
function verifyChallengeResource(scope, request) {
|
|
1483
|
+
let scopeAsUrl;
|
|
1484
|
+
try {
|
|
1485
|
+
scopeAsUrl = new URL(scope);
|
|
1486
|
+
}
|
|
1487
|
+
catch (e) {
|
|
1488
|
+
throw new Error(`The challenge contains invalid scope '${scope}'`);
|
|
1489
|
+
}
|
|
1490
|
+
const requestUrl = new URL(request.url);
|
|
1491
|
+
if (!requestUrl.hostname.endsWith(`.${scopeAsUrl.hostname}`)) {
|
|
1492
|
+
throw new Error(`The challenge resource '${scopeAsUrl.hostname}' does not match the requested domain. Set disableChallengeResourceVerification to true in your client options to disable. See https://aka.ms/azsdk/blog/vault-uri for more information.`);
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1486
1495
|
/**
|
|
1487
1496
|
* @internal
|
|
1488
1497
|
*
|
|
@@ -1496,8 +1505,9 @@ function parseWWWAuthenticate(wwwAuthenticate) {
|
|
|
1496
1505
|
*
|
|
1497
1506
|
* Following the first request of a client, follow-up requests will get the cached token
|
|
1498
1507
|
* if possible.
|
|
1508
|
+
*
|
|
1499
1509
|
*/
|
|
1500
|
-
function createChallengeCallbacks() {
|
|
1510
|
+
function createChallengeCallbacks({ disableChallengeResourceVerification, } = {}) {
|
|
1501
1511
|
let challengeState = { status: "none" };
|
|
1502
1512
|
function requestToOptions(request) {
|
|
1503
1513
|
return {
|
|
@@ -1509,7 +1519,7 @@ function createChallengeCallbacks() {
|
|
|
1509
1519
|
};
|
|
1510
1520
|
}
|
|
1511
1521
|
async function authorizeRequest(options) {
|
|
1512
|
-
const {
|
|
1522
|
+
const { request } = options;
|
|
1513
1523
|
const requestOptions = requestToOptions(request);
|
|
1514
1524
|
switch (challengeState.status) {
|
|
1515
1525
|
case "none":
|
|
@@ -1522,7 +1532,7 @@ function createChallengeCallbacks() {
|
|
|
1522
1532
|
case "started":
|
|
1523
1533
|
break; // Retry, we should not overwrite the original body
|
|
1524
1534
|
case "complete": {
|
|
1525
|
-
const token = await options.getAccessToken(scopes, requestOptions);
|
|
1535
|
+
const token = await options.getAccessToken(challengeState.scopes, requestOptions);
|
|
1526
1536
|
if (token) {
|
|
1527
1537
|
request.headers.set("authorization", `Bearer ${token.token}`);
|
|
1528
1538
|
}
|
|
@@ -1532,7 +1542,7 @@ function createChallengeCallbacks() {
|
|
|
1532
1542
|
return Promise.resolve();
|
|
1533
1543
|
}
|
|
1534
1544
|
async function authorizeRequestOnChallenge(options) {
|
|
1535
|
-
const {
|
|
1545
|
+
const { request, response } = options;
|
|
1536
1546
|
if (request.body === null && challengeState.status === "started") {
|
|
1537
1547
|
// Reset the original body before doing anything else.
|
|
1538
1548
|
// Note: If successful status will be "complete", otherwise "none" will
|
|
@@ -1544,14 +1554,24 @@ function createChallengeCallbacks() {
|
|
|
1544
1554
|
if (!challenge) {
|
|
1545
1555
|
throw new Error("Missing challenge.");
|
|
1546
1556
|
}
|
|
1547
|
-
const parsedChallenge = parseWWWAuthenticate(challenge) ||
|
|
1548
|
-
const
|
|
1557
|
+
const parsedChallenge = parseWWWAuthenticate(challenge) || {};
|
|
1558
|
+
const scope = parsedChallenge.resource
|
|
1559
|
+
? parsedChallenge.resource + "/.default"
|
|
1560
|
+
: parsedChallenge.scope;
|
|
1561
|
+
if (!scope) {
|
|
1562
|
+
throw new Error("Missing scope.");
|
|
1563
|
+
}
|
|
1564
|
+
if (!disableChallengeResourceVerification) {
|
|
1565
|
+
verifyChallengeResource(scope, request);
|
|
1566
|
+
}
|
|
1567
|
+
const accessToken = await options.getAccessToken([scope], Object.assign(Object.assign({}, getTokenOptions), { tenantId: parsedChallenge.tenantId }));
|
|
1549
1568
|
if (!accessToken) {
|
|
1550
1569
|
return false;
|
|
1551
1570
|
}
|
|
1552
1571
|
options.request.headers.set("Authorization", `Bearer ${accessToken.token}`);
|
|
1553
1572
|
challengeState = {
|
|
1554
1573
|
status: "complete",
|
|
1574
|
+
scopes: [scope],
|
|
1555
1575
|
};
|
|
1556
1576
|
return true;
|
|
1557
1577
|
}
|
|
@@ -1642,9 +1662,9 @@ class KeyVaultAccessControlClient {
|
|
|
1642
1662
|
*
|
|
1643
1663
|
* let client = new KeyVaultAccessControlClient(vaultUrl, credentials);
|
|
1644
1664
|
* ```
|
|
1645
|
-
* @param vaultUrl - the URL of the Key Vault. It should have this shape: `https://${your-key-vault-name}.vault.azure.net
|
|
1665
|
+
* @param vaultUrl - the URL of the Key Vault. It should have this shape: `https://${your-key-vault-name}.vault.azure.net`. You should validate that this URL references a valid Key Vault or Managed HSM resource. See https://aka.ms/azsdk/blog/vault-uri for details.
|
|
1646
1666
|
* @param credential - An object that implements the `TokenCredential` interface used to authenticate requests to the service. Use the \@azure/identity package to create a credential that suits your needs.
|
|
1647
|
-
* @param
|
|
1667
|
+
* @param options - Options used to configure Key Vault API requests. Omit this parameter to use the default configuration.
|
|
1648
1668
|
*/
|
|
1649
1669
|
constructor(vaultUrl, credential, options = {}) {
|
|
1650
1670
|
this.vaultUrl = vaultUrl;
|
|
@@ -1660,8 +1680,10 @@ class KeyVaultAccessControlClient {
|
|
|
1660
1680
|
this.client = new KeyVaultClient(serviceVersion, clientOptions);
|
|
1661
1681
|
this.client.pipeline.addPolicy(coreRestPipeline.bearerTokenAuthenticationPolicy({
|
|
1662
1682
|
credential,
|
|
1663
|
-
scopes
|
|
1664
|
-
|
|
1683
|
+
// The scopes will be populated in the challenge callbacks based on the WWW-authenticate header
|
|
1684
|
+
// returned by the challenge, so pass an empty array as a placeholder.
|
|
1685
|
+
scopes: [],
|
|
1686
|
+
challengeCallbacks: createChallengeCallbacks(options),
|
|
1665
1687
|
}));
|
|
1666
1688
|
}
|
|
1667
1689
|
/**
|
|
@@ -2443,7 +2465,7 @@ class KeyVaultBackupClient {
|
|
|
2443
2465
|
*
|
|
2444
2466
|
* let client = new KeyVaultBackupClient(vaultUrl, credentials);
|
|
2445
2467
|
* ```
|
|
2446
|
-
* @param vaultUrl - the URL of the Key Vault. It should have this shape: `https://${your-key-vault-name}.vault.azure.net
|
|
2468
|
+
* @param vaultUrl - the URL of the Key Vault. It should have this shape: `https://${your-key-vault-name}.vault.azure.net`. You should validate that this URL references a valid Key Vault or Managed HSM resource. See https://aka.ms/azsdk/blog/vault-uri for details.
|
|
2447
2469
|
* @param credential - An object that implements the `TokenCredential` interface used to authenticate requests to the service. Use the \@azure/identity package to create a credential that suits your needs.
|
|
2448
2470
|
* @param options - options used to configure Key Vault API requests.
|
|
2449
2471
|
*/
|
|
@@ -2461,8 +2483,10 @@ class KeyVaultBackupClient {
|
|
|
2461
2483
|
this.client = new KeyVaultClient(apiVersion, clientOptions);
|
|
2462
2484
|
this.client.pipeline.addPolicy(coreRestPipeline.bearerTokenAuthenticationPolicy({
|
|
2463
2485
|
credential,
|
|
2464
|
-
scopes
|
|
2465
|
-
|
|
2486
|
+
// The scopes will be populated in the challenge callbacks based on the WWW-authenticate header
|
|
2487
|
+
// returned by the challenge, so pass an empty array as a placeholder.
|
|
2488
|
+
scopes: [],
|
|
2489
|
+
challengeCallbacks: createChallengeCallbacks(options),
|
|
2466
2490
|
}));
|
|
2467
2491
|
}
|
|
2468
2492
|
/**
|