Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webhttpbinding with HTTPS and authentication with UserNamepPasswordValidator when hosted in IIS

I'm trying to set up a WCF service hosted in IIS that exposes an endpoint that acts as a REST service producing JSON data, and I want to use HTTPS. I want to take care of the user authentication myself with the help of UserNamePasswordValidator, since the users are stored in a database.

At the moment I'm using a webhttpbinding to achieve the REST-fulness. My problem starts when I try to enable HTTPS (setting security mode to Transport). I have an SSL certificate on the server side (self signed for now), so that is all good, but I don't know how to configure the transport clientCredentialType of the binding so that the credentials are passed on to my implementation of UserNamePasswordValidator.

I've googled a lot, but can't seem to find any thing good. If I understand it correctly IIS handles the authentication before WCF and there is nothing to do about it? I would really prefer not to use a ASP.Net membership provider, but maybe that is an approach or is there another way?

Thank you!

Edit: Found this. Not really what I was hoping for...

like image 433
Joel Avatar asked Jun 15 '11 08:06

Joel


1 Answers

You can't use UserName credentials - that is message level authentication through SOAP header but JSON data exchange doesn't have such header. Try to setup Basic credentials in transport element (= transport level authentication). It should work with custom password validator since .NET 3.5. You will have to pass valid HTTP header for basic authentication to successfully authenticate.

Edit:

I didn't test it with IIS so there can be some problems because IIS trigger authentication before the custom validator is executed. In such case you will need custom HTTP module for authentication.

like image 194
Ladislav Mrnka Avatar answered Sep 18 '22 21:09

Ladislav Mrnka