0

I'm implementing an application that is supposed to be able to talk to different APIs on behalf of its users. Amongst others, this includes github. I'm using the oauth-plugin (https://github.com/pelle/oauth-plugin) to perform the authentication for each API. Unfortunately, this doesn't work for Github.

Here's my current GithubToken implementation:

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

When starting the authentication process, I get a 403 error during the get_request_token call. I assume the request_token_path is somehow wrong, but was unable to find any information on the correct path. Searching google with github as part of the search term was also not very helpful. Will try omniauth now, but as I'm planning on using the provider capabilities of the oauth-plugin, as well, any help would be much appreciated.

1 Answer 1

1

Ok, solved it. The following configuration in initialisers/oauth_consumers.rb will do the trick:

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'
     }
  }
}

Also make sure to register /oauth_consumers/github/callback2 as your callback URL.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.