【问题标题】:How to work with Session in Rails_API gem如何在 Rails_API gem 中使用 Session
【发布时间】:2013-09-26 05:09:37
【问题描述】:

目前我正在我的项目和那个项目中工作 使用 rails_api 宝石。我想为身份验证添加会话管理,但是 它 似乎会话不起作用。这是我的配置 config/initializer/session_store.rb:

Pmcapi::Application.config.session_store :cookie_store, {

key: '_pmcapi_session',
expire_after: 1.hour

}

在我的 session_controller 中,我添加了会话来存储令牌

(在 session_controller.rb 中)

def create
  #just to generate new token
  user.reset_sso_token!
  session[:token] ||= user.sso_token
  self.current_user = user
  redirect_to root_path
end

when i am in application_controller, i want to access session[:token] 
but
the result is nil (in application_controller.rb)

def authenticate_user!
  #puts("User Authentication")
  #puts(request.authorization)
  #puts(request)
  @user = User.authenticate_with_token(session[:token])
  #head :unauthorized unless @user.present?
  redirect_to sign_in_path if @user.nil?
end

拜托,我需要帮助。我一直坚持这个,谢谢

【问题讨论】:

    标签: ruby-on-rails ruby session


    【解决方案1】:

    您是否按照documentation 中的说明在配置文件中添加了config.api_only = false

    会话管理:如果提供了 config.session_store 并且 config.api_only = false,此中间件使会话可用 作为 ActionController 中的会话方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-18
      • 2012-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-28
      相关资源
      最近更新 更多