Re: sending basic auth credentials with request

3 views
Skip to first unread message

lsiden

unread,
Nov 23, 2009, 2:31:27 PM11/23/09
to webrat, rubyd...@googlegroups.com, cu...@googlegroups.com
A bit more info. In webrat.log, I've got:

D, [2009-11-23T14:14:06.042501 #12946] DEBUG -- : REQUESTING PAGE: GET
https://gator1087.hostgator.com/~tes/admin/ with {} and HTTP headers
{"HTTP_AUTHORIZATION"=>"Basic dGVzOnRvdGFsZXF1aXR5MQ==\n"}

I'm not sure what "Basic dGVzOnRvdGFsZXF1aXR5MQ==\n" means at the end
of the log message. Is that a hash of the username and password. Is
something supposed to be on the right side of the '=='? All I can
find on the subject is this: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.8.
What is the request header supposed to look like?

On Nov 22, 8:44 pm, lsiden <lsi...@gmail.com> wrote:
> I need to get Webrat::Mechanize to log onto a site that returns a 403
> even when you go to the welcome page (it's not for the general public,
> but the client must use a shared-hosting site).
>
> First I attempted to use the login form but that did not work, because
> Webrat does not create a scope object when it sees the 403, even when
> there is content.
>
> Martin Emde already recommended on the forum that I try basic
> authentication.  I tried doing it like this:
>
>    ... do |site, user, pwd|
>      basic_auth(user, pwd)
>      visit site
>    ...
>    end
>
> but it throws an exception:
>
>       403 => Net::HTTPForbidden (WWW::Mechanize::ResponseCodeError)
>
> I suppose I would see this if I were passing an invalid username and/
> or password, but I already double-checked this manually in the browser
> and I'm passing the right credentials.
>
> I'm obviously doing something wrong, but I need an example to go on.
> Can anyone point me to an example?

Timothy Fisher

unread,
Nov 23, 2009, 3:58:20 PM11/23/09
to rubyd...@googlegroups.com, webrat, cu...@googlegroups.com
Larry,
 
I can explain this part:
dGVzOnRvdGFsZXF1aXR5MQ==
 
That is the Base64 encoding of username:password.  That is part of the BASIC http authentication spec.  You can read more about it at:

--
You received this message because you are subscribed to the Google
Groups "Detroit.rb" group.
To post to this group, send email to rubyd...@googlegroups.com
To unsubscribe from this group, send email to
rubydetroit...@googlegroups.com

Larry Siden

unread,
Nov 23, 2009, 4:50:40 PM11/23/09
to rubyd...@googlegroups.com
Thanks.  Funny, I came across that page, but didn't didn't see the example when I scanned it.  Must have scrolled too quickly. 

In any case, I'm still trying to figure out what I need to do to make this test work correctly.  It's not critical.  Just a learning exercise at this point, but could become useful in the future.

Larry Siden
http://umich.edu/~lsiden
734-926-9614
skype: lsiden
Reply all
Reply to author
Forward
0 new messages