Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.