Created
September 27, 2012 14:53
-
-
Save andrei512/3794449 to your computer and use it in GitHub Desktop.
simple API security
This file contains 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
before_filter :restrict_access | |
protected | |
def restrict_access | |
if Rails.env != "development" | |
access_token = request.headers['access_token'] | |
access_token ||= params[:access_token] | |
begin | |
@auth = Authorization.find_by_access_token(access_token) | |
head :unauthorized unless @auth | |
rescue ActiveRecord::RecordNotFound => e | |
head :unauthorized | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment