Skip to content

Instantly share code, notes, and snippets.

@nahi
Last active August 29, 2015 14:07
Show Gist options
  • Save nahi/d5373bb96c5e21c83950 to your computer and use it in GitHub Desktop.
Save nahi/d5373bb96c5e21c83950 to your computer and use it in GitHub Desktop.
require 'httpclient'
# Obtain Personal access token from https://github.com/settings/applications
personal_access_token = ''
h = HTTPClient.new
h.set_auth(nil, personal_access_token, 'x-oauth-basic')
puts h.get_content('https://api.github.com/user/repos?type=private')
% ruby github.rb
= Request
! CONNECT TO api.github.com:443
! CONNECTION ESTABLISHED
GET /user/repos?type=private HTTP/1.1
User-Agent: HTTPClient/1.0 (2.3.4.1, ruby 2.2.0 (2014-09-30))
Accept: */*
Date: Tue, 07 Oct 2014 13:42:22 GMT
Host: api.github.com
= Response
HTTP/1.1 401 Unauthorized
Server: GitHub.com
Date: Tue, 07 Oct 2014 13:42:22 GMT
Content-Type: application/json; charset=utf-8
Status: 401 Unauthorized
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 57
X-RateLimit-Reset: 1412692785
X-GitHub-Media-Type: github.v3
X-XSS-Protection: 1; mode=block
X-Frame-Options: deny
Content-Security-Policy: default-src 'none'
Content-Length: 91
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
Access-Control-Allow-Origin: *
X-GitHub-Request-Id: 7CD39D0C:3B43:261B6976:5433EDBD
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
X-Content-Type-Options: nosniff
httpclient-2.3.4.1/lib/httpclient.rb:975:in `success_content': unexpected response (HTTPClient::BadResponseError)
from httpclient-2.3.4.1/lib/httpclient.rb:594:in `get_content'
from github.rb:10:in `<main>'
@nahi
Copy link
Author

nahi commented Oct 7, 2014

Workaround:

h = HTTPClient.new
h.set_auth(nil, personal_access_token, 'x-oauth-basic')
h.www_auth.basic_auth.challenge('https://api.github.com/')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment