def auth(options = {})
    # Create new Mechanize instance to drop any old credentials.
    
    if options[:cert]
      key = options[:cert][:key]
      if key.respond_to?(:to_str) && !File.exist?(key)
        key = OpenSSL::PKey::RSA.new key
      end
      cert = options[:cert][:cert]
      if cert.respond_to?(:to_str) && !File.exist?(cert)
        cert = OpenSSL::X509::Certificate.new cert
      end
      
      @mech = mech do |m|
        m.key = key
        m.cert = cert
      end
    else
      @mech = mech
    end
    
    # Go to a page that is guaranteed to redirect to shitoleth.
    step1_page = get '/atstellar'
    # Fill in the form.
    step1_form = step1_page.form_with :action => /WAYF/
    step1_form.checkbox_with(:name => /perm/).checked = :checked
    step2_page = step1_form.submit step1_form.buttons.first
    # Click through the stupid confirmation form.
    step2_form = step2_page.form_with :action => /WAYF/
    cred_page = step2_form.submit step2_form.button_with(:name => /select/i)
    
    # Fill in the credentials form.
    if options[:cert]
      cred_form = cred_page.form_with :action => /certificate/i
      cred_form.checkbox_with(:name => /pref/).checked = :checked
    elsif options[:kerberos]
      cred_form = cred_page.form_with :action => /username/i
      cred_form.field_with(:name => /user/).value = options[:kerberos][:user]
      cred_form.field_with(:name => /pass/).value = options[:kerberos][:pass]
    else
      raise ArgumentError, 'Unsupported credentials'
    end
    
    # Click through the SAML response form.
    saml_page = cred_form.submit cred_form.buttons.first
    unless saml_form = saml_page.form_with(:action => /SAML/)
      raise ArgumentError, 'Authentication failed due to invalid credentials'
    end
    saml_form.submit
    
    self
  end
def auth(options = {})
    # Create new Mechanize instance to drop any old credentials.
    
    if options[:cert]
      key = options[:cert][:key]
      if key.respond_to?(:to_str) && !File.exist?(key)
        key = OpenSSL::PKey::RSA.new key
      end
      cert = options[:cert][:cert]
      if cert.respond_to?(:to_str) && !File.exist?(cert)
        cert = OpenSSL::X509::Certificate.new cert
      end
      
      @mech = mech do |m|
        m.key = key
        m.cert = cert
      end
    else
      @mech = mech
    end
    
    # Go to a page that is guaranteed to redirect to shitoleth.
    step1_page = get '/atstellar'
    # Fill in the form.
    step1_form = step1_page.form_with :action => /WAYF/
    step1_form.checkbox_with(:name => /perm/).checked = :checked
    step2_page = step1_form.submit step1_form.buttons.first
    # Click through the stupid confirmation form.
    step2_form = step2_page.form_with :action => /WAYF/
    cred_page = step2_form.submit step2_form.button_with(:name => /select/i)
    
    # Fill in the credentials form.
    if options[:cert]
      cred_form = cred_page.form_with :action => /certificate/i
      cred_form.checkbox_with(:name => /pref/).checked = :checked
    elsif options[:kerberos]
      cred_form = cred_page.form_with :action => /username/i
      cred_form.field_with(:name => /user/).value = options[:kerberos][:user]
      cred_form.field_with(:name => /pass/).value = options[:kerberos][:pass]
    else
      raise ArgumentError, 'Unsupported credentials'
    end
    
    # Click through the SAML response form.
    saml_page = cred_form.submit cred_form.buttons.first
    unless saml_form = saml_page.form_with(:action => /SAML/)
      raise ArgumentError, 'Authentication failed due to invalid credentials'
    end
    saml_form.submit
    
    self
  end
Authenticates using some credentials, e.g. an MIT certificate.

 @param [Hash] options credentials to be used for authentication
 @option options [String] :cert path to MIT client certificate for the user
 @option options [Hash] :kerberos:: Kerberos credentials, encoded as a Hash
     with :user and :pass keys
 @return [Stellar::Client] self, for convenient method chaining