Last active
March 6, 2017 15:54
-
-
Save baldowl/6658258 to your computer and use it in GitHub Desktop.
Adjusting To GitHub's 2FA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
security add-generic-password \ | |
-a my-github-login \ | |
-s github \ | |
-D "GitHub's OAuth2 Token" \ | |
-T "" \ | |
-w the-long-oauth-token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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