Skip to content

Instantly share code, notes, and snippets.

@baldowl
Last active March 6, 2017 15:54
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save baldowl/6658258 to your computer and use it in GitHub Desktop.
Save baldowl/6658258 to your computer and use it in GitHub Desktop.
Adjusting To GitHub's 2FA
security add-generic-password \
-a my-github-login \
-s github \
-D "GitHub's OAuth2 Token" \
-T "" \
-w the-long-oauth-token
#!/usr/bin/env ruby
require 'highline/import'
gem 'octokit', '>= 2.1.0'
require 'octokit'
require 'pp'
login = ask('login: ')
password = ask('password: ') {|q| q.echo = '*'}
client = Octokit::Client.new :login => login, :password => password
user = begin
client.user
rescue Octokit::OneTimePasswordRequired
otp = ask('OTP: ') {|q| q.echo = '*'}
client.user login, :headers => {'X-GitHub-OTP' => otp}
end
puts(pp(user))
#!/usr/bin/env ruby
require 'highline/import'
gem 'octokit', '>= 2.1.0'
require 'octokit'
require 'pp'
login = ask('login: ')
password = ask('password: ') {|q| q.echo = '*'}
otp = ask('OTP: ') {|q| q.echo = '*'}
puts
temp_client = Octokit::Client.new :login => login, :password => password
auth = temp_client.create_authorization :scope => %w(user repo gist),
:note => "Disposable - #{$PROGRAM_NAME} - #{Time.now}",
:headers => {'X-GitHub-OTP' => otp}
client = Octokit::Client.new :login => auth.token,
:password => 'x-oauth-basic', :auto_paginate => true
# Just to simulate a lot of requests.
client.repositories(nil, :type => 'all').each do |repo|
puts(pp(client.repository(repo.full_name)))
end
#!/usr/bin/env ruby
require 'highline/import'
gem 'octokit', '>= 2.1.0'
require 'octokit'
require 'pp'
login = ask('login: ')
password = ask('password: ') {|q| q.echo = '*'}
otp = ask('OTP: ') {|q| q.echo = '*'}
puts
temp_client = Octokit::Client.new :login => login, :password => password
auths = temp_client.authorizations(:headers => {'X-GitHub-OTP' => otp})
token = auths.find {|a| a.note == 'Toy 3'}.token
client = Octokit::Client.new :login => token,
:password => 'x-oauth-basic', :auto_paginate => true
# Just to simulate a lot of requests.
client.repositories(nil, :type => 'all').each do |repo|
puts(pp(client.repository(repo.full_name)))
end
#!/usr/bin/env ruby
require 'highline/import'
gem 'octokit', '>= 2.1.0'
require 'octokit'
require 'pp'
login = 'my-github-login'
service = 'github'
kind = "GitHub's OAuth2 Token"
token = %x(security find-generic-password \
-w \
-a #{login} \
-s #{service} \
-D "#{kind}").chop
client = Octokit::Client.new :login => token,
:password => 'x-oauth-basic', :auto_paginate => true
# Just to simulate a lot of requests.
client.repositories(nil, :type => 'all').each do |repo|
puts(pp(client.repository(repo.full_name)))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment