简体   繁体   English

令牌寿命不适用于 devise auth token gem 和 devise in rails grape api

[英]token lifespan is not working with devise auth token gem and devise in rails grape api

I have a rails-grape api application that has been authenticated with devise.我有一个 rails-grape api 应用程序,该应用程序已通过 devise 进行身份验证。 Now I am trying to implement auto-session timeout with the apis.现在我正在尝试使用 api 实现自动会话超时。 For that I have implemented the devise_auth_token gem.为此,我实现了 devise_auth_token gem。

My devise_auth_token.rb我的 devise_auth_token.rb

DeviseTokenAuth.setup do |config|
  config.change_headers_on_each_request = false
  config.token_lifespan = 60.seconds
  config.batch_request_buffer_throttle = 30.seconds
end

I have run the install command as it was mentioned in the docs.我已经运行了文档中提到的安装命令。

rails g devise_token_auth:install User auth

I have updated my migration file like:我已经更新了我的迁移文件,例如:

 class DeviseTokenAuthCreateUsers < ActiveRecord::Migration[5.2]
  def change
   ## Required
   add_column :users, :provider, :string, null: false, default: "email"
   add_column :users, :uid, :string, null: false, default: ""

   ## Tokens
   add_column :users, :tokens, :json
   add_index :users, [:uid, :provider], unique: true
  end
end

My routes.rb我的路线.rb

devise_for :users, ActiveAdmin::Devise.config
 # token auth routes available at /api/v1/auth
  namespace :api do
    scope :v1 do
      mount_devise_token_auth_for 'User', at: 'auth'
    end
  end

As you can see that I have kept the token_lifespan to 60 seconds.如您所见,我将 token_lifespan 保持为 60 秒。 but even after I am inactive for almost 5 minutes, my session is not expiring.但即使在我闲置近 5 分钟后,我的 session 也不会过期。 I need help to understand that what I am missing/doing wrong here.我需要帮助来了解我在这里缺少/做错了什么。 Any help will be highly appreciated.任何帮助将不胜感激。

Thanks in advance.提前致谢。

As far as I remember session expire functionality works only with config.change_headers_on_each_request = true据我记得 session 过期功能仅适用于config.change_headers_on_each_request = true

Watch thishttps://github.com/lynndylanhurley/devise_token_auth/issues/573观看此https://github.com/lynndylanhurley/devise_token_auth/issues/573

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM