Search code examples
xamarinactive-directorywin-universal-appuwpwindows-authentication

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


I'm trying to use WebAccountManager as suggested for my organization link at https://si.business360online.com/ It can be logged in using same account as Windows User(on orgnization domain). I'm not able to get any token or existing account from Windows 10 PC.

I have also tried the AccountsSettingsPane with WebAccountProvider as follows:

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

and then OnlineDataStore_AccountCommandsRequested is as follows:

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

but wap is always null.

Can anybody help on how to login through Windows Credentials of current logged in user in UWP? Using following more R&D I'm able to login as Windows current user, but in Windows.Web.Http, I'm not able to control the logout/clear credentials etc.

Edit 1: Following code snippets works but System.Net.Http may be deprected in future versions.

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);

Edit 2: This might be helpful to someone: To enable Windows authentication in UWP/Windows Mobile, it is must to enable Enterprise Capabilities. Following points I found:

  • For System.Net.Http we can control credentials by setting CredentialCache.DefaultCredentials
  • For Windows.Web.Http, it will automatically log in as Windows Credentials if no credentials are set in HttpProtocolFilter.

Solution

  • To enable Windows authentication in UWP/Windows Mobile, it is must to enable Enterprise Capabilities. (Same has been edited in question)

    • For System.Net.Http we can control credentials by setting CredentialCache.DefaultCredentials
    • For Windows.Web.Http, it will automatically log in as Windows Credentials if no credentials are set in HttpProtocolFilter.