1

My app is trying to make a request to a service on our domain, but it's failing to pass through, the windows credentials of the user running the app which is causing a login request for every service call (there are several in a row... ultra-annoying)

If I set the ServerCredential to a PasswordCredential (using HttpBaseProtocolFilter) and use hardcoded information (resource, username, password) then everything works fine, but that is not adequate as it needs to be able to pass through the creds of whatever user is using the application.

Example:

var filter = new HttpBaseProtocolFilter
{
    ServerCredential = new PasswordCredential("ourServiceHost", "username", "password")
});

var client = new HttpClient(filter);

I read somewhere that not setting the ServerCredential should cause it to default to the current user's windows credentials, but that doesn't seem to be happening.

Ideas?

Sinaesthetic
  • 11,426
  • 28
  • 107
  • 176
  • Did you find a solution to this problem? I am facing the same situation and I get the exact same behavior like you. If I have just var filter = new HttpBaseProtocolFilter(); I am prompted for the credentials and the call succeeds. If I have var filter = new HttpBaseProtocolFilter { AllowUI = false }; it fails with error 401 - Unauthorized. – Eddie Mar 28 '18 at 20:56
  • It was a while ago, and I don't remember ever actually finding a solution, I'm sorry. It was a side project for a tool at a job I no longer work at. – Sinaesthetic Mar 30 '18 at 05:32
  • Not a problem. Thanks for getting back to me on it. If I find a solution, I will post it here as well. – Eddie Mar 30 '18 at 23:47

1 Answers1

2

You need to select the Enterprise Authentication capability in the Package.AppxManifest of your app.

To avoid the username and password prompt, disable the UI:

HttpBaseProtocolFilter filter = new BaseProtocolFilter();
filter.AllowUI = false;
HttpClient client = new HttpClient(filter);
kiewic
  • 15,852
  • 13
  • 78
  • 101