我按照https://azure.microsoft.com/en-us/documentation/samples/active-directory-dotnet-daemon-certificate-credential/上的示例来使用Azure AD对带有证书的守护程序应用程序进行身份验证 . 我做了以下事情:
-
创建我自己的Active Directory
-
在AD中创建守护程序应用程序名称:TodoListDaemonWithCertYanlin登录URL:http:// TodoListDaemonWithCertYanlin应用程序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可能会搜索我的组织AD而不是我创建的AD . 但我不知道如何调试问题 .
1 回答
问题解决了 .
以下是它发生的原因:我使用我的org的凭证登录Azure,然后创建了一个测试Active Directory,并在我的测试Active Directory中创建了Todo List Daemon应用程序 . 当我在PowerShell中登录Azure时,我使用了我的org的凭证 . 似乎Azure PowerShell将仅在我的组织AD中寻找应用原则,而不是在我的测试AD中 - 可能有一种方法可以切换AD,但我还不知道 .
以下是我解决问题的方法:
去了https://manage.windowsazure.com并尝试使用我的测试AD中的用户登录 .
Azure提示用户未与任何订阅关联 . 按照"Sign up"链接注册免费试用订阅 .
等待几分钟让租户配置
在PowerShell中,使用我测试Azure AD中的用户登录azure,然后再次运行PowerShell . 现在它成功了 .
以下是我运行的PowerShell cmdlet: