esriConfig.request.interceptors not appending token to /legend?f=json

1061
2
Jump to solution
09-29-2022 10:31 AM
jasonwriter1
New Contributor

I'm trying to use the esriConfig.request.interceptors to attach a token for a secured service which works until I try to fetch the legend info for the same url base.

esriConfig.request.interceptors.push({
  urls: "https://gis.wgfd.wyo.gov/arcgis/rest/services/OneSteppe/OneSteppe_ExistingDisturbance_WyGISC/",
  before: function (params) {
   params.requestOptions.query = params.requestOptions.query || {};
   params.requestOptions.query.token = "theToken";
 },
});

The fetch I'm using:

fetch('https://gis.wgfd.wyo.gov/arcgis/rest/services/OneSteppe/OneSteppe_ExistingDisturbance_WyGISC/MapServ... (response) { return response.json() }).then(function (legend) {console.log(legend)})

error is 499 "Token Required".

Thanks in advance for any help.

Jason.

0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor

The interceptors only work when using the request method of the JSAPI.

https://developers.arcgis.com/javascript/latest/api-reference/esri-request.html

It uses fetch under the hood, but can't intercept native fetch requests.

View solution in original post

0 Kudos
2 Replies
ReneRubalcava
Frequent Contributor

The interceptors only work when using the request method of the JSAPI.

https://developers.arcgis.com/javascript/latest/api-reference/esri-request.html

It uses fetch under the hood, but can't intercept native fetch requests.

0 Kudos
jasonwriter1
New Contributor

Thank you. So in this case I would pass the token in the query string of the request, I take it?

0 Kudos