JSONP Server with key authentication

Events happening in the community are now at Drupal community events on www.drupal.org.
jazzdrive3's picture

I'm building an iPhone app using JQTouch/JQuery and PhoneGap, and so I was hoping the services module would allow me to pull content via javascript into my iPhone application from Drupal. In theory.

It took me all day to figure out why my calls weren't working with the normal JSON server...because it's cross-domain. Ugh.

So now I'm going to focus on JSONP, which should solve THAT problem. But I can't really find a clear explanation of how to do anything with key authentication in javascript. Or would key authentication even be necessary here? I do want it as secure as possible.

I already downloaded http://point-at-infinity.org/jssha256/ for the hash functions I need (I think I need anyway).

As a test, I want to try something like:

$.ajax({
     type: "POST",
     url: service_url,
     dataType: "jsonp",
     data: {"method": "node.get", "nid": 15},
     success: function(msg){
       alert( "Data: " + msg["#data"].nid );
     }
});

I assume this would work with authentication off, assuming I've made the proper modifications to the json_server module so it accepts jsonp. But what do I add to the data object if I am using key authentication with session ids?

Thanks!

Comments

solutions?

primerg's picture

have you figured this out? I want to do the same thing.

I'm also interested in this

FreddieK's picture

I'm also interested in this subject. Has anyone found a solution to this?

Reference

rjbrown99's picture

A solid reference is here: http://drupal.org/node/900630

JSONP connect

pajoh's picture

That reference link is for Drupal 6, and I'd like a Drupal 7 solution because services 3 supports JSONP.

I've been trying the following to connect and have had no luck. Any help would be much appreciated.

var val = {
type: "POST",
url: serviceEndpoint + "/system/connect.jsonp",
dataType: 'jsonp',
error: function(XMLHttpRequest, textStatus, errorThrown) {

    console.log(JSON.stringify(XMLHttpRequest));
    console.log(JSON.stringify(textStatus));
    console.log(JSON.stringify(errorThrown));

  },
  success: function(data){
    console.log(data);

  }
};

try {
$.ajax(val);
}
catch (error) { alert(error); }

jsonp can't post

cdmo's picture

This approach doesn't work. I don't have an alternative for you, but when you attempt a POST request with JSONP it will be turned into a GET request. See http://stackoverflow.com/a/4508215/721065

Here's an alternative: http://drupal.org/node/1334758

Services

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: