首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >rails-api和身份验证

rails-api和身份验证
EN

Stack Overflow用户
提问于 2014-12-30 01:57:56
回答 1查看 117关注 0票数 0

我在验证对Rails API发出的请求时遇到问题。

在我的应用程序控制器中,我有以下代码

代码语言:javascript
复制
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)由于某种原因永远不会到达。有谁知道为什么会这样吗?

EN

回答 1

Stack Overflow用户

发布于 2015-03-04 06:56:50

看起来你的ApplicationController需要:

代码语言:javascript
复制
include ActionController::HttpAuthentication::Token::ControllerMethods
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27693726

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档