Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用KeyVault&;创建Azure广告应用程序;Azure PowerShell证书身份验证_Azure_Certificate_Azure Active Directory_Azure Powershell - Fatal编程技术网

使用KeyVault&;创建Azure广告应用程序;Azure PowerShell证书身份验证

使用KeyVault&;创建Azure广告应用程序;Azure PowerShell证书身份验证,azure,certificate,azure-active-directory,azure-powershell,Azure,Certificate,Azure Active Directory,Azure Powershell,我正在尝试使用Azure PowerShell证书身份验证在Azure AD中创建应用程序,下面是PowerShell代码段: Login-AzureRmAccount $certPassword = ConvertTo-SecureString $CertPassword -AsPlainText -Force $x509 = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -Argumen

我正在尝试使用Azure PowerShell证书身份验证在Azure AD中创建应用程序,下面是PowerShell代码段:

Login-AzureRmAccount

$certPassword = ConvertTo-SecureString $CertPassword -AsPlainText -Force

$x509 = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList     $certPath,$certPassword

$credValue = [System.Convert]::ToBase64String($x509.GetRawCertData())

$adapp = New-AzureRmADApplication -DisplayName $ApplicationName -HomePage $URL -IdentifierUris $URL -CertValue $credValue -StartDate $startDate -EndDate $endDate     

$sp = New-AzureRmADServicePrincipal -ApplicationId $adapp.ApplicationId

Set-AzureRmKeyVaultAccessPolicy -VaultName $VaultName  -ServicePrincipalName $sp.ServicePrincipalNames[1] -PermissionsToKeys all –PermissionsToSecrets all -ResourceGroupName $ResourceGroupName
Azure AD应用程序已成功创建,但是对于具有证书身份验证的Azure AD应用程序,创建后keyCredentials中的customKeyIdentifier和值为空,这是我从Azure portal下载的应用程序清单的一部分:

"keyCredentials": [{
      "customKeyIdentifier": null,
      "endDate": "2018-01-25T11:55:35.7680698Z",
      "keyId": "ca1e536c-2220-478b-af73-1198d125bb5f",
      "startDate": "2017-01-25T11:55:35.7680698Z",
      "type": "AsymmetricX509Cert",
      "usage": "Verify",
      "value": null
    } ]
该证书是使用本地生成的makecert命令创建的自签名证书。 我使用的是Powershell 2.0.1版本

用于检索具有应用程序Id和指纹的令牌的C代码

公共静态异步任务GetAccessToken(字符串权限, 字符串资源,字符串范围){ var context=newauthenticationcontext(authority,TokenCache.DefaultShared); var result=await context.AcquireTokenAsync(资源,断言专家); 返回result.AccessToken;}

此代码在var结果处出错,并显示“Keyset不存在”

有没有办法解决这个问题


谢谢:)

你看了这里的答案了吗

在评论中,他提到CustomKeyIdentifier为null对于身份验证并不重要

您是否尝试过在不考虑空值的情况下进行身份验证\

编辑: 如果要为您拥有的公共证书生成指纹,可以使用以下powershell cmdlet:

$cer = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$cer.Import(“mycer.cer”)
$bin = $cer.GetCertHash()
$base64Thumbprint = [System.Convert]::ToBase64String($bin)

我希望这会有所帮助。

因此,您的问题是值为null,而不是您的应用程序不工作?我已经根据Powershell版本(2.0.1)编写了与上述相同的代码。在此版本中创建新AzureADApplication的Commandlet已更改。但用证书对AD应用程序进行身份验证以检索Keyvault机密不起作用。。。因此,我在查看清单文件时,发现了“customKeyIdentifier”:null。如何获得该值?或任何Powershell命令创建具有证书的AD应用程序并获取此CustomerKeyIdentifier值据我所知,CustomKeyIdentifier不是严格定义的属性。它应该表示上传到密钥凭证中的公共证书的指纹,但其值不是由AAD自动设置的,因此用户可以发布任何与x509指纹大小匹配的内容。我将在上面的帖子中包含一个关于如何自己生成此代码的代码示例。感谢您的及时回复Shawn。。基本上,我想用证书对AD应用程序进行身份验证,以检索KeyVault机密。特别是在这个Powershell版本中,commandlets发生了更改…使用Powershell创建带有证书的AD应用程序的代码工作正常。。。但在c#级别,当我试图通过传递ApplicationID和指纹来检索keyvault机密时…它会在说“Keyset不存在”时出错…我的控制台应用程序可以检索证书指纹也无法使用证书验证应用程序…因此在搜索错误时。。我指的是这个文档链接