得到错误"找不到服务主管"尝试将证书添加到azure应用程序时

时间:2015-11-09 19:07:44

标签: azure azure-active-directory

我正在关注https://azure.microsoft.com/en-us/documentation/samples/active-directory-dotnet-daemon-certificate-credential/上的示例,使用Azure AD对带有证书的守护程序应用程序进行身份验证。我做了以下事情:

  • 创建我自己的Active Directory
  • 在AD中创建守护程序应用程序 名称:TodoListDaemonWithCertYanlin 登录URL:http:// TodoListDaemonWithCertYanlin App Id Url:http:// TodoListDaemonWithCertYanlin
  • 创建自签名证书 makecert -r -pe -n" CN = TodoListDaemonWithCertYanlin" -ss My -len 2048 TodoListDaemonWithCert.cer

当我尝试将证书添加到PowerShell中的守护程序应用程序时,出现错误。

我使用的PowerShell命令:New-MsolServicePrincipalCredential -AppPrincipalId" e5dedde0-2221-4ce4-a74d-af4e96705c01" -type asy mmetric -Value $ credValue -StartDate $ cer.GetEffectiveDateString() - EndDate $ cer.GetExpirationDateString() - 使用验证

错误是: New-MsolServicePrincipalCredential:找不到服务主体。

" Get-MsolServicePrincipal -SearchString TodoListDaemonWithCert"返回了一堆应用程序,但我没有包含它。

我怀疑Azure可能会搜索我的组织广告,而不是我创建的广告。但我不知道如何调试这个问题。

1 个答案:

答案 0 :(得分:0)

问题解决了。

以下是它发生的原因:我使用我的org的凭据登录Azure,然后创建了一个测试Active Directory,并在我的测试Active Directory中创建了Todo List Daemon应用程序。当我在PowerShell中登录Azure时,我使用了我的org的凭证。似乎Azure PowerShell将仅在我的组织AD中寻找应用原则,而不是在我的测试AD中 - 可能有办法切换AD,但我还不知道。

以下是我解决问题的方法:

  • 去了https://manage.windowsazure.com并试图在我的测试广告中使用用户登录。
  • Azure提示用户未与任何订阅相关联。点击“注册”链接注册免费试用订阅。
  • 等待几分钟让租户配置
  • 在PowerShell中,使用我测试Azure AD中的用户登录azure,然后再次运行PowerShell。现在它成功了。

以下是我运行的PowerShell cmdlet:

connect-msolservice
$cer = New-Object System.Security.Cryptography.X509Certificates.X509Certificate
$cer.Import("D:\Fast1\dev\TodoListDaemonWithCert.cer")
$binCert = $cer.GetRawCertData()
$credValue = [System.Convert]::ToBase64String($binCert)
New-MsolServicePrincipalCredential -AppPrincipalId  "e5dedde0-2221-4ce4-a74d-af4e96705c01" -Type asymmetric -Value $credValue -StartDate $cer.GetEffectiveDateString() -EndDate $cer.GetExpirationDateString() -Usage verify
相关问题