Skip to content

Commit

Permalink
Support TOTP when requesting an OAuth token
Browse files Browse the repository at this point in the history
  • Loading branch information
mpalmer committed May 27, 2020
1 parent 6393491 commit b39008a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/github-release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,17 @@ def get_new_token
pass = $stdin.noecho(&:gets).chomp
puts

headers = {}

api = Octokit::Client.new(:login => user, :password => pass)
begin
res = api.create_authorization(:scopes => [:repo], :note => "git release")
res = api.create_authorization(:scopes => [:repo], :note => "git release #{Time.now.strftime("%FT%TZ")}", :headers => headers)
rescue Octokit::OneTimePasswordRequired
print "OTP code: "
headers["X-GitHub-OTP"] = $stdin.gets.chomp
retry
rescue Octokit::Unauthorized
puts "Username or password incorrect. Please try again."
puts "Credentials incorrect. Please try again."
return get_new_token
end

Expand Down

0 comments on commit b39008a

Please sign in to comment.