Ruby on rails 轨道-设计+;OmniAuth:如何设置登台版本的凭据?
在/config/initializers/designe.rb中,我有如下内容: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
# 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
这种方法有几个优点:
处理不同凭据的最佳方法是将它们放在环境变量中,就像omniauth gem doc所说: 这种方法有几个优点: