0

在我们的应用程序中,我们允许用户使用 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 的正确方法是什么?

4

1 回答 1

0

我自己找到了答案:问题在于不使用 Devise 添加到 OmniAuth 的功能的薄包装,而是自己处理 OmniAuth 路由。我在 Devise Wiki 中描述了这种方法。

于 2020-01-09T21:21:57.583 回答