使用rails oauth插件访问github API

我正在实现一个应用程序,该应用程序应该能够代表其用户与不同的API通信。 除此之外,这包括github。 我正在使用oauth-plugin( https://github.com/pelle/oauth-plugin )为每个API执行身份validation。 不幸的是,这对Github不起作用。

这是我目前的GithubToken实现:

class GithubToken "https://github.com", :request_token_path => "/login/oauth/request_token", :authorize_path => "/login/oauth/authorize", :access_token_path => "/login/oauth/access_token", } def self.consumer @consumer||=create_consumer end def self.create_consumer(options={}) OAuth::Consumer.new credentials[:key],credentials[:secret],GITHUB_SETTINGS.merge(options) end def self.get_request_token(callback_url, scope=nil) https://github.com/login/oauth/authorize consumer.get_request_token({:oauth_callback=>callback_url}, :scope=>scope||credentials[:scope]||"") end end 

启动身份validation过程时,我在get_request_token调用期间收到403错误。 我假设request_token_path有点错误,但无法在正确的路径上找到任何信息。 使用github搜索谷歌作为搜索词的一部分也不是很有帮助。 现在尝试omniauth,但是因为我正计划使用oauth-plugin的提供者function,所以任何帮助都会非常感激。

好的,解决了。 initialisers / oauth_consumers.rb中的以下配置可以解决这个问题:

 OAUTH_CREDENTIALS={ :github=>{ :key => "KEY", :secret => "SECRET", :expose => false, # expose client at /oauth_consumers/twitter/client see docs :oauth_version => 2, :options => { :site => 'https://github.com', :authorize_url => '/login/oauth/authorize', :token_url => '/login/oauth/access_token' } } } 

还要确保将/ oauth_consumers / github / callback2注册为回调URL。