You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/key-vault/quick-create-net-v3.md
+17-4Lines changed: 17 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -149,13 +149,26 @@ This .NET quickstart relies on environment variables to store credentials that s
149
149
150
150
Before you build and run your app, use the `setx` command to set the `akvClientId`, `akvClientSecret`, `akvTenantId`, and `akvSubscriptionId` environment variables to the values you noted above.
151
151
152
+
**Windows**
153
+
152
154
```console
153
-
setx akvClientId <your-clientID>
155
+
setx akvClientId "<your-clientID>"
156
+
setx akvClientSecret "<your-clientSecret>"
157
+
```
158
+
159
+
**Linux**
154
160
155
-
setx akvClientSecret <your-clientSecret>
156
-
````
161
+
```bash
162
+
export akvClientId = "<your-clientID>"
163
+
export akvClientSecret = "<your-clientSecret>"
164
+
```
165
+
166
+
**MacOS**
157
167
158
-
Each time you call `setx`, you should get a response of "SUCCESS: Specified value was saved."
168
+
```bash
169
+
export akvClientId = "<your-clientID>"
170
+
export akvClientSecret = "<your-clientSecret>"
171
+
```
159
172
160
173
Assign these environment variables to strings in your code, and then authenticate your application by passing them to the [KeyVaultClient class](/dotnet/api/microsoft.azure.keyvault.keyvaultclient):
The simplest way to authenticate a cloud-based .NET application is with a managed identity; see [Use an App Service managed identity to access Azure Key Vault](managed-identity.md) for details. For the sake of simplicity however, this quickstart creates a .NET console application. Authenticating a desktop application with Azure requires the use of a service principal and an access control policy.
@@ -109,14 +115,39 @@ This operation will return a series of key / value pairs.
109
115
}
110
116
```
111
117
118
+
Create a service principal using Azure PowerShell [New-AzADServicePrincipal](/powershell/module/az.resources/new-azadserviceprincipal) command:
For more details about the service principal with Azure PowerShell, refer to [Create an Azure service principal with Azure PowerShell](/powershell/azure/create-azure-service-principal-azureps).
137
+
112
138
Take note of the clientId, clientSecret, and tenantId, as we will use them in the following steps.
113
139
140
+
114
141
#### Give the service principal access to your key vault
115
142
116
143
Create an access policy for your key vault that grants permission to your service principal by passing the clientId to the [az keyvault set-policy](/cli/azure/keyvault?view=azure-cli-latest#az-keyvault-set-policy) command. Give the service principal get, list, and set permissions for both keys and secrets.
117
144
118
145
```azurecli
119
-
az keyvault set-policy -n <your-unique-keyvault-name> --spn <clientId-of-your-service-principal> --secret-permissions delete get list set --key-permissions create decrypt delete encrypt get list unwrapKey wrapKey
146
+
az keyvault set-policy -n <your-unique-keyvault-name> --spn <clientId-of-your-service-principal> --secret-permissions list get set delete purge
Each time you call `setx`, you should get a response of "SUCCESS: Specified value was saved."
139
170
171
+
```shell
172
+
AZURE_CLIENT_ID=<your-clientID>
173
+
174
+
AZURE_CLIENT_SECRET=<your-clientSecret>
175
+
176
+
AZURE_TENANT_ID=<your-tenantId>
177
+
178
+
KEY_VAULT_NAME=<your-key-vault-name>
179
+
```
180
+
140
181
## Object model
141
182
142
183
The Azure Key Vault client library for .NET allows you to manage keys and related assets such as certificates and secrets. The code samples below will show you how to create a client, set a secret, retrieve a secret, and delete a secret.
@@ -169,6 +210,10 @@ You can verify that the secret has been set with the [az keyvault secret show](/
169
210
az keyvault secret show --vault-name <your-unique-keyvault-name> --name mySecret
You can now retrieve the previously set value with the [client.GetSecret method](/dotnet/api/microsoft.azure.keyvault.keyvaultclientextensions.getsecretasync).
@@ -189,6 +234,10 @@ You can verify that the secret is gone with the [az keyvault secret show](/cli/a
189
234
az keyvault secret show --vault-name <your-unique-keyvault-name> --name mySecret
0 commit comments