0

我正在实现一个应用程序,它应该能够代表其用户与不同的 API 对话。其中包括 github。我正在使用 oauth-plugin ( https://github.com/pelle/oauth-plugin ) 为每个 API 执行身份验证。不幸的是,这不适用于 Github。

这是我当前的 GithubToken 实现:

class GithubToken < ConsumerToken

  GITHUB_SETTINGS={
    :site=>"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

启动身份验证过程时,我在 get_request_token 调用期间收到 403 错误。我认为 request_token_path 有点错误,但无法在正确路径上找到任何信息。使用 github 作为搜索词的一部分搜索 google 也不是很有帮助。现在将尝试omniauth,但是由于我也计划使用oauth-plugin的提供者功能,因此我们将不胜感激。

4

1 回答 1

1

好的,解决了。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。

于 2013-08-13T18:07:33.310 回答