aanand / deadweight

NOT MAINTAINED
MIT License
1.19k stars 52 forks source link

HTTP Basic Authentication #5

Closed almays closed 14 years ago

almays commented 14 years ago

Hello. Thank you for this gemful gem.

One question. How can I login to the hidden sections of the site behind authenticate_or_request_with_http_basic?

Thank you.

aanand commented 14 years ago

You'll need to use the procs-as-pages feature, as demonstrated in the README under "You Can Use Mechanize for Complex Stuff". This necessitates installing the mechanize gem and setting dw.mechanize = true in your config block. Then you can use Mechanize's built-in basic auth support.

For example, to access the path "/widgets/1" using basic authentication, you'd go:

Deadweight::RakeTask.new do |dw|
  dw.stylesheets = %w( /stylesheets/style.css )
  dw.mechanize = true

  dw.pages << proc {
    agent.auth('username', 'password')
    fetch('/widgets/1')
  }
end