class Heroku::Command::TwoFactor

manage two-factor authentication settings

Public Instance Methods

disable() click to toggle source

twofactor:disable

Disable two-factor authentication for your account

# File lib/heroku/command/two_factor.rb, line 31
def disable
  print "Password (typing will be hidden): "
  password = Heroku::Auth.ask_for_password

  update = MultiJson.dump(
    :two_factor_authentication => false,
    :password => password)

  api.request(
    :expects => 200,
    :headers => { "Accept" => "application/vnd.heroku+json; version=3" },
    :method  => :patch,
    :path    => "/account",
    :body    => update)
  display "Disabled two-factor authentication."
rescue Heroku::API::Errors::RequestFailed => e
  error Heroku::Command.extract_error(e.response.body)
end
generate_recovery_codes() click to toggle source

twofactor:generate-recovery-codes

Generates and replaces recovery codes

# File lib/heroku/command/two_factor.rb, line 57
def generate_recovery_codes
  code = Heroku::Auth.ask_for_second_factor

  recovery_codes = api.request(
    :expects => 200,
    :method  => :post,
    :path    => "/account/two-factor/recovery-codes",
    :headers => { "Heroku-Two-Factor-Code" => code }
  ).body

  display "Recovery codes:"
  recovery_codes.each { |c| display c }
rescue RestClient::Unauthorized => e
  error Heroku::Command.extract_error(e.http_body)
end
index() click to toggle source

twofactor

Display whether two-factor authentication is enabled or not

# File lib/heroku/command/two_factor.rb, line 11
def index
  account = api.request(
    :expects => 200,
    :headers => { "Accept" => "application/vnd.heroku+json; version=3" },
    :method  => :get,
    :path    => "/account").body

  if account["two_factor_authentication"]
    display "Two-factor authentication is enabled."
  else
    display "Two-factor authentication is not enabled."
  end
end