I have a REST API that is HTTP Basic Auth enabled.
My user name is an email address: “[email protected]” and my password
is “asdf”
Logging in and everything work fine in the browser or curl. However,
I’m lost at how to use an email for a username with ActiveResource. If
I don’t escape the ‘@’ in the email I get a bad uri error:
and If I escape the ‘@’ with ‘%40’ it’s taken literally and the
username is passed to rails as ‘email%40domain.com’ and subsequently
fails authentication.
I have the same problem and don’t yet have a solution for you but
observe that another REST client, the gem rally_rest_api (see
rest_builder.rb #send_request), handles this by not relying on URI
parsing. Instead they create a Net::HTTP::Get and then call #basic_auth username, password which set the credentials directly in
the HTTP header. I haven’t been successful in escaping the @ sign and
suspect that it may be necessary to patch ActiveResource to behave
like rest_builder.rb.
John-Mason Shackelford
Software Development Coach
Pearson
2510 North Dodge St.
Iowa City, IA 52245
ph. 319-354-9200x6214 [email protected]
I don’t really have this issue anymore 'cause I moved to a token based
auth system for my API. Regardless, I’m still thinking about filing a
bug report in the rails trac, I’m just not sure if this is exceptional
behavior or not…
Isn’t this a cop-out of sorts? The uri-encoded text in the URI should
be decoded shouldn’t it?
A cop out? We’re not out to win any awards… I personally think
encoding it in the url is a bit ugly. You can use the #site attribute
to set the userinfo (site is an instance of URI), but it falls for the
same encoding problem. If someone wants to write a quick patch for
URI, that’d be fine I suppose. But in the end, I went with something
similar to what John proposed.