# File lib/rhc/wizard.rb, line 167
    def login_stage
      if token_for_user
        options.token = token_for_user
        say "Using an existing token for #{options.rhlogin} to login to #{openshift_server}"
      elsif options.rhlogin
        say "Using #{options.rhlogin} to login to #{openshift_server}"
      end

      self.rest_client = new_client_for_options

      begin
        rest_client.api
      rescue RHC::Rest::CertificateVerificationFailed => e
        debug "Certificate validation failed: #{e.reason}"
        unless options.insecure
          if RHC::Rest::SelfSignedCertificate === e
            warn "The server's certificate is self-signed, which means that a secure connection can't be established to '#{openshift_server}'."
          else
            warn "The server's certificate could not be verified, which means that a secure connection can't be established to '#{openshift_server}'."
          end
          if openshift_online_server?
            paragraph{ warn "This may mean that a server between you and OpenShift is capable of accessing information sent from this client.  If you wish to continue without checking the certificate, please pass the -k (or --insecure) option to this command." }
            return
          else
            paragraph{ warn "You may bypass this check, but any data you send to the server could be intercepted by others." }
            return unless agree "Connect without checking the certificate? (yes|no): "
            options.insecure = true
            self.rest_client = new_client_for_options
            retry
          end
        end
      end

      self.user = rest_client.user
      options.rhlogin = self.user.login unless username

      if rest_client.supports_sessions? && !options.token && options.create_token != false
        paragraph do
          info "OpenShift can create and store a token on disk which allows to you to access the server without using your password. The key is stored in your home directory and should be kept secret.  You can delete the key at any time by running 'rhc logout'."
          if options.create_token or agree "Generate a token now? (yes|no) "
            say "Generating an authorization token for this client ... "
            token = rest_client.new_session
            options.token = token.token
            self.auth(true).save(token.token)
            self.rest_client = new_client_for_options
            self.user = rest_client.user

            success "lasts #{distance_of_time_in_words(token.expires_in_seconds)}"
          end
        end
      end
      true
    end