Created
March 10, 2013 13:37
-
-
Save Godoy/5128597 to your computer and use it in GitHub Desktop.
Devise - Autenticação por Token como parâmetro no Header
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 Api::ApiController < ActionController::Base | |
| prepend_before_filter :get_auth_token | |
| respond_to :json | |
| public | |
| def restrict_access | |
| api_key = User.find_by_authentication_token(params[:auth_token]) | |
| head :unauthorized unless api_key | |
| end | |
| private | |
| def get_auth_token | |
| if auth_token = params[:auth_token].blank? && request.headers["X-AUTH-TOKEN"] | |
| params[:auth_token] = auth_token | |
| end | |
| end | |
| end |
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 Api::UsersController < Api::ApiController | |
| before_filter :restrict_access, :except => [:create, :login] | |
| ..... | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment