macks / ruby-ntlm

NTLM authentication client for Ruby.
http://github.com/macks/ruby-ntlm
48 stars 34 forks source link

undefined method handle for class Mechanize::Chain::AuthHeaders #4

Open iGallina opened 10 years ago

iGallina commented 10 years ago

I've just required your gem, and got this while using on a Rake Task... undefined method 'handle' for class 'Mechanize::Chain::AuthHeaders' /Users/iangallina/projetos/gtdi/vendor/bundle/gems/ruby-ntlm-0.0.1/lib/ntlm/mechanize.rb:9:in '<class:AuthHeaders>' /Users/iangallina/projetos/gtdi/vendor/bundle/gems/ruby-ntlm-0.0.1/lib/ntlm/mechanize.rb:6:in '<class:Chain>' /Users/iangallina/projetos/gtdi/vendor/bundle/gems/ruby-ntlm-0.0.1/lib/ntlm/mechanize.rb:5:in '<class:Mechanize>' /Users/iangallina/projetos/gtdi/vendor/bundle/gems/ruby-ntlm-0.0.1/lib/ntlm/mechanize.rb:4:in '<top (required)>' /Users/iangallina/projetos/gtdi/vendor/bundle/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:in 'require' /Users/iangallina/projetos/gtdi/vendor/bundle/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:in 'block in require' /Users/iangallina/projetos/gtdi/vendor/bundle/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:214:in 'load_dependency' /Users/iangallina/projetos/gtdi/vendor/bundle/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:in 'require' /Users/iangallina/projetos/gtdi/lib/tasks/processa_xml.rake:3:in '<top (required)>' /Users/iangallina/projetos/gtdi/vendor/bundle/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:223:in 'load' /Users/iangallina/projetos/gtdi/vendor/bundle/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:223:in 'block in load' /Users/iangallina/projetos/gtdi/vendor/bundle/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:214:in 'load_dependency' /Users/iangallina/projetos/gtdi/vendor/bundle/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:223:in 'load' /Users/iangallina/projetos/gtdi/vendor/bundle/gems/railties-4.0.1/lib/rails/engine.rb:641:in 'block in run_tasks_blocks' /Users/iangallina/projetos/gtdi/vendor/bundle/gems/railties-4.0.1/lib/rails/engine.rb:641:in 'each' /Users/iangallina/projetos/gtdi/vendor/bundle/gems/railties-4.0.1/lib/rails/engine.rb:641:in 'run_tasks_blocks' /Users/iangallina/projetos/gtdi/vendor/bundle/gems/railties-4.0.1/lib/rails/application.rb:244:in 'run_tasks_blocks' /Users/iangallina/projetos/gtdi/vendor/bundle/gems/railties-4.0.1/lib/rails/engine.rb:446:in 'load_tasks' /Users/iangallina/projetos/gtdi/vendor/bundle/gems/railties-4.0.1/lib/rails/railtie/configurable.rb:30:in 'method_missing' /Users/iangallina/projetos/gtdi/Rakefile:6:in '<top (required)>'

macks commented 10 years ago

ruby-ntlm doesn't work well with recent Mechanize library. Recent Mechanize has native support for NTLM authentication mechanism, so I'll remove 'ntlm/mechanize' from ruby-ntlm.

If you do want to use ruby-ntlm with Mechanize, apply following patch to mechanize.

--- a/lib/mechanize/http/agent.rb
+++ b/lib/mechanize/http/agent.rb
@@ -1,5 +1,5 @@
 require 'tempfile'
-require 'net/ntlm'
+require 'ntlm'
 require 'kconv'
 require 'webrobots'

@@ -750,17 +750,15 @@ class Mechanize::HTTP::Agent
       existing_realms << realm

       if challenge.params then
-        type_2 = Net::NTLM::Message.decode64 challenge.params
+        type_2 = challenge.params.unpack('m').first

         user, password, domain = @auth_store.credentials_for uri, nil

-        type_3 = type_2.response({ :user => user, :password => password,
-                                   :domain => domain },
-                                 { :ntlmv2 => true }).encode64
+        type_3 = ::NTLM.authenticate(type_2, user, domain, password).to_base64

         headers['Authorization'] = "NTLM #{type_3}"
       else
-        type_1 = Net::NTLM::Message::Type1.new.encode64
+        type_1 = ::NTLM.negotiate.to_base64
         headers['Authorization'] = "NTLM #{type_1}"
       end
     elsif challenge = challenges.find { |c| c.scheme == 'Basic' } then