我使用acquireTokenAsync方法如下:
var authenticationContext = new AuthenticationContext(azureActiveDirectoryAuthority);
var authenticationResult =
await authenticationContext.AcquireTokenAsync(
azureActiveDirectoryResource,
azureActiveDirectoryClientId,
new Uri("urn:ietf:wg:oauth:2.0:oob"),
new PlatformParameters(
PromptBehavior.Always,
Process.GetCurrentProcess().MainWindowHandle));
在Windows10上运行正常。
当我在Windows Server中运行应用程序时,它具有Enhaced Secutiry Configuration(ESC),
事实证明,用户输入其凭据以通过AzureAD进行身份验证的提示窗口被阻止,因为网址:
https:// login.microsoftonline.com
https:// secure.aadcdn.microsoftonline-p.com
不在Internet Explorer安全配置的默认受信任站点中
The window pop-up getting blocked by IE Security settings
我可以手动或以编程方式更改此配置(例如编辑注册表),但此代码是在客户服务器上运行的安装的一部分,因此我无法轻松更改这些安全设置。
是否有任何解决方案在Windows Server中使用ESC对AzureAD使用此身份验证,而不会在IE中被阻止? 是否有其他API不使用IE浏览器,或以某种方式使用其他浏览器(如不阻止这些网站的chrome)?
谢谢,
NIV
答案 0 :(得分:0)
我可以手动或以编程方式更改此配置(例如编辑注册表),但此代码是在客户服务器上运行的安装的一部分,因此我无法轻松更改这些安全设置
建议不要禁用Windows Server ESC,而是将Microsoft的站点添加到信任URL。我们也可以使用代码完成此操作,这里是使用PowerShell的代码示例供您参考:
If($TrustedSites)
{
#Adding trusted sites in the registry
Foreach($TruestedSite in $TrustedSites)
{
#If the user does not specify the user type, by default the script will add the trusted sites for the current user.
If($HTTP)
{
CreateKeyReg -KeyPath $UserRegPath -Name $TruestedSite
SetRegValue -RegPath "$UserRegPath\$TruestedSite" -blnHTTP $true -DWord $DWord
Write-Host "Successfully added '$TruestedSite' domain to Internet Explorer trusted Sites."
}
Else
{
CreateKeyReg -KeyPath $UserRegPath -Name $TruestedSite
SetRegValue -RegPath "$UserRegPath\$TruestedSite" -blnHTTP $false -DWord $DWord
Write-Host "Successfully added '$TruestedSite' domain to Internet Explorer trusted Sites."
}
}
}
您可以参考here的完整代码示例。
注意:强>
上述脚本不适用于Windows Server 2016,我们需要将$UserRegPath
从HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains
修改为HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\EscDomains
是否有任何解决方案在Windows Server中使用ESC对AzureAD使用此身份验证,而不会在IE中被阻止?是否有其他API不使用IE浏览器,或以某种方式使用其他浏览器(如不阻止这些网站的chrome)?
不,没有这样的API。默认情况下,dotnet的ADAL库使用WebBrowser控件与用户进行交互。(请参阅源代码here)