0

我有带有 oauth2、omniauth 和 fb_graph 的应用程序,并且在本地工作得很好。我有开发、测试和生产环境。我的omniauth.rb是

  if Rails.env.production?
 provider :twitter, '***', '***'
 provider :facebook, '***', '***', {:scope => 'user_about_me,friends_about_me,user_activities,friends_activities,user_birthday,friends_birthday,user_checkins,friends_checkins,user_education_history,friends_education_history,user_events,friends_events,user_groups,friends_groups,user_hometown,friends_hometown,user_interests,friends_interests,user_likes,friends_likes,user_location,friends_location,user_notes,friends_notes,user_online_presence,friends_online_presence,user_photo_video_tags,friends_photo_video_tags,user_photos,friends_photos,user_questions,friends_questions,user_relationships,friends_relationships,user_relationship_details,friends_relationship_details,user_religion_politics,friends_religion_politics,user_status,friends_status,user_videos,friends_videos,user_website,friends_website,user_work_history,friends_work_history,email,read_friendlists,read_insights,read_mailbox,read_requests,read_stream,xmpp_login,ads_management,create_event,manage_friendlists,manage_notifications,offline_access,publish_checkins,publish_stream,rsvp_event,publish_actions,manage_pages,user_subscriptions', :client_options => {:ssl => {:ca_file => "/usr/lib/ssl/certs/ca-certificates.crt"}}}
 elsif Rails.env.development?
 provider :twitter, '******',     '******'
 provider :facebook, '******', '*******', :scope => 'user_about_me,friends_about_me,user_activities,friends_activities,user_birthday,friends_birthday,user_checkins,friends_checkins,user_education_history,friends_education_history,user_events,friends_events,user_groups,friends_groups,user_hometown,friends_hometown,user_interests,friends_interests,user_likes,friends_likes,user_location,friends_location,user_notes,friends_notes,user_online_presence,friends_online_presence,user_photo_video_tags,friends_photo_video_tags,user_photos,friends_photos,user_questions,friends_questions,user_relationships,friends_relationships,user_relationship_details,friends_relationship_details,user_religion_politics,friends_religion_politics,user_status,friends_status,user_videos,friends_videos,user_website,friends_website,user_work_history,friends_work_history,email,read_friendlists,read_insights,read_mailbox,read_requests,read_stream,xmpp_login,ads_management,create_event,manage_friendlists,manage_notifications,offline_access,publish_checkins,publish_stream,rsvp_event,publish_actions,manage_pages,user_subscriptions', :client_options => {:ssl => {:ca_file => "/etc/ssl/certs"}}

身份验证后的本地化使用此重定向 uri 进行授权

 http://www.facebook.com/dialog/permissions.request?_path=permissions.request&app_id=*******&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Ffacebook%2Fcallback&display=page&response_type=code&perms=user_about_me%2Cfriends_about_me%2Cuser_activities%2Cfriends_activities%2Cuser_birthday%2Cfriends_birthday%2Cuser_checkins%2Cfriends_checkins%2Cuser_education_history%2Cfriends_education_history%2Cuser_events%2Cfriends_events%2Cuser_groups%2Cfriends_groups%2Cuser_hometown%2Cfriends_hometown%2Cuser_interests%2Cfriends_interests%2Cuser_likes%2Cfriends_likes%2Cuser_location%2Cfriends_location%2Cuser_notes%2Cfriends_notes%2Cuser_online_presence%2Cfriends_online_presence%2Cuser_photo_video_tags%2Cfriends_photo_video_tags%2Cuser_photos%2Cfriends_photos%2Cuser_questions%2Cfriends_questions%2Cuser_relationships%2Cfriends_relationships%2Cuser_relationship_details%2Cfriends_relationship_details%2Cuser_religion_politics%2Cfriends_religion_politics%2Cuser_status%2Cfriends_status%2Cuser_videos%2Cfriends_videos%2Cuser_website%2Cfriends_website%2Cuser_work_history%2Cfriends_work_history%2Cemail%2Cread_friendlists%2Cread_insights%2Cread_mailbox%2Cread_requests%2Cread_stream%2Cxmpp_login%2Cads_management%2Ccreate_event%2Cmanage_friendlists%2Cmanage_notifications%2Coffline_access%2Cpublish_checkins%2Cpublish_stream%2Crsvp_event%2Cpublish_actions%2Cmanage_pages%2Cuser_subscriptions&fbconnect=1&from_login=1&client_id=******

这是正确的重定向 uri。

但是在身份验证后的heroku中,使用此重定向uri进行授权

 http://www.facebook.com/dialog/permissions.request?_path=permissions.request&app_id=******&redirect_uri=http%3A%2F%2Feap2.heroku.com%2Fauth%2Ffacebook%2Fcallback&display=page&response_type=code&perms=email%2Coffline_access&fbconnect=1&from_login=1&client_id=*******

这是错误的;显然缺少权限。我不知道为什么。

ps我的gemfile

  source 'http://rubygems.org'

  gem 'rails', '3.0.11'
  gem 'pg'
  gem 'devise'
  gem "recaptcha", :require => "recaptcha/rails"
  gem 'sinatra'
  gem 'mogli'
  gem 'gravatar_image_tag', '1.0.0.pre2'
  gem 'rails-i18n'
  gem 'will_paginate', '~> 3.0.pre2'
  gem 'RedCloth'
  gem 'coderay'
  gem 'validate_url'
  gem 'thin'
  gem 'acts-as-taggable-on', '~> 2.2.2'
  gem 'omniauth'
  gem 'omniauth-twitter'
  gem 'omniauth-facebook'
  gem 'omniauth-openid'
  gem 'omniauth-github'
  gem 'multi_json'
  gem 'dalli'
  gem 'oauth2'
  gem 'fb_graph'

  group     :test do
     gem 'sqlite3'
  end
4

1 回答 1

0

我之前的production.rb

  config.cache_classes = true
  config.cache_store = :dalli_store
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.action_mailer.default_url_options = { :host => 'eap2.heroku.com' }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
     :address              => "smtp.gmail.com",
     :port                 => 587,
     :domain               => 'gmail.com',
     :user_name            => '****@gmail.com',
     :password             => '*****',
     :authentication       => 'plain',
     :enable_starttls_auto => true  }
  config.action_dispatch.x_sendfile_header = "X-Sendfile"
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
  provider :twitter, '***', '***'
  provider :facebook, '***', '***', :scope => user_about_me,friends_about_me,user_activities,friends_activities
 end

和我的解决方案后的生产 rb

  config.cache_classes = true
  config.cache_store = :dalli_store
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.action_mailer.default_url_options = { :host => 'eap2.heroku.com' }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
     :address              => "smtp.gmail.com",
     :port                 => 587,
     :domain               => 'gmail.com',
     :user_name            => '****@gmail.com',
     :password             => '*****',
     :authentication       => 'plain',
     :enable_starttls_auto => true  }
  config.action_dispatch.x_sendfile_header = "X-Sendfile"
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
  end

这意味着 Rails 只需要 config/initializers/omniauth.rb 文件而不是 config/environements/production.rb 文件中的 twitter 和 facebook 配置。

于 2012-04-23T14:32:22.340 回答