我尝试使用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和值为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命令创建的自签名证书 . 我正在使用Powershell版本的2.0.1
使用Application Id和Thumbprint检索令牌的C#代码
public static async Task GetAccessToken(字符串权限,字符串资源,字符串范围){var context = new AuthenticationContext(authority,TokenCache.DefaultShared); var result = await context.AcquireTokenAsync(resource,AssertionCert); return result.AccessToken; }
由于“Keyset不存在”,此代码在var结果中出错
有什么方法可以解决这个问题吗?
谢谢 :)
1 回答
你看到这里的答案了吗?
Create a Application in Azure AD with Azure PowerShell Certificate authentication
在评论中,他提到CustomKeyIdentifier为null对于身份验证无关紧要 .
您是否尝试过验证无论空值如何?
编辑:如果要为您拥有的公共证书生成指纹,可以使用以下powershell cmdlet执行此操作:
我希望这有帮助 .