Skip to content

Remove out of band fallback #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions lib/aws/google.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
Loading