octokit / octokit.rb

Ruby toolkit for the GitHub API
http://octokit.github.io/octokit.rb/
MIT License
3.85k stars 1.14k forks source link

Authentication with oauth failes #855

Closed casecamp closed 7 years ago

casecamp commented 7 years ago

screen shot 2017-01-12 at 1 48 23 pm client = Octokit::Client.new(:access_token => access_token) If i use this method then

user = client.user

gives bad credentials errror, only basic authentication working, other authentications gives same error.

Using octokit 4.6.2

pengwynn commented 7 years ago

@casecamp Let's rule out a couple of things first:

zenspider commented 7 years ago

works fine on this side

retorquere commented 7 years ago

I think I'm seeing the same problem, using Octokit 4.7.0 under Ruby 2.3. My script is:

!/usr/bin/env ruby

require 'dotenv/load'
require 'octokit'

Octokit.configure{|c|
  c.access_token = ENV['GITHUB_TOKEN']
}

repo = 'retorquere/zotero-better-bibtex'

release = Octokit.release_for_tag(repo, 'update.rdf')

The token is a freshly generated personal access token with repo:status, repo_deployment and public_repo access.

The full error is:

/home/emile/.rvm/gems/ruby-2.3.0@zotero/gems/octokit-4.7.0/lib/octokit/response/raise_error.rb:16:in `on_complete': GET https://api.github.com/repos/retorquere/zotero-better-bibtex/releases/tags/update.rdf: 401 - Bad credentials // See: https://developer.github.com/v3 (Octokit::Unauthorized)
    from /home/emile/.rvm/gems/ruby-2.3.0@zotero/gems/faraday-0.9.2/lib/faraday/response.rb:9:in `block in call'
    from /home/emile/.rvm/gems/ruby-2.3.0@zotero/gems/faraday-0.9.2/lib/faraday/response.rb:57:in `on_complete'
    from /home/emile/.rvm/gems/ruby-2.3.0@zotero/gems/faraday-0.9.2/lib/faraday/response.rb:8:in `call'
    from /home/emile/.rvm/gems/ruby-2.3.0@zotero/gems/octokit-4.7.0/lib/octokit/middleware/follow_redirects.rb:73:in `perform_with_redirection'
    from /home/emile/.rvm/gems/ruby-2.3.0@zotero/gems/octokit-4.7.0/lib/octokit/middleware/follow_redirects.rb:61:in `call'
    from /home/emile/.rvm/gems/ruby-2.3.0@zotero/gems/faraday-0.9.2/lib/faraday/rack_builder.rb:139:in `build_response'
    from /home/emile/.rvm/gems/ruby-2.3.0@zotero/gems/faraday-0.9.2/lib/faraday/connection.rb:377:in `run_request'
    from /home/emile/.rvm/gems/ruby-2.3.0@zotero/gems/faraday-0.9.2/lib/faraday/connection.rb:140:in `get'
    from /home/emile/.rvm/gems/ruby-2.3.0@zotero/gems/sawyer-0.8.1/lib/sawyer/agent.rb:94:in `call'
    from /home/emile/.rvm/gems/ruby-2.3.0@zotero/gems/octokit-4.7.0/lib/octokit/connection.rb:156:in `request'
    from /home/emile/.rvm/gems/ruby-2.3.0@zotero/gems/octokit-4.7.0/lib/octokit/connection.rb:19:in `get'
    from /home/emile/.rvm/gems/ruby-2.3.0@zotero/gems/octokit-4.7.0/lib/octokit/client/releases.rb:137:in `release_for_tag'
    from /home/emile/.rvm/gems/ruby-2.3.0@zotero/gems/octokit-4.7.0/lib/octokit.rb:46:in `method_missing'
kytrinyx commented 7 years ago

I created a new token with all the repo scopes, and called your script, which succeeded.

Do you get the expected token when you call puts ENV['GITHUB_TOKEN']?

I'm going to close this. If you are able to create reproduction steps, please open a new issue.