Class: Monotes::Authenticator
- Inherits:
-
Object
- Object
- Monotes::Authenticator
- Defined in:
- lib/monotes/authenticator.rb
Constant Summary collapse
- ACCESS_NOTE =
"Monotes access token"
Instance Method Summary collapse
- #get_oauth_token(username, password, &acquire_two_fa) ⇒ Object
-
#initialize(api_client_klass) ⇒ Authenticator
constructor
A new instance of Authenticator.
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.(:scopes => scopes, :note => ACCESS_NOTE) rescue Octokit::OneTimePasswordRequired two_fa_token = yield acquire_two_fa api_client.(:scopes => scopes, :note => ACCESS_NOTE, :headers => { "X-GitHub-OTP" => two_fa_token }) end end |