javascript - Issue in this.withCredentials attribute in Cross Origin Resource Sharing - Stack Overflow

We are implementing an AngularJS based application which uses a rest web service hosted in a different

We are implementing an AngularJS based application which uses a rest web service hosted in a different domain. The following script is used for CORS and it works perfectly on Chrome and FireFox. It has an issue in IE9 and Safari when authenticating. It seems the issue is with the withCredentials attribute in those browsers. Is there any other way that IE and Safari supports CORS?

<script type="text/javascript">
     XMLHttpRequest.prototype.realSend = XMLHttpRequest.prototype.send;
     XMLHttpRequest.prototype.send = function(vData) {
        this.withCredentials = true;
        this.realSend.apply(this, arguments);
     };
</script>

We are implementing an AngularJS based application which uses a rest web service hosted in a different domain. The following script is used for CORS and it works perfectly on Chrome and FireFox. It has an issue in IE9 and Safari when authenticating. It seems the issue is with the withCredentials attribute in those browsers. Is there any other way that IE and Safari supports CORS?

<script type="text/javascript">
     XMLHttpRequest.prototype.realSend = XMLHttpRequest.prototype.send;
     XMLHttpRequest.prototype.send = function(vData) {
        this.withCredentials = true;
        this.realSend.apply(this, arguments);
     };
</script>
Share Improve this question edited Oct 7, 2013 at 10:50 Shanaka asked Oct 7, 2013 at 9:30 ShanakaShanaka 1,7383 gold badges21 silver badges43 bronze badges 2
  • If you are asking about credentialed cross origin requests in IE9 or older, the answer is "not supported". These browsers only have limited CORS support via XDomainRequest. – Ray Nicholus Commented Oct 7, 2013 at 12:37
  • Nop. I'm asking for IE10+ versions – Shanaka Commented Oct 8, 2013 at 3:51
Add a ment  | 

1 Answer 1

Reset to default 7

According to the different scenarios we tried we could e up with following summary. Hope that would be useful.

  1. According to the browser specifications IE10+ and Safari 4+ versions supports XHR and withCredentials attribute.
  2. That can be used for CORS without any issue as in the above script.
  3. For other IE versions (9-) we need to use XDR.
  4. URL rewrite mod was not successful with the server side when it es to HTTPS.

The solution was very simple. By default IE and Safari have disabled the 3rd party cookies. Since we use two different domains once a user enters the credentials to login, those browsers were unable to save that cookie. Because of that all other requests were unauthorized.

Steps for allowing 3rd party cookies

  • IE 10 - Internet Options > Privacy > Advanced > Third Party Cookies > Accept
  • Safari - Preferences > Privacy > Block Cookies > Never

Due to this problem we found that in AngularJS version 1.1.1+ they have made it easy by setting the ‘withCredentials’ value in ‘config’ module ( $httpProvider.defaults.withCredentials = true;)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745479269a4629490.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信