diff --git a/lib/aws/google.rb b/lib/aws/google.rb index dd235ed..b98c465 100644 --- a/lib/aws/google.rb +++ b/lib/aws/google.rb @@ -108,7 +108,7 @@ def silence_output end def get_oauth_code(client, options) - raise 'fallback' unless @port && !@port.zero? + raise ArgumentError.new('Missing port for local oauth server') unless @port && !@port.zero? require 'launchy' require 'webrick' @@ -135,20 +135,17 @@ def get_oauth_code(client, options) end end while server_thread.alive? - raise 'fallback' if !launchy.alive? && !launchy.value.success? + unless launchy.alive? && launchy.value.success? + server.shutdown + raise RuntimeError.new('Failed to launch browser with Launchy') + end sleep 0.1 end end - code || raise('fallback') - rescue StandardError + code || raise('Local Google Oauth failed to get code') + ensure trap('INT', 'DEFAULT') - # Fallback to out-of-band authentication if browser launch failed. - client.redirect_uri = 'oob' - return ENV['OAUTH_CODE'] if ENV['OAUTH_CODE'] - - raise RuntimeError, 'Open the following URL in a browser to get a code,' \ - "export to $OAUTH_CODE and rerun:\n#{client.authorization_uri(options)}", [] end def refresh