Class: Moloni::Cli::OauthCallbackCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/moloni/cli/oauth_callback_command.rb

Instance Method Summary collapse

Constructor Details

#initialize(developer_id, client_secret) ⇒ OauthCallbackCommand

Returns a new instance of OauthCallbackCommand.



14
15
16
17
18
19
20
# File 'lib/moloni/cli/oauth_callback_command.rb', line 14

def initialize(developer_id, client_secret)
  @options = {
    port: default_port,
    client_secret:,
    developer_id:
  }
end

Instance Method Details

#default_portObject



22
23
24
# File 'lib/moloni/cli/oauth_callback_command.rb', line 22

def default_port
  Moloni::Cli::OauthCallbackServer.settings.port
end

#run(_argv = ARGV, _env = ENV) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/moloni/cli/oauth_callback_command.rb', line 26

def run(_argv = ARGV, _env = ENV)
  Moloni::Cli::OauthCallbackServer.set(:port, @options[:port]) if @options[:port]

  callback_path = Moloni::Cli::OauthCallbackServer::CALLBACK_PATH
  bind_port = Moloni::Cli::OauthCallbackServer.settings.port
  bind_address = Moloni::Cli::OauthCallbackServer.settings.bind

  callback_url = "http://#{bind_address}:#{bind_port}/#{callback_path}"

  Moloni.configure do |config|
    config.developer_id = @options[:developer_id] || ENV['DEVELOPER_ID']
    config.redirect_uri = ENV['REDIRECT_URI']
    config.client_secret = @options[:client_secret] || ENV['CLIENT_SECRET']
    config.debug = true
  end

  url = Moloni::Auth.auth_url

  puts "Callback URL: #{callback_url}"
  puts "Open this url to authenticate: #{url}"

  Launchy.open(url)

  puts 'Running callback server....'
  Moloni::Cli::OauthCallbackServer.run!
end