class FIS::CLI::Commands::Login
`auth login` - Requests and adds the user's authentication credentials
Public Class Methods
new(options)
click to toggle source
# File lib/fis/cli/commands/login.rb, line 8 def initialize(options) @options = options @auth_local_server = FIS::Auth::Runner.new end
Public Instance Methods
execute()
click to toggle source
# File lib/fis/cli/commands/login.rb, line 13 def execute # TODO: Allow for token to be set with a flag FIS.ui.newline return FIS.ui.error("You're already logged in. Please run `fis auth logout` to continue.") if logged_in? return FIS.ui.warn('OAuth not available. Please set your token using the `--token` flag.') if remote_ide? @auth_local_server.start FIS.ui.info('Logging into your Flatiron School account...') open_browser! sleep 1 until token_accessible? # TODO: Timeout? FIS.ui.newline FIS.ui.ok("You've successfully logged in.") ensure @auth_local_server.stop end
Private Instance Methods
logged_in?()
click to toggle source
# File lib/fis/cli/commands/login.rb, line 37 def logged_in? FIS.config.fetch(:identity, :portal, :token) end
open_browser!()
click to toggle source
# File lib/fis/cli/commands/login.rb, line 41 def open_browser! system('open', FIS::Auth::LOCAL_URI) end
remote_ide?()
click to toggle source
# File lib/fis/cli/commands/login.rb, line 45 def remote_ide? false # TODO: Check if in an environment without a browser end
token_accessible?()
click to toggle source
# File lib/fis/cli/commands/login.rb, line 49 def token_accessible? FIS.config.reread token = FIS.config.fetch(:identity, :portal, :token) !token.nil? && !token.empty? end