1

I'm developing a backend for an Android application using Drupal, and I've run into somewhat of a weird problem. I'm using Services and Views for the input and output of various content types. In order to make requests to the Services module, the users need to authenticate using HTTP Basic authentication.

When users create a new account in my app, I use the Services endpoint to create the new account using data that the user enters himself. However, the password that gets send to the endpoint is not the same as the password that gets saved. This results in users not being able to authenticate other requests using HTTP Basic Auth with the password they set, as Drupal does not recognize the password. However, logging in using the Services endpoint DOES work with the set password.

When changing this user's password manually in the Administration panel to the value they set in the app, the HTTP Basic auth requests suddenly work, and they can still login using the Services module as well.

What's going wrong here, and even better, what can I do to remedy this problem? I'm not looking forward to changing every user's password manually so they can use the rest of my backend, and dropping the HTTP Basic Authentication is not an option either.

Edit:

Further investigation has shown that it's also not possible to login to the Drupal frontend using an account created by the Services endpoint, unless you change the password manually.

6
  • Instead of basic auth, perhaps you could use a token / hash based authentication instead? Apr 8, 2014 at 8:44
  • @DavidThomas This was the original idea, but it was dropped by my project leader after running into problems getting it to work on iOS devices. Http Basic auth worked on both platforms without any hiccups so far, hence the choice for using HTTP Basic auth. Apr 8, 2014 at 8:47
  • Probably something overwriting the authorization header preventing the basic auth Apr 8, 2014 at 8:49
  • @DavidThomas Sadly no, I just created a new account using the Services endpoint with the username and password "test", and upon trying to login using my normal Drupal frontend it tells me my password is incorrect. Logging into the admin panel and setting the password of this account to "test" manually suddenly makes it possible to log in to the front end as well. Somewhere, something is going wrong and I have no clue what or why. Apr 8, 2014 at 8:51
  • This is what I do using CURL in php for basic Auth, may be you get some point from this, I don't know how things works on android. pastebin.com/Arzag9Xy
    – shrish
    Apr 8, 2014 at 9:26

1 Answer 1

1

@Sander van't Veer - I struggled with this same problem recently. It looks like there's a bug in the services module where the password doesn't get set. Try this patch and you should be good.

https://drupal.org/files/issues/user_create-2198005-1.patch

14
  • Eventually I found the same patch you linked to and managed to fix my problem. I commented about it on another question bit totally forgot about my own one! Thanks for posting the solution. May 10, 2014 at 16:28
  • Sure. Did you also have an issue with setting other fields on the user like "roles" and "notify"? I'm having an issue with that still.
    – Justine
    May 10, 2014 at 16:31
  • I had some problems with setting roles but these were quickly fixed. What problems are you running into? May 10, 2014 at 16:35
  • I created a role in the Drupal admin. When I create the user either using Poster or within my app code (ios/objective c) and set the role, it doesn't seem to take. I also tried setting the "notify" property to 0 because I don't want to send out an email to the user after they register, but the site still sends out the email. Is there some bug in the module for setting "roles" and "notify" properties? The user seems to be created fine otherwise besides these properties not being set correctly.
    – Justine
    May 10, 2014 at 16:39
  • 1
    Hmm odd. I'll have a look at my own code and get back to you later this weekend. Edit:had some code on dropbox, we create our users like so { "name": "....", "mail": "...., "pass": "...", "status": "1", "roles": [ "5" ] } Where 5 is the id of the role we wish to give our users May 10, 2014 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.