Hello Support,

We have both a native iOS and Android APP. We are using Drupal 7 and the dev version of the Services API. We are having a problem authenticating to the API because of the CSRF Token Failed issue. We are using application/JSON. We used the user/token parameter to get the token and received this error.

Request failed: unacceptable (406), This happened when we requested the token.

Please provide the sequence of events that need to happen in order to authenticate from a native APP. We need a step by step.

Thank you.

Comments

NextGame created an issue. See original summary.

tyler.frankenstein’s picture

Priority: Critical » Normal
Status: Active » Postponed (maintainer needs more info)

Just use ?q=services/session/token for a plain text token retrieved with a simple GET request.

kylebrowning’s picture

NextGame’s picture

Thank you for your responses. Will review and keep you posted on the outcome. Appreciated.

srinath7’s picture

I ran into a very similar issue today with my apps in production (built with Services and Drupalgap). The apps were working perfectly fine until the day before.

At first the apps wouldn't load. Upon debugging (using XCode and Ripple) I found that the Session token being retrieved from services.module, had a prefixed newline character. This newline is NOT generated by the function drupal_get_token, however I see it in the response received by jDrupal. I'm flummoxed and as a temporary fix, have put in a token=token.trim() in the jDrupal function services_get_csrf_token(), after I receive the token. And now it works just fine. I would definitely be glad to know the root cause for this.

I'm really unsure what caused the server/apps to start functioning different. I don't think it's a Services module issue, cause I have the same setup running on localhost and it works just fine. I'm beginning to think it's got to do with the server config. I recently moved to https, and am wondering if any server updates coupled with that https move had a part to play.

EDIT: I figured the cause of my troubles. It was a .php file I had included. In the script, I had closed the file with a ?> followed by a 'return'. I realize it is best practice to NOT close php files with ?> specifically to avoid such errors. Found it out the hard way!

Reference: http://askubuntu.com/questions/175870/apache-or-php-inserting-a-newline-...

tyler.frankenstein’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

Thanks for following up with this information, it is helpful for folks using Services, and/or DrupalGap and/or jDrupal.