I have been trying for a long time to get user basic authentication working in the WCF service, and I searched the Internet trying to get a good answer without any luck.
I tried using the userNameAuthentication custom function as well as the custom serviceAuthorizationManager.
What I use is that I am stuck in the "loop" of his credential request, and it is never suitable for my user authentication. From my research, this seems to be due to the fact that IIS captures authentication and local user authentication.
From the web configuration, I have transport security enabled with basic authentication:
<webHttpBinding>
<binding name="SecureBinding">
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</webHttpBinding>
Service related behavior: (I have one of the things I tried to comment on)
<serviceBehaviors>
<behavior name="AuthenticatedWCF.CustomServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceAuthorization serviceAuthorizationManagerType="AuthenticatedWCF.Classes.Helpers.AuthenticationManager, AuthenticatedWCF" />
</behavior>
</serviceBehaviors>
( ):
public class AuthenticationManager : ServiceAuthorizationManager
{
protected override bool CheckAccessCore(OperationContext operationContext)
{
var authHeader = WebOperationContext.Current.IncomingRequest.Headers["Authorization"];
if ((authHeader != null) && (authHeader != string.Empty))
{
return true;
}
else
{
WebOperationContext.Current.OutgoingResponse.Headers.Add("WWW-Authenticate: Basic realm=AuthenticatedWCF");
throw new WebFaultException(HttpStatusCode.Unauthorized);
}
}
}
, , IIS, ?
, , .