【发布时间】:2017-06-18 02:21:28
【问题描述】:
我尝试使用 Azure PowerShell 证书身份验证在 Azure AD 中创建应用程序,下面是 Powershell sn-p:
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 和 value 为 null,这是我从 Azure 门户下载的应用程序清单的一部分:
"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 命令创建的自签名证书。 我正在使用 2.0.1 的 Powershell 版本
使用应用程序 ID 和指纹检索令牌的 C# 代码
public static async Task GetAccessToken(string authority, 字符串资源,字符串范围){ var context = new AuthenticationContext(authority, TokenCache.DefaultShared); var result = await context.AcquireTokenAsync(resource, AssertionCert); 返回结果.AccessToken; }
此代码在 var 结果中出错,并显示“密钥集不存在”
有没有办法解决这个问题?
谢谢你:)
【问题讨论】:
标签: azure certificate azure-active-directory azure-powershell