Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


authenticate does not work #7

wheineman opened this Issue · 7 comments

5 participants


authenticate method is not working. There doesn't seem to be a testcase for authenticate.


Do you have an example where it doesn't work?
r.authenticate expects an URL prefix that is matched exactly.
Resty will send the authentication headers for any URL that starts with that prefix.
What URLs are you using?


Hi @beders,

I'm using Resty 0.3.1, and I can't seem to get HTTP Basic Authentication to work. I receive an error when I use the json() method. Here is the stack trace:

at us.monoid.web.auth.RestyAuthenticator.getPasswordAuthentication(
at us.monoid.web.AbstractResource.fill(
at us.monoid.web.Resty.fillResourceFromURL(
at us.monoid.web.Resty.doGET(
at us.monoid.web.Resty.json(
at us.monoid.web.Resty.json(

I'm new to Java, so I could be completely wrong, but I noticed that there's a reference to the method getRequestingURL(), but it's not defined anywhere else in the code:

To work around this bug, I'm using the alwaysSend() method instead, performing the Base64 encoding myself, like so:

Resty resty = new Resty();
String encodedString = Base64.encodeToString((username + ":" + password).getBytes("UTF-8"), android.util.Base64.DEFAULT);
resty.alwaysSend("Authorization", "Basic " + encodedString);

Object name = resty.json(baseURI + "/users/new").get("user.firstName");

Thanks for this library!

@beders beders referenced this issue from a commit
@beders Support for authentication realms if the underlying connection URL is…
… not delivering requestingURL to the Authenticator class

(fix for issue #7)

I'm also having problems with the authentication. But with my case for some reason I'm always getting the 401 unauthorized error. I believe there is something wrong with setting the parameters for username and password. I am absolutely sure the credentials I set are correct and I verified this by using Poster plugin in the Chrome browser.

below is the code that i am using...

resty.authenticate("http://localhost/drupal/rest-api/user/login", "ecxxxx", "xxxx".toCharArray());

And below is the error output. Server returned HTTP response code: 401 for URL: http://localhost/drupal/rest-api/user/login.json
    at us.monoid.web.AbstractResource.fill(
    at us.monoid.web.Resty.fillResourceFromURL(
    at us.monoid.web.Resty.doPOSTOrPUT(
    at us.monoid.web.Resty.json(
    at us.monoid.web.Resty.json(
    at MassimoDuttiItem.saveResty(
    at EmParisParser.main(

I also tried setting the form values like so ...

resty.json("http://localhost/drupal/rest-api/user/login", Resty.form("username", "ecdiddy")));

and receive the same error. I checked my server logs and my login module doesn't recognize the username that was set. It thinks it is accessing as an anonymous user. That is why I believe there is something wrong with the setting form parameters with this resty function.

I'm not sure if authenticateForRealm is the solution for this issue which mentions about not delivering the URL. Is anyone else facing this issue?


I have the same problem as ecdiddy re: authenticate() not working. Maybe the author could provide an example and some more explanation in the documentation? I'm doing HTTPS, as will most real-world users wanting to authenticate.

Non-Android version of Todd's solution:
byte[] encoded = Base64.encodeBase64((uid + ":" + pw).getBytes());
String value = "Basic " + new String(encoded);
resty.alwaysSend("Authorization",value );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.