我有一个RoR应用程序,运行Devise Gem进行身份验证。对于我的新API,我已经实现了Gem“devise-token-auth”:https://github.com/lynndylanhurley/devise_token_auth
由于我希望Devise运行网站和API身份验证,我也遵循以下说明中的额外提示(以及Gem's Git的常见问题解答):http://www.developingandrails.com/2015/02/api-authentication-with-devisetokenauth.html
我已停用Devise's:确认,但已激活:omniauthable。一切似乎都已到位,但我收到以下错误:
/Users/sebastianplasschaert/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/devise-3.5.2/lib/devise/rails/routes.rb:240:in `block in devise_for': Mapping omniauth_callbacks on a resource that is not omniauthable (ArgumentError)
Please add `devise :omniauthable` to the `User` model
在我的用户模型中,我从以下代码开始:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :invitable, :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:omniauthable
include DeviseTokenAuth::Concerns::User
所以,:omniauthable似乎就在那里。当我停用时:
include DeviseTokenAuth::Concerns::User
然后一切都再次起作用(但我需要它用于我的API身份验证)。
关于我做错的任何想法?
答案 0 :(得分:6)
由于某种原因include DeviseTokenAuth::Concerns::User
删除了omniauthable
。
我修复了将其添加回来的问题:
devise :invitable, :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:omniauthable
include DeviseTokenAuth::Concerns::User
devise :omniauthable