title: RESTful web service - how to authenticate requests from other services?
body: <p>I am designing a RESTful web service that needs to be accessed by users, but also other web services and applications. All of the incoming requests need to be authenticated. All communication takes place over HTTPS. User authentication is going to work based on an authentication token, acquired by POSTing the username and password (over an SSL connection) to a <em>/session</em> resource provided by the service.</p>
  
  <p><em>In the case of web service clients, there is <strong>no end user</strong> behind the client service.</em> The requests are initiated by scheduled tasks, events or some other computer operations. The list of connecting services is known beforehand (obviously, I guess). <strong>How should I authenticate these requests coming from other (web) services?</strong> I want the authentication process to be as easy as possible to implement for those services, but not at the cost of security. What would be the standard and best practices for a scenario like this?</p>
  
  <p>Options that I can think of (or have been suggested to me):</p>
  
  <ol>
  <li><p>Have the client services resort to having a "fake" username and password, and authenticate them in the same way as users. I do not like this option - it just doesn't feel right.</p></li>
  <li><p>Assign a permanent application id for the client service, possibly an application key as well. As far as I have understood this is just the same as having username + password. With this id and key, I can either authenticate each request, or create an authentication token to authenticate further requests. Either way, I do not like this option, because anyone who can get a hold of the application id and key can impersonate the client.</p></li>
  <li><p>I could add an IP address check to previous option. This would make it harder to perform fake requests.</p></li>
  <li><p>Client certificates. Set up my own certificate authority, create root certificate, and create client certificates for the client services. A couple of issues come to mind, though: a) how do I still allow the users to authenticate without certificates and b) how complicated is this scenario to implement from the client service point of view?</p></li>
  <li><p><em>Something else - there must be other solutions out there?</em> </p></li>
  </ol>
  
  <p>My service would be running on Java, but I deliberately left out information about what specific framework it would be built on, because I am more interested on the basic principles and not so much on the implementation details - I assume the best solution for this will be possible to implement regardless of the underlying framework. However, I am a bit inexperienced with this subject, so concrete tips and examples on the actual implementation (such as useful third party libraries, articles, etc.) will be much appreciated as well.</p>