Quick token authentication for rails controllers
Create a concern in concerns/request_auth.rb with the following:
module RequestAuth
  extend ActiveSupport::Concern
  included do
    before_filter :authenticate_request
  end
  def authenticate_request
    raise "Invalid authentication token" if params[:auth_token] != "some_auth_token"
  end
end
Then in the controller you wish to secure just include the module.
class SomeController < ApplicationController
  include RequestAuth
  ...
end
And that's it your controller should be secured by the auth token you specify.
Written by Ian Rodriguez
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
 #Rails 
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#