Created
November 24, 2012 23:03
-
-
Save mscoutermarsh/4141736 to your computer and use it in GitHub Desktop.
Authentication helpers
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
| 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