1

This is related to a bug report I filed just moments ago. If there's someone who has successfully used the REST server in the Services module with JSONP requests (cross-domain), I'd be happy to hear about it.

I'm currently trying to get cross-domain JSONP requests in services working. However, it seems that I'm out of luck. I have created a sandbox Drupal installation with just the service (and dependent) modules installed. The endpoint for testing is setup as follows:

  • name: api
  • server: REST
  • debug: disabled
  • authentication: session

The REST server is setup as follows:

  • response formatters: json, jsonp
  • request parsing: application/json, application/x-www-form-urlencoded, multipart/form-data

All resources provided by default are turned on. What I'm trying to achieve now is to get the user logged in, in order to be able to access other, permission based ressources such as node etc.

The test request is as follows:

  • url and params: http://d7.sandbox/api/user/login.json?callback=test&username=test&password=test
  • http header Content-Type: application/json

The response returns a 401 HTTP header and the following message:

401 (Unauthorized: Access denied for user anonymous)

It seems that this is not the desired behavior. JSON requests (e.g. a POST request to api/user/login.json) work fine. However, these cannot be used for applications running on other domains or devices to retrieve data from Drupal over the REST server.

Any ideas?

P.S. I went through the tests in the services package. It seems that tests for the JSONP functionality are missing as well.

1
  • did you check /admin/structure/services/list/services and see if you have checked session authentication? it happens once with me that I need to disable it and enable it and then clear the cache.
    – cayerdis
    Commented Oct 20, 2012 at 17:34

1 Answer 1

2

Try POST method instead of GET. Drupal won't allow authentication through GET method due to security reason.

1
  • what about drupal_http_request ?
    – monymirza
    Commented Nov 15, 2012 at 6:14

Your Answer

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

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