2012-07-26 63 views
2

確定它已經超過5個小時,我仍然沒有得到任何地方。我正在嘗試的是在我的一個基於Ruby-Sinatra的應用程序中設置omniauth-gihub gem。以下是我所做的。Ruby,Sinatra,omniauth-github身份驗證失敗回調錯誤

添加了寶石的Gemfile中(&冉捆綁更新命令ofcourse):

source 'https://rubygems.org' 

gem 'sinatra' 
gem 'haml' 
gem 'shotgun' 
gem 'omniauth', :git => 'git://github.com/intridea/omniauth.git' 
gem 'omniauth-github', :git => 'git://github.com/intridea/omniauth-github.git' 

在我app.rb文件我有以下代碼:

#imports 
require 'rubygems' 
require 'bundler' 
require 'sinatra' 
require 'omniauth' 
require 'omniauth-github' 
require 'haml' 
require './helpers.rb' 

#Configure OmniAuth 
use OmniAuth::Builder do 
    provider :github, ENV['api_key'], ENV['secret'], # Removing the key and secret for security reasons 
    scope: "user,repo,gist" 
end 

#Application Settings 
set :sessions, true 
set :views, 'templates' 


#Get Method for Application Root 
get '/' do 
    haml :index 
end 

#Get/Post Methods For Authentication 
%w(get post).each do |method| 
    send(method, "/auth/:provider/callback") do 
    env['omniauth.auth'] 
    end 
end 

GitHub的應用程序的設置如下:

URL = http://127.0.0.1:4567 
Callback URL = http://127.0.0.1:4567/auth/github/callback 

現在每當我訪問127.0 .0.1:4567/auth /中github上/回調我得到以下錯誤:

I, [2012-07-26T07:05:23.540462 #30458] INFO -- omniauth: (github) Callback phase initiated. 
E, [2012-07-26T07:05:23.540700 #30458] ERROR -- omniauth: (github) Authentication failure! invalid_credentials: OmniAuth::Strategies::OAuth2::CallbackError, OmniAuth::Strategies::OAuth2::CallbackError 
localhost - - [26/Jul/2012:07:05:23 IST] "GET /auth/github/callback HTTP/1.1" 302 9 
- -> /auth/github/callback 
localhost - - [26/Jul/2012:07:05:23 IST] "GET /auth/failure?message=invalid_credentials&strategy=github HTTP/1.1" 404 448 
- -> /auth/failure?message=invalid_credentials&strategy=github 
localhost - - [26/Jul/2012:07:05:23 IST] "GET /favicon.ico HTTP/1.1" 404 447 
- -> /favicon.ico 

似乎它甚至沒有試圖連接到github上,我以爲我已經登錄,所以我退出github上的,然後嘗試訪問127.0.0.4567/auth/github/callback再次,是的,它甚至沒有連接或發送任何信息給github。

我檢查我的API密鑰和祕密,他們是正確的。我無法弄清楚我錯過了什麼,真的很累。任何幫助或建議將不勝感激。

編輯::

好吧,我發現,提高了錯誤的代碼是在oauth2.rb如下

def callback_phase 
    if request.params['error'] || request.params['error_reason'] 
     raise CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri']) 
    end 
    if request.params['state'].to_s.empty? || request.params['state'] != session.delete('omniauth.state') 
     raise CallbackError.new(nil, :csrf_detected) 
    end 

我覺得這是值得做的CSRF。

回答

2

這可能會感興趣: https://github.com/intridea/omniauth-github/issues/12

我得到了同樣的錯誤,你,並添加範圍:「用戶」的固定對我來說。

我看到你已經在使用範圍,但鏈接可能會讓你走上正軌。

+0

感謝您的回覆,我已經經歷過這一切。此外,我在幾個小時前解決了這個問題,只是將omni-oauth2 gem文件更新爲最新版本並更新了軟件包。瞧! – Amyth 2012-07-27 05:37:41