I'm designing restful webservice which will be used by 3rd parties.They need to be authenticated to use my Restful service.For that i'm planing to use two approach to authenticate them.
Using another Restful service as a proxy to access the Restful services: To access the RESTful service the user will send the username and password to this proxy class in POST method.When the username and password is correct a unique id(say, authentication key) will be generated and is sent in the response.When the next request is made,the user will send the authentication key (and other details to access the target Restful service) in the request payload.This authentication key will be validated by the proxy.If the key is valid ,the proxy will invoke the target restful service and return the response to the client.Otherwise error message will be sent in the resonse.
Servlet based authentication: Same as first approach but servlet will act as a proxy to access webservices.In this approach username and password will be validated by the servlet and if it is correct,the servlet will set some cookie in the response and send it to the client.Next time the when the user sends request cookie will be validated.If it is valid then the servlet will invoke the Restful service and sends the response.But i'm not sure whether the user request will contain cookie or not.
In first approach the user needs to send the authentication key for every request. But in second approach it is not needed.
I need to know which approach is better?..and also any other way to handle this..