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?

3
  • 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. Commented Mar 28, 2018 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. Commented Mar 30, 2018 at 5:32
  • Not a problem. Thanks for getting back to me on it. If I find a solution, I will post it here as well. Commented Mar 30, 2018 at 23:47

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

5 Comments

I added it but there was no change. I'm still being prompted for a username and password.
How I'm just getting non-success responses
To clarify: I'm no longer being prompted, but now the response from the server is 401
Are you sure your server is correctly configured? You can test it using PowerShell: Invoke-WebRequest -Method GET -Uri "http://example.com" -UseDefaultCredentials
yeah, if I run that in powershell, I get an OK response

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.