nsarno / knock

Seamless JWT authentication for Rails API
MIT License
2.07k stars 253 forks source link

Response with Bad Credencials #246

Closed GabrielBortolote closed 4 years ago

GabrielBortolote commented 5 years ago

If i send a Good Credencials post to my UserTokenController < Knock::AuthTokenController the default render object is a jbuilder wich the same name than the action in the controller. But if i send bad credencials, the only thing i can handle on the response is the status: 404. The action called by the routes for this path is not called too, just the method auth_params, unabling me to create a middle-way to handle the rendering object. But i need handle it. There is something blinding me ?

class UserTokenController < Knock::AuthTokenController

  def create
    @user = User.find(auth_token.payload[:sub])
    @auth_token = auth_token
  end

  def auth_params
    debugger
    login_param = Company.find(params[:company_id]).login_attribute
    params.require(:auth).permit(login_param, :password)
  end
end
sshaw commented 5 years ago

Can't you override unauthorized_entity? https://github.com/nsarno/knock#usage

GabrielBortolote commented 5 years ago

I solved the problem this way:

class UserTokenController < Knock::AuthTokenController

  rescue_from Knock.not_found_exception_class_name, with: :bad_request

  def bad_request
    render status: 404
  end

  def create
    @user = User.find(auth_token.payload[:sub])
    @auth_token = auth_token
  end

  def auth_params
    login_param = Company.find(params[:company_id]).login_attribute
      params.permit(login_param, :password)
  end
end