我在验证对Rails API发出的请求时遇到问题。
在我的应用程序控制器中,我有以下代码
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
# protect_from_forgery with: :null_session, if: Proc.new { |c| c.request.format == 'application/json' }
before_filter :authenticate_user_from_token!
private
def authenticate_user_from_token!
Rails.logger.debug "Authenticating..." <---------- (1)
authenticate_with_http_token do |token, options|
Rails.logger.debug "options: #{options.inspect}" <-----------------------(2)
user_email = options[:user_email].presence
user = user_email && User.find_by_email(user_email)
if user && Devise.secure_compare(user.authentication_token, token)
sign_in user, store: false
end
end
end
end但问题是,当(1)被执行和记录时,(2)由于某种原因永远不会到达。有谁知道为什么会这样吗?
发布于 2015-03-04 06:56:50
看起来你的ApplicationController需要:
include ActionController::HttpAuthentication::Token::ControllerMethodshttps://stackoverflow.com/questions/27693726
复制相似问题