Created
August 27, 2012 16:06
-
-
Save lukelex/3489878 to your computer and use it in GitHub Desktop.
Simple api token authentication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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