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.

1 Answer 1

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, ...}}

Sign up to request clarification or add additional context in comments.

3 Comments

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')
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
@Eygle check out this question on stackoverflow may be it will help you: stackoverflow.com/a/15106647

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.