1

/config/initializers/devise.rb我有这样的东西:

  # production
  config.omniauth :facebook, 'aaa', 'bbb',
      :site              => 'https://graph.facebook.com',
      :authorize_path    => '/oauth/authorize',
      :access_token_path => '/oauth/access_token',
      :scope => 'email'

  # staging version
  config.omniauth :facebook, 'ccc', 'ddd',
      :site              => 'https://graph.facebook.com',
      :authorize_path    => '/oauth/authorize',
      :access_token_path => '/oauth/access_token',
      :scope => 'email'

当我将这两个代码块放入devise.rb文件时,我收到错误消息,提示凭据不正确。

我不知道为 Twitter 和 Facebook 等服务设置 OmniAuth 凭据以进行设计的最佳方法是什么——我使用的那个显然是不正确的。

为应用程序的 localhost、生产和暂存版本设置凭据的最佳方法是什么?

谢谢

4

3 回答 3

1

看来您的凭据对于 localhost 是错误的。我有两个版本的开发和生产信用,这里是例子

if Rails.env.development?
    config.omniauth :facebook, "xxx", "yyy"
    config.omniauth :vkontakte, "xxx_loc", "yyy_loc"
else
    config.omniauth :facebook, "zzz", "rrr"
    config.omniauth :vkontakte, 'zzz_loc', 'rrr_loc'
end

在 /config/initializers/devise.rb

于 2013-08-07T12:50:07.807 回答
0

处理不同凭据的最佳方法是将它们放入环境变量中,就像omniauth gem doc 所说:

https://github.com/intridea/omniauth#getting-started

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :developer unless Rails.env.production?
  provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']
end

这种方法有几个优点:

  1. 它使您的配置简单
  2. 代码存储库中没有凭据
  3. 它不会限制您使用 dev/test/prod
于 2015-01-31T13:00:17.010 回答
0
case Rails.env
when "production"
    # production version
    config.omniauth :facebook, 'aaa', 'bbb',
            :site              => GRAPH_URL,
            :authorize_path    => '/oauth/authorize',
            :access_token_path => '/oauth/access_token',
            :scope => 'email'
when "staging"
    # staging version
    config.omniauth :facebook, 'ccc', 'ddd',
            :site              => GRAPH_URL,
            :authorize_path    => '/oauth/authorize',
            :access_token_path => '/oauth/access_token',
            :scope => 'email'
else
    # development version
    config.omniauth :facebook, 'eee', 'fff',
            :site              => GRAPH_URL,
            :authorize_path    => '/oauth/authorize',
            :access_token_path => '/oauth/access_token',
            :scope => 'email'
end
于 2013-09-13T12:58:52.380 回答