百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
D

devise-token_authenticatable

> 编程语言
开源

此 gem 提供了 devise 中提取的 Token Authenticatable 模块。它使用户可以通过身份验证令牌进行登录。

171 stars0 点赞4 次浏览
访问官网GitHub

工具介绍

此 gem 提供了 devise 中提取的 Token Authenticatable 模块。它使用户可以通过身份验证令牌进行登录。

Devise::TokenAuthenticatable

This gem provides the extracted Token Authenticatable module of devise. It includes the functionality that was also in version 3.1.2 of devise. With the inclusion of this module a user is able to sign in via an authentication token. This token can be given via a query string or HTTP Basic Authentication. See the hint below to understand which version of this gem supports which version of devise.

Use this gem as a starting point for your own token authentication mechanism for devise. Furthermore, if you need token authentication in connection with newer devise releases this gem might be an appropriate solution, too.

Installation

Add this line to your application's Gemfile:

gem 'devise-token_authenticatable'

And then execute:

$ bundle

Or install it yourself as:

$ gem install devise-token_authenticatable

Which version to use for which version of devise?

devise-token_authenticatable devise
~> 0.1 ~> 3.2.0
~> 0.2 ~> 3.3.0
~> 0.3 ~> 3.4.0
~> 0.4.0, 3.5.0, 0.4.9 ~> 3.5.2
~> 0.5.x, = 4.0.0, 1.1.0 >= 4.0.0, < 5.0.0

Usage

Create needed columns with corresponding migration:

ruby
  def change
    add_column :users, :authentication_token, :text
    add_column :users, :authentication_token_created_at, :datetime

    add_index :users, :authentication_token, unique: true
  end

Add :token_authenticatable to your devise model:

ruby
class User < ActiveRecord::Base
  devise :database_authenticatable, :token_authenticatable
end

Configuration

This gem can be configured as shown in the following:

…

Enable devise's HTTP Auth for the token strategy as shown below:

ruby
# initializers/devise.rb
Devise.setup do |config|
  # ...
  config.http_authenticatable = true
  # or
  config.http_authenticatable = [:token]
  # ...
end

Troubleshooting

Using a new user's auth token does not result in invalidating an old users session. How can I ignore session storage when using token authentication?

Add :token_auth to your devise configuration:

ruby
Devise.setup do |config|
  config.skip_session_storage = [:http_auth, :token_auth]
end

Documentation

For your convenience there is also a source code documentation.

Contributing

  1. Fork it.
  2. Create your feature branch (git checkout -b my-new-feature).
  3. Commit your changes (git commit -am 'Add some feature').
  4. Push to the branch (git push origin my-new-feature).
  5. Create new Pull Request.
  6. Get a thank you!

Issues· 3 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言