Note that there are some explanatory texts on larger screens.

plurals
  1. PORESTful authentication for web applications
    primarykey
    data
    text
    <p>Hi already wrote this observation and question on <a href="https://stackoverflow.com/questions/319530/restful-authentication/1135995#1135995">this question</a> earlier, but only later noticed that it was an old and "dead" question. As I'd really like some insights from others, I'm reposting it as a new question.</p> <p>To the question of how to do authentication RESTfully, people generally enthousiastically shout "HTTP Authentication". However, I sorf of doubt whether those people ever tried making a browser-based <em>application</em> (instead of a machine-to-machine web service) with REST. (no offense intended - I just don't think they ever faced the complications) </p> <p>Problems that I found with using HTTP Authentication on RESTful services that produce HTML pages to be viewed in a browser are:</p> <ul> <li>user typically gets an ugly browser-made login box, which is veyr user-unfriendly. you cannot add password retrieval, help boxes, etcetera.</li> <li>logging out or logging in under a different name is a problem - browsers will keep sending authentication information to the site until you close the window</li> <li>timeouts are difficult</li> </ul> <p>A very insightful article that tackles these point by point is <a href="http://www.berenddeboer.net/rest/authentication.html" rel="nofollow noreferrer">here</a>, but this results to a <em>lot</em> of browser-specific javascript hackery, workarounds to workarounds, etcetera. As such, it is also not forward-compatible so will require constant maintenance as new browsers are released. I do not consider that clean and clear design, plus I feel it is a lot of extra work and headache just so that I can enthousiastically show my REST-badge to my friends.</p> <p>I believe that cookies are the solution. But wait, cookies are evil, aren't they? No they're not, the way cookies are used often is evil. A cookie itself is just a piece of client-side information, just like the HTTP authentication info that the browser would keep track of while you browse. And this piece of client-side information is sent to the server at every request, again just like the HTTP Authentication info would be. Conceptually, the only difference is that the <em>content</em> of this piece of client-side state can be determined by the <em>server</em> as part of its response.</p> <p>By making sessions a RESTful resource with just the following rules:</p> <ul> <li>A <em>session</em> maps a key to a user id (and possibly a last-action-timestamp for timeouts)</li> <li>If a <em>session</em> exists, then that means that the key is valid.</li> <li>Login means POSTing to /sessions, a new key is set as a cookie</li> <li>Logout means DELETEing /sessions/{key} (with overloaded POST, remember, we're a browser and HTML 5 is a long way to go yet)</li> <li>Authentication is done by sending the key as a cookie at every request and checking whether the session exists and is valid</li> </ul> <p>The only difference to HTTP Authentication, now, is that the authentication key is generated by the server and sent to the client who keeps sending it back, instead of the client computing it from the entered credentials.</p> <p>I feel that this is a sufficient solution that works fine, but I must admit that I'm not enough of a security expert to identify potential holes in this scheme - all I know is that hundreds of non-RESTful web applications use essentially the same login protocol ($_SESSION inphp, HttpSession in j2ee, etc). The cookie header contents is simply used to address a server-side resource, just like an accept-language might be used to access translation resources, etcetera. I feel that it is the same, but maybe others don't? What do you think, guys?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload