Class: Monotes::Authenticator

Inherits:
Object
  • Object
show all
Defined in:
lib/monotes/authenticator.rb

Constant Summary collapse

ACCESS_NOTE =
"Monotes access token"

Instance Method Summary collapse

Constructor Details

#initialize(api_client_klass) ⇒ Authenticator

Returns a new instance of Authenticator.



4
5
6
# File 'lib/monotes/authenticator.rb', line 4

def initialize(api_client_klass)
  @api_client_klass = api_client_klass
end

Instance Method Details

#get_oauth_token(username, password, &acquire_two_fa) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/monotes/authenticator.rb', line 8

def get_oauth_token(username, password, &acquire_two_fa)
  api_client = @api_client_klass.new(:login => username, :password => password)
  begin
    api_client.create_authorization(:scopes => scopes, :note => ACCESS_NOTE)
  rescue Octokit::OneTimePasswordRequired
    two_fa_token = yield acquire_two_fa
    api_client.create_authorization(:scopes => scopes, :note => ACCESS_NOTE,
                                   :headers => { "X-GitHub-OTP" => two_fa_token })
  end
end