gpt4 book ai didi

azure - 如何注册我在 Azure Active Directory 中创建的本地应用程序?

转载 作者:行者123 更新时间:2023-12-03 05:47:55 24 4
gpt4 key购买 nike

我正在按照此处的说明学习 AzureKeyVault 配置设置

Key Vault Configuration Provider sample application (ASP.NET Core 2.x)

This sample illustrates the use of the Azure Key Vault Configuration Provider for ASP.NET Core 2.x. For the ASP.NET Core 1.x sample, see Key Vault Configuration Provider sample application (ASP.NET Core 1.x).

For more information on how the sample works, see the Azure Key Vault configuration provider topic.

Using the sample

  1. Create a key vault and set up Azure Active Directory (Azure AD) for the application following the guidance in Get started with Azure Key Vault.

    • Add secrets to the key vault using the AzureRM Key Vault PowerShell Module available from the PowerShell Gallery, the Azure Key Vault REST API, or the Azure Portal. Secrets are created as either Manual or Certificate secrets. Certificate secrets are certificates for use by apps and services but are not supported by the configuration provider. You should use the Manual option to create name-value pair secrets for use with the configuration provider.
      • Simple secrets are created as name-value pairs. Azure Key Vault secret names are limited to alphanumeric characters and dashes.
      • Hierarchical values (configuration sections) use -- (two dashes) as a separator in the sample. Colons, which are normally used to delimit a section from a subkey in ASP.NET Core configuration, aren't allowed in secret names. Therefore, two dashes are used and swapped for a colon when the secrets are loaded into the app's configuration.
      • Create two Manual secrets with the following name-value pairs. The first secret is a simple name and value, and the second secret creates a secret value with a section and subkey in the secret name:
        • SecretName: secret_value_1
        • Section--SecretName: secret_value_2
    • Register the sample app with Azure Active Directory.
    • Authorize the app to access the key vault. When you use the Set-AzureRmKeyVaultAccessPolicy PowerShell cmdlet to authorize the app to access the key vault, provide List and Get access to secrets with -PermissionsToSecrets list,get.
  2. Update the app's appsettings.json file with the values of Vault, ClientId, and ClientSecret.

  3. Run the sample app, which obtains its configuration values from IConfigurationRoot with the same name as the secret name. * Non-hierarchical values: The value for SecretName is obtained with config["SecretName"]. * Hierarchical values (sections): Use : (colon) notation or the GetSection extension method. Use either of these approaches to obtain the configuration value:
    • config["Section:SecretName"]
    • config.GetSection("Section")["SecretName"]

好的,我已将应用程序的名称作为“企业应用程序”复制到 Azure Active Directory 中。我已经在 Azure 中为刚刚创建的 ADD 对象添加了“获取”和“列表”的“访问策略”。然而,当我尝试启动应用程序时,我在程序中收到此错误:

Exception: {"error":"unauthorized_client","error_description":"AADSTS70001: 
Application with identifier '(guid)' was not found in the directory ...(continues)

2018 年 8 月 4 日更新好的,我发现 Azure 使用本地 appsettings.json 中的“ClientId”和“ClientSecret”来连接到 Azure 在本教程中注册的内容:https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal#log-in-as-the-application

  1. 我从使用 ADD>App Registrations>New 创建的 ADD 上的 applicationId 获取 appsettings.json 中的 clientId
  2. 我在刚刚创建的应用程序上单击 ADD 中的设置,并创建一个具有过期时间的 key ,以将其存储为 appsettings.json 中的 ClientSecret。
  3. 我将应用程序设置中的“保管库”更改为我命名的保管库。
  4. 我运行上面的 powershell 来授予访问权限,或者在 ADD 中执行此操作。

所以现在我遇到了一个更简单的错误:

'Microsoft.Azure.KeyVault.Models.KeyVaultErrorException: 'Access denied''

我尝试在 Visual Studio 中以管理员身份运行。我进入 Azure 中的订阅>访问控制>(IAM)>将我的新应用程序设置为 Reader。

最佳答案

因此,您的 powershell 失败的原因是您尝试分配一个用户主体(用户),而实际上您需要一个服务主体

我看不到你的 C# 支持更多,只是说当你使用 SDK 作为服务主体登录时,你使用应用程序/服务主体的应用程序 ID(其相同的 ID)。

服务主体的行为类似于本地目录中的用户,但您以应用程序身份登录。

<小时/>

编辑:

我查看了您发布的示例并自己运行了它,并且遇到了非常相似的问题。不过我已经让它工作了。步骤如下:

创建应用程序

  1. 创建注册应用程序。我通过 Azure 门户执行此操作,因此服务主体会自动创建。记下 ApplicationId
  2. 在创建的应用程序上生成 key 凭据并记下它。
  3. 在应用程序中,单击本地目录中的托管应用程序的链接。这是服务主体,记下 ObjectId

创建 key 保管库

  1. 创建 KeyVault - 我使用 PowerShell 来执行此操作。 New-AzureRmKeyVault

  2. 将服务主体应用到 key 保管库。

    Set-AzureRmKeyVaultAccessPolicy -VaultName <vault> -ResourceGroupName <ResourceGroupName> -ObjectId <Object Id of the Created Service Principal> -PermissionsToSecrets Get,List

运行示例应用程序

在您的应用程序设置中遵循以下格式:

{
"Vault": <the name of your vault>,
"ClientId": <ApplicationId of the Registered Application>,
"ClientSecret": <Credential generated from the Registered Application>
}

这对我有用,允许我运行示例并从保险库中检索 secret 。

关于azure - 如何注册我在 Azure Active Directory 中创建的本地应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51675611/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com