Skip to content

Instantly share code, notes, and snippets.

@mscoutermarsh
Created November 24, 2012 23:03
Show Gist options
  • Select an option

  • Save mscoutermarsh/4141736 to your computer and use it in GitHub Desktop.

Select an option

Save mscoutermarsh/4141736 to your computer and use it in GitHub Desktop.
Authentication helpers
helpers do
def authenticate!
error!('Unauthorized. Invalid or expired token.', 401) unless current_user
end
def current_user
# find token. Check if valid.
user_token = params[:token]
token = ApiKey.where(:access_token => user_token).first
if token && !token.expired?
@current_user = User.find(token.user_id)
else
false
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment