在我们的应用程序中,我们允许用户使用 Omniauth 通过可用的 API 访问不同提供商(Google 日历、Microsoft Outlook、Facebook 时间线等)的数据。为此,我们拥有omniauth.rb
所有必要的配置,例如:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], scope: 'email,user_posts,user_status,public_profile,manage_pages,instagram_basic'
provider :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_CLIENT_SECRET'],
name: 'google',
scope: 'email, profile, calendar.readonly',
access_type: 'offline',
prompt: 'select_account consent'
# etc...
end
现在我们希望添加使用 Google 登录作为登录的替代方式。由于我们使用 Devise 进行用户会话管理,因此我们希望使用 Devise 的 Omniauth 功能来实现使用 OAuth 提供商(如 Google)的登录。但是,一旦我们将模型设为“omniauthable”,现有的 Omniauth 功能就会No route matches [GET] "/auth/facebook"
在尝试添加 oauth 帐户以访问 API 时停止工作。
在 Devise 和我们自己的普通 OAuth 流程中结合使用 Omniauth 的正确方法是什么?