question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enable passing headers (and possibly credentials) to fetch?

See original GitHub issue

Hello,

I am using “arcgis-rest-js” library to query a secured Web-tiers ArcGIS Server from NodeJS backend. The ArcGIS Server is not federated to a Portal so I cannot use the built-in Oauth mechanism. I am able to query the ArcGIS Server using fetch by specifiying a cookie to add in the request: fetch(agsUrl, { headers: { Cookie: mycookie } })

but I am under the impression that it is not possible with this library or did I miss anything ?

Thanks for your help and for this well-documented library !

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
itrewcommented, Jan 17, 2019

@jgravois I’ll go ahead and log another issue or now, as it really is a separate, but probably a pretty low priority. I’ll be sure include my work around in the new issue in case anyone else stumbles onto the same problem.

1reaction
Bibobacommented, Aug 21, 2018

In the meantime, I was able to solve my issue using a custom fetch with cookie management:

const nodeFetch = require("node-fetch");
const tough = require('tough-cookie');
const cookieJar = new tough.CookieJar(mycookies);
const fetchWithCookie = require('fetch-cookie')(nodeFetch, cookieJar);
const { queryFeatures } = require("@esri/arcgis-rest-feature-service");

queryFeatures({
  fetch: fetchWithCookie,
  url: panoramicServiceUrl,
  where: whereClause
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using the Fetch API - MDN Web Docs
Sending a request with credentials included ... To cause browsers to send a request with credentials included on both same-origin and cross-origin ...
Read more >
Fetch: Cross-Origin Requests - The Modern JavaScript Tutorial
If the server agrees to accept the request with credentials, it should add a header Access-Control-Allow-Credentials: true to the response, in ...
Read more >
How to send data using fetch and POST request with ...
you need to pass headers like this in your fetch request for post method: { credentials: 'include', mode: 'cors', method: 'POST', headers: ...
Read more >
Handling cookies with Fetch's credentials - Zell Liew
Fetch has a credentials option that can be used to send credentials to servers. It has three possible values — omit , same-origin...
Read more >
Fetch Standard
Header names starting with ` Sec- ` are reserved to allow new ... cross-origin and allow for more versatile fetches than possible with ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found