如何自定义生成的令牌的长度:token_authenticatable in devise - Rails 3? [英] How do I customize the length of the token generated in :token_authenticatable in devise - Rails 3?
本文介绍了如何自定义生成的令牌的长度:token_authenticatable in devise - Rails 3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我生成的令牌似乎是大约20个字符,我如何将长度更改为别的东西?
My token generated seems to be about 20 characters, how do I change the length to something else ?
我查看了 devise.rb
文件,并尝试两者:
I checked the devise.rb
file and tried both:
config.token_authentication_key = :access_key
config.token_authenticatable.length = 40
产生了此错误:
config/initializers/devise.rb:110:in `block in <top (required)>': undefined method `token_authenticatable' for Devise:Module (NoMethodError)
和
config.token_authentication_key = :access_key
config.token_authentication_key.length = 40
产生了此错误:
/config/initializers/devise.rb:110:in `block in <top (required)>': undefined method `length=' for :access_key:Symbol (NoMethodError)
当我尝试运行 安慰。
and both gave me errors when I tried to run the console.
有没有这样做?
推荐答案
提供设置此令牌长度的功能。您将必须覆盖模型上的 generate_token
方法,以更改此令牌的结果。
Devise does not provide a functionality to set the length of this token. You would have to override the generate_token
method on your model to change the outcome of this token.
这篇关于如何自定义生成的令牌的长度:token_authenticatable in devise - Rails 3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文