I\'m following this excellent article to setup the authentification part of my rails (3.2) API:
http://blog.joshsoftware.com/2011/12/23/designing-rails-api-using-rabl-and-de
Regarding Luc's question, that's my understanding as well.
For example, using default non-API login, SessionsController.create
handles the login. How do I retrieve the authentication_token
and reuse it as part of the API calls later?
Also, how do I override the SessionsController.create
to call resource.reset_authentication_token!
?
It's my fault, I'll update the blog post. You need to add the following code to create the user in you registration controller
if params[:api_key].blank? or params[:api_key] != API_KEY
render :json => {'errors'=>{'api_key' => 'Invalid'}}.to_json, :status => 401
return
end
build_resource
if resource.save
sign_in(resource)
resource.reset_authentication_token!
#rabl template with authentication token
render :template => '/devise/registrations/signed_up'
else
render :template => '/devise/registrations/new' #rabl template with errors
end
Let me know if you face any problem?