Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 轨道-设计+;OmniAuth:如何设置登台版本的凭据?_Ruby On Rails_Ruby_Devise_Omniauth - Fatal编程技术网

Ruby on rails 轨道-设计+;OmniAuth:如何设置登台版本的凭据?

Ruby on rails 轨道-设计+;OmniAuth:如何设置登台版本的凭据?,ruby-on-rails,ruby,devise,omniauth,Ruby On Rails,Ruby,Devise,Omniauth,在/config/initializers/designe.rb中,我有如下内容: # production config.omniauth :facebook, 'aaa', 'bbb', :site => 'https://graph.facebook.com', :authorize_path => '/oauth/authorize', :access_token_path => '/oauth

/config/initializers/designe.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'
当我将这两块代码放入designe.rb文件时,我得到一个错误,即存在不正确的凭证

我不知道为Desive的Twitter和Facebook等服务设置OmniAuth凭据的最佳方法是什么——我使用的方法显然不正确

为应用程序的本地主机、生产和登台版本设置凭据的最佳方法是什么


谢谢

您的本地主机凭据似乎有误。我有两个用于开发和生产的Credits版本,下面是一个示例

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/designe.rb上,您的本地主机凭据似乎有误。我有两个用于开发和生产的Credits版本,下面是一个示例

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
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

在/config/initializers/designe.rb中,处理不同凭证的最佳方法是将它们放入环境变量中,就像omniauth gem doc所说的那样:

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

这种方法有几个优点:

  • 它使您的配置保持简单
  • 代码存储库中没有凭据
  • 它并不限制您使用dev/test/prod

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

    这种方法有几个优点:

  • 它使您的配置保持简单
  • 代码存储库中没有凭据
  • 它并不限制您使用dev/test/prod