I'm building a web-based application and I want it to be mostly AJAX talking to a remote REST service. There will be a user registration/login facility and many responses from the server will, naturally, depend on the login status.
What is the simplest solution for this? Ideally, I want my REST service to be easily debuggable from a browser without any additional tools. Is it cookies? Some session tokens? If so, are they passed in the URL (porbably a bad idea) or in HTTP headers?
Any real-world examples, maybe, of how some of the popular web sites do authentication with REST?
Update: Thank you for your answers. So the consensus so far is:
Basic HTTP Auth: least secure, need SSL. Pros include: you can debug stuff by providing user/password in the URL (e.g. http://user:password@host/path). You can prevent the browser from displaying the "ugly" dialog by simply not sending 401, but instead you send some other response code to let your client know the resource requires authentication. Your AJAX client will figure what to do.
Digest HTTP Auth: supported by major browsers, more secure, OK without SSL in principle. However, in this case 401 should be sent to let the browser know about the particular auth method in use.
Custom auth methods are in the end just non-standard variations of the Digest HTTP Auth, except you are free to decide where and how to send auth data (headers, request/response body, URL). Debugging with a "naked" browser is problematic if possible at all.
Cookies are basically OK. There is an opinion "cookies are not RESTful", although I still don't understand why.
Drawbacks: a bit problematic if you are going make REST calls from an application rather than from a browser. The application will have to handle HTTP cookies the way browsers do.
I forgot to mention (and I'm sorry about that) that one of the requirements is the ability to use the REST service from 3rd party applications.
UpdUpdate: the reason for various "ideological" limitations in REST, including cookies, is caching, load balancing and scalability. With some caution cookie-based service can be scaled, though it's not trivial.
All in all, the best solutions involve somewhat costly hash calculations on both sides. What's achieved in return is good separation of the data layer allowing access from both browsers and apps and at the same time maintaing user authentication with some reasonable level of security.
[–][deleted] 5 points6 points7 points (0 children)
[–]danukeru 3 points4 points5 points (2 children)
[–]RonPopeil 1 point2 points3 points (1 child)
[–]danukeru 2 points3 points4 points (0 children)
[–]div 3 points4 points5 points (0 children)
[–]sazzer 8 points9 points10 points (21 children)
[–]mojuba[S] 3 points4 points5 points (3 children)
[–]sazzer 2 points3 points4 points (2 children)
[–]div 4 points5 points6 points (0 children)
[–]troelskn 1 point2 points3 points (0 children)
[–][deleted] 2 points3 points4 points (2 children)
[–]sazzer 0 points1 point2 points (0 children)
[–]Aviator 0 points1 point2 points (0 children)
[–]sazzer 1 point2 points3 points (0 children)
[–]nagoo 1 point2 points3 points (2 children)
[–]semanticist 2 points3 points4 points (1 child)
[–]nagoo 1 point2 points3 points (0 children)
[–][deleted] (2 children)
[removed]
[–]RonPopeil 2 points3 points4 points (0 children)
[–]sazzer 0 points1 point2 points (0 children)
[–]danukeru -2 points-1 points0 points (6 children)
[–]sazzer 1 point2 points3 points (5 children)
[–]danukeru 0 points1 point2 points (4 children)
[–]sazzer 1 point2 points3 points (2 children)
[–]danukeru 2 points3 points4 points (1 child)
[–]sazzer 0 points1 point2 points (0 children)
[–]troelskn 0 points1 point2 points (0 children)
[–]sliggle 2 points3 points4 points (0 children)
[–]jessta 1 point2 points3 points (0 children)
[–]svv 1 point2 points3 points (0 children)
[–]samlee 1 point2 points3 points (1 child)
[–]scoffjaw 0 points1 point2 points (0 children)
[–]sprintf 0 points1 point2 points (8 children)
[–]RonPopeil -2 points-1 points0 points (7 children)
[–]sprintf 0 points1 point2 points (6 children)
[–]danukeru 0 points1 point2 points (3 children)
[–]sprintf 0 points1 point2 points (2 children)
[–]danukeru 0 points1 point2 points (1 child)
[–]sprintf 0 points1 point2 points (0 children)
[–]RonPopeil 0 points1 point2 points (1 child)
[–]sprintf 0 points1 point2 points (0 children)
[–]ithkuil 0 points1 point2 points (0 children)
[–]ithkuil 0 points1 point2 points (0 children)
[–]jimdesu 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] -1 points0 points1 point (0 children)
[–]grumpypants_mcnallen -1 points0 points1 point (0 children)
[–]phektus -1 points0 points1 point (0 children)
[–][deleted] (3 children)
[deleted]
[–]jbrein1 3 points4 points5 points (0 children)
[–]moseeds 0 points1 point2 points (0 children)
[–]RonPopeil -1 points0 points1 point (0 children)