Ruby on rails rails api和身份验证
我在验证对Rails API的请求时遇到问题 在我的应用程序控制器中,我使用了以下代码Ruby on rails rails api和身份验证,ruby-on-rails,rails-api,Ruby On Rails,Rails Api,我在验证对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_sessio
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永远不会到达。有人知道这是为什么吗?似乎您的应用程序控制器需要:
您使用的是哪个版本的rails?
include ActionController::HttpAuthentication::Token::ControllerMethods