WCF, RESTful Web Services and custom authentication

When I was investigating how to implement security for my own WCF RESTful service I spent some time looking at how other popular services like flickr and amazon implement their own security – assuming that they’ve probably spent far more time thinking about it than I have. Flickr’s documentation in particular helped shaped how I formated my signatures and requests.

In the end I chose a HMAC (Hash-based Message Authentication Code) authentication scheme for my services.

I created a custom HMAC ServiceAuthorizationManager that validates the signature of each request as it comes in. Each request contains the following:

  • a user token
  • timestamp
  • nonce
  • signature

Using this information the manager can look up the user’s secret from their token and can recreate the signature on the server using the provided information.

My signature consists of an MD5 hash of the following (values are concatenated together in a specific order and hashed so the value can be repeated on the server):

  • apikey
  • userToken
  • secret
  • timestamp
  • nonce

I store the nonce’s in a memcache instance for a short period of time in order to quickly check against any replay attacks. After that time skew (about 10 minutes) the timestamp is used to reject any other old requests.

I can post some snippets of my code if it will help. In general I’ve found that the HMAC authentication is generally the safest way to go and is easily supported on any clients that will be using your service (not just .NET).

Leave a Comment