如何在 UWP 中使用 WebAccountManager 来使用 Window 凭据对应用程序进行身份验证

How to use WebAccountManager in UWP to authenticate app using Window Credentials

我正在尝试将 WebAccountManager 用作 suggested for my organization link at https://si.business360online.com/ 它可以使用与 Windows 用户(在组织域上)相同的帐户登录。我无法从 Windows 10 PC.

获得任何令牌或现有帐户

我也试过 AccountsSettingsPaneWebAccountProvider 如下:

AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += OnlineDataStore_AccountCommandsRequested;
AccountsSettingsPane.Show();

然后OnlineDataStore_AccountCommandsRequested如下:

WebAccountProvider wap = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://si.business360online.com/");

but wap is always null.

任何人都可以帮助了解如何通过 Windows UWP 中当前登录用户的凭据登录吗? 使用以下更多研发,我能够以 Windows 当前用户,但在 Windows.Web.Http 中,我无法控制 logout/clear 凭据等

编辑 1: 以下代码片段有效,但 System.Net.Http 可能会在未来版本中弃用。

var handler = new HttpClientHandler();
handler.AllowAutoRedirect = true;
handler.Credentials = CredentialCache.DefaultCredentials;
var httpClient = new System.Net.Http.HttpClient(handler);
System.Net.Http.message = await httpClient.GetAsync(feedUrl);

编辑 2: 这可能对某人有帮助:要在 UWP/Windows 移动设备中启用 Windows 身份验证,必须启用 Enterprise Capabilities.我发现以下几点:

要在 UWP/Windows 移动设备中启用 Windows 身份验证,必须启用 Enterprise Capabilities。 (同样已在问题中编辑)

  • 对于 System.Net.Http,我们可以通过设置 CredentialCache.DefaultCredentials
  • 来控制凭据
  • 对于 Windows.Web.Http,如果 HttpProtocolFilter 中没有设置凭据,它将自动以 Windows 凭据登录。