Skip to content

Instantly share code, notes, and snippets.

@pi3r
Last active December 16, 2015 01:09
Show Gist options
  • Save pi3r/5353199 to your computer and use it in GitHub Desktop.
Save pi3r/5353199 to your computer and use it in GitHub Desktop.
class Api::V1::BaseController < ActionController::Base
include ActionController::HttpAuthentication::Basic
protect_from_forgery with: :null_session
before_filter :require_current_user
respond_to :json
rescue_from AccessDenied do |exception|
respond_with({ status: 'error', message: exception.message }, status: :forbidden)
end
protected
def require_current_user
raise AccessDenied unless current_user
end
def current_user
@current_user ||= begin
user, token = user_name_and_password(request)
User.where(github_username: user, api_token: token).first
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment