Class: Heroku::Command::TwoFactor

Inherits:
BaseWithApp
  • Object
show all
Defined in:
lib/heroku/command/two_factor.rb

Overview

manage two-factor authentication settings

Instance Method Summary collapse

Instance Method Details

#disableObject

twofactor:disable

Disable two-factor authentication for your account


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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_codesObject

twofactor:generate-recovery-codes

Generates and replaces recovery codes


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 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

#indexObject

twofactor

Display whether two-factor authentication is enabled or not


11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/heroku/command/two_factor.rb', line 11

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

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