Reputation: 21
I am designing a series of web services using the new microsoft asp.net mvc 4 WebApi.
For any call to any of these services a username and password must be passed each time and these details must be checked in sql server to authorize the user.
Questions:
1) Would it be correct to pass the username and password each time using the basic authentication headers or perhaps custom http headers? The thing is I don't want to interfere with the querystring or the request body in each call and would prefer headers.
2) Once passed in headers how can I use the authorize attribute to to call my method that verifies the user is valid in sql? Do I need to roll a custom authorize attribute?
Upvotes: 2
Views: 9772
Reputation: 2824
Upvotes: 1
Reputation: 81660
There are a few implementations already there, best being Dominick's Baier:
http://leastprivilege.com/2012/05/26/thinktecture-identitymodel-and-asp-net-web-api/
This one is using attributes:
http://www.piotrwalat.net/basic-http-authentication-in-asp-net-web-api-using-membership-provider/
Upvotes: 1