Authentication and sessions are the area that is rarely truly RESTful, because they are stateful, unless you pass full authentication credentials with each request.
Here is what I do, similar to yours, with one big difference.
POST /session/ --> creates a session, passing credentials in HTTP Auth Header
The above returns a 201 if successful, along with the session ID, just like a real resource. It also includes a session token in the cookies (and in a special X- type HTTP header), which can be used in each subsequent request.
GET /protectedResource --> includes the credential in the HTTP header
And to terminate/invalidate a session, which is a common activity, like clicking on "logout"
DELETE /session/sessionId
The only real difference from what you have done is that I would never pass the tokens and credentials in the query path or body. The only exception is if you want to do form-based authentication and submit, but even then, when I can, I prefer to process Web-side and submit as a header.
The reason is 2-fold:
- You want to be able to expose the URL without exposing anything secret
- You want to be able to reuse the URL without exposing
One other advantage of HTTP auth (which is in the headers) is that it becomes immensely easier to test your REST API using curl:
curl --user username:pass http://server/protectedResource
And you can even generate session tokens and use them in curl.
If you are comfortable with nodejs, you can look at the README and source code for cansecurity http://github.com/deitch/cansecurity