0

My goal is to connect to Symfony throughout a WSSE protocole. I have a code which works perfectly when I try to connect to Symfony locally but not when I try to connect to the same Symfony on a distant server. (All the code are the same, the only parameters which change is the APILINK, I also set the .htaccess to allow all headers, requests and origins)

Here is the code (javascript)

SimpleWSSEAuth.setup = function(username, password, salt, options) {
    $.ajaxPrefilter(function(options, originalOptions, jqXHR) {
        jqXHR.setRequestHeader('Authorization', 'Authorization profile="UsernameToken"');
        jqXHR.setRequestHeader('X-WSSE',    SimpleWSSEAuth.BuildXWSSEHeader(username, password, salt));
    });
};

SimpleUserAPI.WSSEAuthentification = function(password, data, success, error) {
    SimpleWSSEAuth.setup(data.username, password, data.salt);

    $.ajax({type: 'GET', dataType:"json", url: APILINK + "public/user", crossDomain: true}).done(success).fail(error);
};

As you can see I call the SimpleWSSEAuth.setup before my ajax request.

Here is my request when APILINK is local:

enter image description here

Here is my request when APILINK is distant:

enter image description here

As you can see the elements 'Authorization' and 'X-WSSE' are presents in the first request but not in the second.

How could I change my request to add those 2 elements with a distant server ? Is it a cross-domain problem ? I tried to find solutions online but I didn't find anything which works actually.

A.L
  • 10,259
  • 10
  • 67
  • 98
Eygle
  • 99
  • 1
  • 6

1 Answers1

0

by looking at your screenshot for distant api link, you are getting "405 method not allowed error" with your ajax call. You need to set dataType to JSONP instead of JSON and also set crossDomain true in your ajax method

$.ajax({type: 'GET', dataType:"jsonp", crossDomain: true, ...}}

Rahul
  • 2,189
  • 7
  • 40
  • 60
  • Thank you for your answer, unfortunately it didn't work. I change json by jsonp and there is some difference but my custom headers are still not send ('Authorization' and 'X-WSSE') – Eygle Dec 23 '14 at 16:59
  • I found this answer which explain why JSONP can't be the solution to my problem: A JSONP request does not use an actual ajax call where you can control the HTTP request. here: [link](http://stackoverflow.com/questions/10546822/setrequestheader-does-not-work-in-jsonp-using-jquery) – Eygle Dec 23 '14 at 17:10
  • 1
    @Eygle check out this question on stackoverflow may be it will help you: http://stackoverflow.com/a/15106647 – Rahul Dec 24 '14 at 07:27