Class: Moloni::Cli::OauthCallbackCommand
- Inherits:
-
Object
- Object
- Moloni::Cli::OauthCallbackCommand
- Defined in:
- lib/moloni/cli/oauth_callback_command.rb
Instance Method Summary collapse
- #default_port ⇒ Object
-
#initialize(developer_id, client_secret) ⇒ OauthCallbackCommand
constructor
A new instance of OauthCallbackCommand.
- #run(_argv = ARGV, _env = ENV) ⇒ Object
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_port ⇒ Object
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 |