title: WCF REST basic authentication on certain methods
body: <p>I have quite a few RESTful (GET and POST) methods implemented in WCF 4.0. All these work over SSL. </p>
  
  <p>An example of some of the methods:</p>
  
  <pre><code>[OperationContract]
  [WebInvoke(UriTemplate = "Login?", Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
  LoginResponse Login(LoginRequest request);
  
  [OperationContract]
  [WebInvoke(UriTemplate = "UpdateDetails?", Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
  UpdateUserDetailResponse UpdateDetails(UpdateUserDetailRequest request);
  
  [OperationContract]
  [WebInvoke(UriTemplate = "GetDetails?", Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
  UserDetailResponse GetDetails(UserDetailRequest request);
  </code></pre>
  
  <p>I have looked through so many blogs and forums and I still cannot find something that meets
  my requirements. I need to implement basic authentication on <em>some</em> of the methods but not all. If you look at the examples above I require a username and password to be sent through for the UpdateDetails and GetDetails method, but not for the Login method. The username and password is then authenticated against a database. Is it possible to do something like this? </p>
  
  <p>As a side note: these REST methods are called by many different mobile devices.</p>
  
  <p>I have looked at the following sites and they all implement basic authentication over REST <em>but</em> they cover all the methods mentioned above. </p>
  
  <ul>
  <li><a href="http://msdn.microsoft.com/en-us/library/aa702565.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa702565.aspx</a></li>
  <li><a href="https://stackoverflow.com/questions/4715752/adding-basic-http-auth-to-a-wcf-rest-service">Adding basic HTTP auth to a WCF REST service</a></li>
  <li><a href="http://custombasicauth.codeplex.com/" rel="nofollow noreferrer">http://custombasicauth.codeplex.com/</a> (links at the bottom don't work
  anymore)</li>
  </ul>
  
  <p>Is it possible to do what I want to do?</p>