[英]Devise authentication token
在設計中,我如何訪問用戶的身份驗證令牌。 當ajax調用啟動用戶會話時,我需要能夠從用戶那里獲取身份驗證令牌。 我嘗試過在我的模型中添加:token_authenticable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
還添加了以下名稱的屬性:authentication_token和:authenticity_token到attr_accessible。 但是每當我嘗試用user.auth調用authentication_token或者authenticity_token時,我會收到像這樣的錯誤
NoMethodError: undefined method `authentication_token' for #<User:0x000001016b1140>
對不起,我需要通過我的ajax調用來獲取此令牌,(我工作的最后一個項目我有一個令人難以置信的BOOTLEG解決方案,其中設備幾乎被撕掉了應用程序,我只需要這個該死的令牌)
通過將:token_authenticatable
模塊包含到devise
用戶模型中來解決此問題:
devise :token_authenticatable, ...
此方法也是在類本身上定義的,而不是實例。 將其稱為User.authentication_token
。
請參見: https : //github.com/plataformatec/devise/blob/master/lib/devise/models/token_authenticatable.rb#L61-63 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.