Skip to content

Instantly share code, notes, and snippets.

@Godoy
Created March 10, 2013 13:37
Show Gist options
  • Select an option

  • Save Godoy/5128597 to your computer and use it in GitHub Desktop.

Select an option

Save Godoy/5128597 to your computer and use it in GitHub Desktop.
Devise - Autenticação por Token como parâmetro no Header
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
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