Skip to content

Instantly share code, notes, and snippets.

@lukelex
Created August 27, 2012 16:06
Show Gist options
  • Select an option

  • Save lukelex/3489878 to your computer and use it in GitHub Desktop.

Select an option

Save lukelex/3489878 to your computer and use it in GitHub Desktop.
Simple api token authentication
class ApplicationController < ActionController::Base
protect_from_forgery
respond_to :json
before_filter :authorize_user!
helper_method :current_user
def current_user
@current_user
end
private
def authorize_user!
@current_user ||= User.find_by_token params[:token]
render nothing: true, status: 401 unless @current_user
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment