0

I'm trying to use the new WCF Web API Preview 6 with Basic Authentication. But don't really know where to begin.

zanewill apparently had the same issue:
https://stackoverflow.com/questions/8304367/how-to-use-basic-authentication-with-wcf-web-api But the question is not a dup. I'm using this with mvc and don't really see how
Wcf Basic authentication
should apply?

I've tried out this:
http://cacheandquery.com/blog/2011/03/customizing-asp-net-mvc-basic-authentication/
But can't get it to work. Should there not be an official solution from MS?

I have to note, that we are using our custom membership provider and that I basically just wanna pass an API token to the service. So the built in Windows Basic Authentification cannot be used.

Community
  • 1
  • 1
Remy
  • 12,555
  • 14
  • 64
  • 104

2 Answers2

1

I actually figured out a way myself. I've built my custom HttpOperationHandler and combined it with an Attribute, so I get a similar functionality as the MVC AuthorizeAttribute.

You can have a look at the solution here:
http://remy.supertext.ch/2012/02/basic-authentication-with-wcf-web-api-preview-6/

Remy
  • 12,555
  • 14
  • 64
  • 104
  • I have a new version for the MVC Web API: http://remy.supertext.ch/2012/04/basic-http-authorization-for-web-api-in-mvc-4-beta/ – Remy Jul 30 '12 at 21:54
0

I think the recommended approach is to implement custom message handler. See my blog post for an example that works with ASP.NET Web API RTM:

http://www.piotrwalat.net/basic-http-authentication-in-asp-net-web-api-using-message-handlers/

Piotr Walat
  • 971
  • 7
  • 9