Skip to content

Instantly share code, notes, and snippets.

@andrei512
Created September 27, 2012 14:53
Show Gist options
  • Save andrei512/3794449 to your computer and use it in GitHub Desktop.
Save andrei512/3794449 to your computer and use it in GitHub Desktop.
simple API security
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