Skip to content

Commit

Permalink
Add support for 'withCredentials' option
Browse files Browse the repository at this point in the history
when sending cross origin requests to servers that are secured with IWA/AD it is necessary to send request with 'withCredentials' set to true
If the layer is created using this option the requests will be adjusted accordingly
  • Loading branch information
luiscamachopt committed Oct 2, 2020
1 parent 59ae703 commit aed611f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Layers/RasterLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { cors } from '../Support';
import { setEsriAttribution } from '../Util';

var Overlay = ImageOverlay.extend({
_initImage: function () {
ImageOverlay.prototype._initImage.call(this);
if (this.options.withCredentials) this._image.crossOrigin = 'use-credentials';
},
onAdd: function (map) {
this._topLeft = map.getPixelBounds().min;
ImageOverlay.prototype.onAdd.call(this, map);
Expand Down
2 changes: 2 additions & 0 deletions src/Request.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ function xmlHttpGet (url, params, callback, context) {
if (typeof context !== 'undefined' && context !== null) {
if (typeof context.options !== 'undefined') {
httpRequest.timeout = context.options.timeout;
if (context.options.withCredentials) httpRequest.withCredentials = true;
}
}
httpRequest.send(null);
Expand All @@ -128,6 +129,7 @@ export function request (url, params, callback, context) {
if (typeof context !== 'undefined' && context !== null) {
if (typeof context.options !== 'undefined') {
httpRequest.timeout = context.options.timeout;
if (context.options.withCredentials) httpRequest.withCredentials = true;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function _findIdAttributeFromFeature (feature) {
export function responseToFeatureCollection (response, idAttribute) {
var objectIdField;
var features = response.features || response.results;
var count = features.length;
var count = features && features.length;

if (idAttribute) {
objectIdField = idAttribute;
Expand Down

0 comments on commit aed611f

Please sign in to comment.