|
| 1 | +--- |
| 2 | +title: include file |
| 3 | +description: include file |
| 4 | +services: cognitive-services |
| 5 | +author: aahill |
| 6 | +ms.service: cognitive-services |
| 7 | +ms.topic: include |
| 8 | +ms.date: 08/25/2022 |
| 9 | +ms.author: aahi |
| 10 | +ms.manager: nitinme |
| 11 | +ms.custom: include |
| 12 | +--- |
| 13 | + |
| 14 | +Before you can grant access to your key vault, you must authenticate with your Azure Active Directory user name and password. |
| 15 | + |
| 16 | +# [Azure CLI](#tab/azure-cli) |
| 17 | + |
| 18 | +To authenticate with the [Azure CLI](/cli/azure), run the `az login` command. |
| 19 | + |
| 20 | +```azurecli-interactive |
| 21 | +az login |
| 22 | +``` |
| 23 | + |
| 24 | +On systems with a default web browser, the Azure CLI will launch the browser to authenticate. For systems without a default web browser, the `az login` command will use the device code authentication flow. You can also force the Azure CLI to use the device code flow rather than launching a browser by specifying the `--use-device-code` argument. |
| 25 | + |
| 26 | +If you have multiple subscriptions, make sure to [select the Azure subscription](/cli/azure/manage-azure-subscriptions-azure-cli#change-the-active-subscription) that contains your key vault. |
| 27 | + |
| 28 | +# [PowerShell](#tab/powershell) |
| 29 | + |
| 30 | +You can also use [Azure PowerShell](/powershell/azure) to authenticate. Applications using the `DefaultAzureCredential` or the `AzurePowerShellCredential` can then use this account to authenticate calls in their application when running locally. |
| 31 | + |
| 32 | +To authenticate with Azure PowerShell, run the `Connect-AzAccount` command. If you're running on a system with a default web browser and Azure PowerShell `v5.0.0` or later, it will launch the browser to authenticate the user. |
| 33 | + |
| 34 | +For systems without a default web browser, the `Connect-AzAccount` command will use the device code authentication flow. You can also force Azure PowerShell to use the device code flow rather than launching a browser by specifying the `UseDeviceAuthentication` argument. |
| 35 | + |
| 36 | +```powershell |
| 37 | +Connect-AzAccount |
| 38 | +``` |
| 39 | + |
| 40 | +If you have multiple subscriptions, make sure to [select the Azure subscription](/powershell/azure/manage-subscriptions-azureps) that contains your key vault. |
| 41 | + |
| 42 | +--- |
| 43 | + |
| 44 | +## Grant access to your key vault |
| 45 | + |
| 46 | +Create an access policy for your key vault that grants secret permissions to your user account. |
| 47 | + |
| 48 | +# [Azure CLI](#tab/azure-cli) |
| 49 | + |
| 50 | +To set the access policy, run the [az keyvault set-policy ](/cli/azure/keyvault#az-keyvault-set-policy) command. Replace `Your-Key-Vault-Name` with the name of your key vault. Replace `[email protected]` with your Azure Active Directory user name. |
| 51 | + |
| 52 | +```azurecli-interactive |
| 53 | +az keyvault set-policy --name Your-Key-Vault-Name --upn [email protected] --secret-permissions delete get list set purge |
| 54 | +``` |
| 55 | + |
| 56 | +# [PowerShell](#tab/powershell) |
| 57 | + |
| 58 | +To set the access policy, run the [Set-AzKeyVaultAccessPolicy ](/powershell/module/az.accounts/set-azcontext) command. Replace `Your-Key-Vault-Name` with the name of your key vault. Replace `[email protected]` with your Azure Active Directory user name. |
| 59 | + |
| 60 | +```powershell |
| 61 | +Set-AzKeyVaultAccessPolicy -VaultName 'Your-Key-Vault-Name' -UserPrincipalName '[email protected]' -PermissionsToSecrets delete,get,list,set,purge -PassThru |
| 62 | +``` |
| 63 | + |
| 64 | +--- |
0 commit comments