How to implement HMAC Authentication in a RESTful WCF API
|December 2, 2011||Posted by forumadmin under TechQns||
We are building a RESTful API using WCF (currently .Net 3.5, but will be moving to .Net 4 soon). We have a functional framework in place, but it is currently unsecured. It will need to be accessible from .Net applications as well as iOS, Android, and web applications.
We would like to use an HMAC Authentication scheme as described here and here, but both examples seem to fall apart when describing how to validate the hash. The first example fails to describe the UserKeys object (hashtable?) and the second example is missing the GetUserKey methods on the client- and server-side.
Can anyone provide an explanation of how the “User Key”/token is generated/stored/retrieved/used in those examples or provide a better example (with source code, if possible) of how to use HMAC Authorization in a RESTful WCF service?
After more research, we determined that we needed more of an “Authorization” technique rather than an “Authentication” technique (semantics?). We implemented Basic Authorization and secured the API behind SSL. The Basic Authorization uses the same “Authorization” header from the web Request as the HMAC Authentication scheme, but passes a username:password string encoded in Base64 instead of a token. This allowed us to custom-validate a user against our database to determine if the user is licensed for and has appropriate security rights to access the desired API method.
We’re certainly open to hearing other options on how to accomplish custom username/password validation and other methods for securing the API.
|Asked By – ICS||Read Answers|