我使用gem devise和omniauth登录我的应用程序的facebook帐户, 当我在开发环境中,它运行良好,没有错误。 但是当我推送到Heroku生产环境时,facebook登录回调将是RuntimeError。 困扰我的最奇怪的事情是我在本地开发环境中完全没问题。但它在Heroku上出错了。
PS我确实记得添加Heroku配置:设置facebook_app_id和facebooK_secret设置参数。我不知道发生了什么。谢谢你的帮助。
以下是错误日志。
(摘要)
MESSAGE 100.0% RuntimeError: --- !ruby/hash:OmniAuth::AuthHash provider: facebook uid: '100002129143525' info: !ruby/hash:OmniAuth::AuthHash::InfoHash nickname: yettie.lin email: yettie.lin@gmail.com name: Yettie Lin first_name: Yettie last_name: Lin image: http://graph.facebook.com/100002129143525/picture?type=square urls: !ruby/hash:OmniAuth::AuthHash Facebook: https://www.facebook.com/yettie.lin credentials: !ruby/hash:OmniAuth::AuthHash token: CAAUfP3P53roBAGaYbjPq89MsvR5Yy2FEMuK42PhQiZCgKAHy6paXQgTkhtlD7zmPmvi7yVlDsB5UgkNZAKkCSbmAbc3mlWgi95zIhAhDDpapmIIPSKpFnPuDgwqTgGsHlePpK7fGebnCbCfAZBysQ75wMZBJEwWKHXN0gMjQnBoMQMXXBUTDxS4XHEVoMisZD expires_at: 1394891723 expires: true extra: !ruby/hash:OmniAuth::AuthHash raw_info: !ruby/hash:OmniAuth::AuthHash id: '100002129143525' name: Yettie Lin first_name: Yettie last_name: Lin link: https://www.facebook.com/yettie.lin gender: male email: yettie.lin@gmail.com timezone: 8 locale: zh_TW updated_time: '2014-01-11T15:52:06+0000' username: yettie.lin
ERROR CLASS RuntimeError
URL http://dan-group-post.herokuapp.com/users/auth/facebook/callback?code=AQCP49MdSSopYTAYIOM-J3WILj2mmZ8-67bEVlPgY-4TXn6tWJBiesqkdLutnAoNvStnplOncQLh_PFOByCMJkdaAnC6j6TTn5hBFL369JRTsAH4xwvk44CBBF74SyQkfwdwaCDBGQvDbI2e6CgVqV19CNT8fX_AyMant_luLB6fHhIzhqnn8wKMYTJKZlr27n6fcRfP91zwU3QuLHs6IbkjE4JqdHFi8W2OjwVpAHZReBC_olFZm1vLAXaGZDPQIJWUWzKMlyio5WPIuyIl9yxtgmT3n1CAlGiFdg89SwRcY18cGa67AZzcW3S6IUD7zVQ&state=1ba64f8c892236e20691beab5d42ed97c93a10ddfd893576
WHERE users/omniauth_callbacks#facebook
OCCURRED Jan 15 01:16:15
SIMILAR 0
BROWSER 100.0% Chrome 31.0.1650.63 (OS X 10.9.1)
TENANT 100.0% dan-group-post.herokuapp.com
APP SERVER c3f4241c-8efa-4371-b08d-9fd7e48d0e53
FRAMEWORK Rails: 4.0.0
REL. DIRECTORY /app
回溯:
app/controllers/user/omniauth_callbacks_controller.rb:3→ facebook
actionpack-4.0.0/lib/action_controller/metal/implicit_render.rb:4→ send_action
参数:
ATEWAY_INTERFACE CGI/1.1
HTTP_ACCEPT text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
HTTP_ACCEPT_ENCODING gzip,deflate,sdch
HTTP_ACCEPT_LANGUAGE zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
HTTP_CACHE_CONTROL max-age=0
HTTP_CONNECTION close
HTTP_HOST dan-group-post.herokuapp.com
HTTP_USER_AGENT Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
HTTP_VERSION HTTP/1.1
HTTP_X_FORWARDED_FOR 112.105.105.89
HTTP_X_FORWARDED_PORT 80
HTTP_X_FORWARDED_PROTO http
HTTP_X_REQUEST_START 1389719774638
ORIGINAL_FULLPATH /users/auth/facebook/callback?code=AQCP49MdSSopYTAYIOM-J3WILj2mmZ8-67bEVlPgY-4TXn6tWJBiesqkdLutnAoNvStnplOncQLh_PFOByCMJkdaAnC6j6TTn5hBFL369JRTsAH4xwvk44CBBF74SyQkfwdwaCDBGQvDbI2e6CgVqV19CNT8fX_AyMant_luLB6fHhIzhqnn8wKMYTJKZlr27n6fcRfP91zwU3QuLHs6IbkjE4JqdHFi8W2OjwVpAHZReBC_olFZm1vLAXaGZDPQIJWUWzKMlyio5WPIuyIl9yxtgmT3n1CAlGiFdg89SwRcY18cGa67AZzcW3S6IUD7zVQ&state=1ba64f8c892236e20691beab5d42ed97c93a10ddfd893576
ORIGINAL_SCRIPT_NAME
PATH_INFO /users/auth/facebook/callback
QUERY_STRING code=AQCP49MdSSopYTAYIOM-J3WILj2mmZ8-67bEVlPgY-4TXn6tWJBiesqkdLutnAoNvStnplOncQLh_PFOByCMJkdaAnC6j6TTn5hBFL369JRTsAH4xwvk44CBBF74SyQkfwdwaCDBGQvDbI2e6CgVqV19CNT8fX_AyMant_luLB6fHhIzhqnn8wKMYTJKZlr27n6fcRfP91zwU3QuLHs6IbkjE4JqdHFi8W2OjwVpAHZReBC_olFZm1vLAXaGZDPQIJWUWzKMlyio5WPIuyIl9yxtgmT3n1CAlGiFdg89SwRcY18cGa67AZzcW3S6IUD7zVQ&state=1ba64f8c892236e20691beab5d42ed97c93a10ddfd893576
REMOTE_ADDR 10.10.155.37
REMOTE_HOST 10.10.155.37
REQUEST_METHOD GET
REQUEST_PATH /users/auth/facebook/callback
REQUEST_URI http://dan-group-post.herokuapp.com/users/auth/facebook/callback?code=AQCP49MdSSopYTAYIOM-J3WILj2mmZ8-67bEVlPgY-4TXn6tWJBiesqkdLutnAoNvStnplOncQLh_PFOByCMJkdaAnC6j6TTn5hBFL369JRTsAH4xwvk44CBBF74SyQkfwdwaCDBGQvDbI2e6CgVqV19CNT8fX_AyMant_luLB6fHhIzhqnn8wKMYTJKZlr27n6fcRfP91zwU3QuLHs6IbkjE4JqdHFi8W2OjwVpAHZReBC_olFZm1vLAXaGZDPQIJWUWzKMlyio5WPIuyIl9yxtgmT3n1CAlGiFdg89SwRcY18cGa67AZzcW3S6IUD7zVQ&state=1ba64f8c892236e20691beab5d42ed97c93a10ddfd893576
ROUTES_69923930432140_SCRIPT_NAME
SCRIPT_NAME
SERVER_NAME dan-group-post.herokuapp.com
SERVER_PORT 80
SERVER_PROTOCOL HTTP/1.1
SERVER_SOFTWARE WEBrick/1.3.1 (Ruby/2.0.0/2013-11-22)
ACTION_DISPATCH_PARAMETER_FILTER ["password"]
ACTION_DISPATCH_REDIRECT_FILTER []
ACTION_DISPATCH_REMOTE_IP 112.105.105.89
ACTION_DISPATCH_REQUEST_CONTENT_TYPE
ACTION_DISPATCH_REQUEST_FORMATS ["text/html"]
ACTION_DISPATCH_REQUEST_ID 65857625-8e21-40fd-82fb-5870f8c70d33
ACTION_DISPATCH_REQUEST_PARAMETERS {"code"=>"AQCP49MdSSopYTAYIOM-J3WILj2mmZ8-67bEVlPgY-4TXn6tWJBiesqkdLutnAoNvStnplOncQLh_PFOByCMJkdaAnC6j6TTn5hBFL369JRTsAH4xwvk44CBBF74SyQkfwdwaCDBGQvDbI2e6CgVqV19CNT8fX_AyMant_luLB6fHhIzhqnn8wKMYTJKZlr27n6fcRfP91zwU3QuLHs6IbkjE4JqdHFi8W2OjwVpAHZReBC_olFZm1vLAXaGZDPQIJWUWzKMlyio5WPIuyIl9yxtgmT3n1CAlGiFdg89SwRcY18cGa67AZzcW3S6IUD7zVQ", "state"=>"1ba64f8c892236e20691beab5d42ed97c93a10ddfd893576", "controller"=>"users/omniauth_callbacks", "action"=>"facebook"}
ACTION_DISPATCH_REQUEST_PATH_PARAMETERS {"controller"=>"users/omniauth_callbacks", "action"=>"facebook"}
ACTION_DISPATCH_REQUEST_QUERY_PARAMETERS {"code"=>"AQCP49MdSSopYTAYIOM-J3WILj2mmZ8-67bEVlPgY-4TXn6tWJBiesqkdLutnAoNvStnplOncQLh_PFOByCMJkdaAnC6j6TTn5hBFL369JRTsAH4xwvk44CBBF74SyQkfwdwaCDBGQvDbI2e6CgVqV19CNT8fX_AyMant_luLB6fHhIzhqnn8wKMYTJKZlr27n6fcRfP91zwU3QuLHs6IbkjE4JqdHFi8W2OjwVpAHZReBC_olFZm1vLAXaGZDPQIJWUWzKMlyio5WPIuyIl9yxtgmT3n1CAlGiFdg89SwRcY18cGa67AZzcW3S6IUD7zVQ", "state"=>"1ba64f8c892236e20691beab5d42ed97c93a10ddfd893576"}
ACTION_DISPATCH_REQUEST_REQUEST_PARAMETERS
ACTION_DISPATCH_SHOW_DETAILED_EXCEPTIONS false
ACTION_DISPATCH_SHOW_EXCEPTIONS true
DEVISE_MAPPING #<Devise::Mapping:0x007f30dca29e28>
DEVISE_SKIP_TIMEOUT true
OMNIAUTH_AUTH {"provider"=>"facebook", "uid"=>"100002129143525", "info"=>{"nickname"=>"yettie.lin", "email"=>"yettie.lin@gmail.com", "name"=>"Yettie Lin", "first_name"=>"Yettie", "last_name"=>"Lin", "image"=>"http://graph.facebook.com/100002129143525/picture?type=square", "urls"=>{"Facebook"=>"https://www.facebook.com/yettie.lin"}}, "credentials"=>{"token"=>"CAAUfP3P53roBAGaYbjPq89MsvR5Yy2FEMuK42PhQiZCgKAHy6paXQgTkhtlD7zmPmvi7yVlDsB5UgkNZAKkCSbmAbc3mlWgi95zIhAhDDpapmIIPSKpFnPuDgwqTgGsHlePpK7fGebnCbCfAZBysQ75wMZBJEwWKHXN0gMjQnBoMQMXXBUTDxS4XHEVoMisZD", "expires_at"=>"1394891723", "expires"=>"true"}, "extra"=>{"raw_info"=>{"id"=>"100002129143525", "name"=>"Yettie Lin", "first_name"=>"Yettie", "last_name"=>"Lin", "link"=>"https://www.facebook.com/yettie.lin", "gender"=>"male", "email"=>"yettie.lin@gmail.com", "timezone"=>"8", "locale"=>"zh_TW", "updated_time"=>"2014-01-11T15:52:06+0000", "username"=>"yettie.lin"}}}
OMNIAUTH_ORIGIN http://dan-group-post.herokuapp.com/
OMNIAUTH_PARAMS
OMNIAUTH_STRATEGY #<OmniAuth::Strategies::Facebook:0x007f30e05e9648>
RACK_MULTIPROCESS false
RACK_MULTITHREAD false
RACK_REQUEST_QUERY_HASH {"code"=>"AQCP49MdSSopYTAYIOM-J3WILj2mmZ8-67bEVlPgY-4TXn6tWJBiesqkdLutnAoNvStnplOncQLh_PFOByCMJkdaAnC6j6TTn5hBFL369JRTsAH4xwvk44CBBF74SyQkfwdwaCDBGQvDbI2e6CgVqV19CNT8fX_AyMant_luLB6fHhIzhqnn8wKMYTJKZlr27n6fcRfP91zwU3QuLHs6IbkjE4JqdHFi8W2OjwVpAHZReBC_olFZm1vLAXaGZDPQIJWUWzKMlyio5WPIuyIl9yxtgmT3n1CAlGiFdg89SwRcY18cGa67AZzcW3S6IUD7zVQ", "state"=>"1ba64f8c892236e20691beab5d42ed97c93a10ddfd893576"}
RACK_REQUEST_QUERY_STRING code=AQCP49MdSSopYTAYIOM-J3WILj2mmZ8-67bEVlPgY-4TXn6tWJBiesqkdLutnAoNvStnplOncQLh_PFOByCMJkdaAnC6j6TTn5hBFL369JRTsAH4xwvk44CBBF74SyQkfwdwaCDBGQvDbI2e6CgVqV19CNT8fX_AyMant_luLB6fHhIzhqnn8wKMYTJKZlr27n6fcRfP91zwU3QuLHs6IbkjE4JqdHFi8W2OjwVpAHZReBC_olFZm1vLAXaGZDPQIJWUWzKMlyio5WPIuyIl9yxtgmT3n1CAlGiFdg89SwRcY18cGa67AZzcW3S6IUD7zVQ&state=1ba64f8c892236e20691beab5d42ed97c93a10ddfd893576
RACK_RUN_ONCE false
RACK_URL_SCHEME http
RACK_VERSION ["1", "2"]
WARDEN Warden::Proxy:69923949726820 @config={:default_scope=>:user, :scope_defaults=>{}, :default_strategies=>{:user=>[:rememberable, :database_authenticatable]}, :intercept_401=>false, :failure_app=>#<Devise::Delegator:0x007f30dec74028>}
以下是我的代码和配置设置。感谢帮助。
route.rb:
Groupme::Application.routes.draw do
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
root :to => "groups#index"
resources :groups do
member do
post :join
post :quit
end
resources :posts
end
namespace :account do
resources :groups
resources :posts
end
end
应用程序/控制器/用户/ omniauth_callbacks_controller.rb
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
raise request.env['omniauth.auth'].to_yaml
@user = User.find_for_facebook_oauth(request.env["omniauth.auth"])
if @user.persisted?
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
end
应用程序/模型/ user.rb
class User < ActiveRecord::Base
has_many :groups
has_many :posts
has_many :group_users
has_many :participated_groups, :through => :group_users, :source => :group
extend OmniauthCallbacks
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
def join!(group)
participated_groups << group
end
def quit!(group)
participated_groups.delete(group)
end
def is_member_of?(group)
participated_groups.include?(group)
end
def self.find_for_facebook_oauth(auth)
user = User.where(provider: auth.provider, fb_id: auth.uid).first
unless user
user = User.create( name: auth.extra.raw_info.name,
provider: auth.provider,
fb_id: auth.uid,
email: auth.info.email,
token: auth.credentials.token,
password: Devise.friendly_token[0,20] )
end
return user
end
end
app / views / common / _user_nav.html.erb(登录链接的导航栏)
<ul class="nav pills pull-right">
<li>
<div class="social"> <%= fb_like(Setting.domain) %> </div>
</li>
<% if current_user %>
<li class="dropdown">
<%= link_to "/account" , :class => "dropdown-toggle", :data => { :toggle => "dropdown" } do %>
<%= current_user.email %>
<% end %>
<%= render_list :class => "dropdown-menu" do |li|
li << link_to("My Group", account_groups_path)
li << link_to("My Post", account_posts_path)
li << link_to("Logout",destroy_user_session_path, :method => :delete )
end %>
</li>
<% else %>
<li> <%= link_to( "Sign Up" ,new_user_registration_path) %> </li>
<li> <%= link_to( "Login", new_user_session_path ) %> </li>
<li> <%= link_to( "FB Login", user_omniauth_authorize_path(:facebook) ) %> </li>
<% end %>
</ul>
和config.yml
defaults: &defaults
hipchat_token:
hipchat_room_name:
admin_emails:
- ""
google_analytics_key: ""
default_logo_url: "/logo.png"
email_sender: ""
development:
<<: *defaults
facebook_app_id: XXXX709306
facebook_secret: "XXXXcf19353d630ddffBBBBBB595"
app_name: "groupme"
domain: "http://groupme.dev"
test:
<<: *defaults
production:
<<: *defaults
facebook_app_id: XXXXX72709306
facebook_secret: "XXXXcf19353d630ddffBBBBBB595"
app_name: "groupme"
domain: "http://dan-group-post.herokuapp.com"
和Gemfile
source 'https://rubygems.org'
ruby '2.0.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'
# Use sqlite3 as the database for Active Record
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'devise', '3.0.2'
gem "seo_helper", "~> 1.0.2"
gem "open_graph_helper"
gem "rmagick"
gem "carrierwave"
gem "carrierwave-meta"
gem "settingslogic"
gem "anjlab-bootstrap-rails", "2.3.1.2", :require => "bootstrap-rails"
gem "bootstrap_helper", ">= 4.2.2.1"
gem "simple_form", "~> 3.0.1"
gem "will_paginate", "3.0.3"
gem "font-awesome-rails", "~> 3.2.1.3"
gem "high_voltage"
gem "airbrake"
gem "rvm-capistrano"
gem "omniauth"
gem "omniauth-facebook"
gem "auto-facebook", "0.4"
gem "whenever"
gem "hipchat"
# Cache
gem "dalli"
gem "compass-rails", "~> 1.1.2"
group :development do
gem 'sqlite3'
gem "capistrano"
gem "capistrano-ext"
gem "cape"
gem "binding_of_caller"
gem "better_errors", "~> 0.9.0"
gem "magic_encoding"
gem "annotate"
gem "powder"
gem "pry-nav"
gem "pry-remote"
end
group :production do
gem 'pg', '0.15.1'
gem "cape"
gem "binding_of_caller"
gem "better_errors", "~> 0.9.0"
gem "magic_encoding"
gem "annotate"
gem "powder"
gem "pry-nav"
gem "pry-remote"
end
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end