I am learning RESTful and have come up with such a question:
Since RESTful web services requires that the server side does not store any connection data, how do we implement user login?
The traditional method can use server-side session to store user data, but RESTful gets aways from it.
One apparent solution is that, the user side always sends username and password every time they visit a new page, and the server side always authenticates the user before it does everything. However, this approach seems very ugly as the front-end has to store username/password and send them in every link, and the server has to check against the database to authenticate, which seems too slow.
So how do we even implement any user authentication mechanism without storing any tracking information on the server side?
ApiKeymodel. Which can generate access tokens. Then you would look forApiKeyby access user token you previously generated. You may also want to add additional restrictions toApiKeylike expires_in etc. So before each request if you don't find theApiKeyby using access token you can returnhead :unauthorizedfrom your controller method. Additionally check this out railscasts.com/episodes/352-securing-an-api