WCF WebHttpBinding with Membership provider authetication
-
15-11-2019 - |
Question
I have a WebHttpBinding service which uses basic HTTP authentication mode, however for some strange reason it validates provided username/password against windows accounts, thought i specified userNamePasswordValidationMode="MembershipProvider".
I found other posts that report this problem too, but no answer to this situation have been given.
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="WebBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" />
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="EPWeb">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="MembershipProvider" membershipProviderName="SqlProvider" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ServiceBehavior" name="Foo">
<endpoint address="Test" behaviorConfiguration="EPWeb"
binding="webHttpBinding" bindingConfiguration="WebBinding"
contract="Foo.IService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:3456/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
Solution
This configuration will not work. But there are workarounds to this issue:
- Create Login() method and use authentication token, which you pass to every service method.
- Use custom validation mode, and validate username\password by code, using Membership.ValidateUser()
OTHER TIPS
Token passed login or a custom http authentication module.
Here is a link to a custom authentication module. http://custombasicauth.codeplex.com/
For token based, you could use an OAuth implementation.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow