我已经尝试了所有方法,但无法从 facebook omniauth gem 中解决这个 NoAuthorizationCodeError 错误。
我基本上已经复制并粘贴了 railscasts ep360。我试图删除咖啡脚本,我已更改为 gem vs 1.4.0,我尝试了不同版本的 rails。
任何帮助,将不胜感激。
at=info method=GET path=/auth/facebook/callback host=enigmatic-sands-2189.herokuapp.com fwd="105.228.66.17" dyno=web.1 connect=2ms service=27ms status=500 bytes=643
2013-10-14T19:20:29.091206+00:00 heroku[router]: at=info method=GET path=/auth/facebook/callback host=enigmatic-sands-2189.herokuapp.com fwd="105.228.66.17" dyno=web.1 connect=14ms service=27ms status=500 bytes=643
2013-10-14T19:20:29.071596+00:00 app[web.1]: Started GET "/auth/facebook/callback" for 105.228.66.17 at 2013-10-14 19:20:29 +0000
2013-10-14T19:20:29.075493+00:00 app[web.1]: (facebook) Callback phase initiated.
2013-10-14T19:20:29.084256+00:00 app[web.1]:
2013-10-14T19:20:29.084256+00:00 app[web.1]: OmniAuth::Strategies::Facebook::NoAuthorizationCodeError (must pass either a `code` parameter or a signed request (via `signed_request` parameter or a `fbsr_XXX` cookie)):
会话控制器
class SessionsController < ApplicationController
def create
user = User.from_omniauth(env["omniauth.auth"])
session[:user_id] = user.id
redirect_to root_url
end
def destroy
session[:user_id] = nil
redirect_to root_url
end
end
路线
root to: 'static_pages#home'
match 'auth/:provider/callback', to: 'sessions#create'
match 'auth/failure', to: redirect('/')
match 'signout', to: 'sessions#destroy', as: 'signout'
宝石文件
ruby '1.9.3'
gem 'rails', '3.2.12'
gem "omniauth", "~> 1.1.1"
gem "omniauth-facebook", "1.4.0"
用户模型
def self.from_omniauth(auth) where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user| user.provider = auth.provider user.uid = auth.uid user.name = auth.info.name user.oauth_token = auth.credentials.token user.oauth_expires_at = Time.at(auth.credentials.expires_at) user.save!结束结束
初始化/omniauth.rb
OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, '51xxxxxxxxx42200', '0e3b1xxxxxxxxxxxxxxxxx4ff87'
end