1
Я пытаюсь создать очень простой аутентификатор, но, к сожалению, я получаю нуль в ответ, вызывая мой маршрут до 401 с момента его несанкционированного доступа.authenticate_with_http_token оценивает в nil
[20] pry(#<API::UsersController>)>
ActionController::HttpAuthentication::Token::ControllerMethods.authenticate_with_http_token
NoMethodError: undefined method `authenticate_with_http_token' for
ActionController::HttpAuthentication::Token::ControllerMethods:Module
[22] pry(#<API::UsersController>)> cd
ActionController::HttpAuthentication::Token::ControllerMethods
[23] pry(#<Module>):1> ls
ActionController::HttpAuthentication::Token::ControllerMethods#methods:
authenticate_or_request_with_http_token authenticate_with_http_token
request_http_token_authentication
locals: _ __ _dir_ _ex_ _file_ _in_ _out_ _pry_
[24] pry(#<Module>):1>
Код:
protected
def authenticate
authenticate_token || render_unauthorized
end
def authenticate_token
binding.pry
authenticate_with_http_token do |token, options|
User.find_by(auth_token: token)
end
end
def render_unauthorized
self.headers['WWW-Authenticate'] = 'Token realm="Application"'
render json: 'Bad credentials', status: 401
end