<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: CORS Error - Generate Token in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cors-error-generate-token/m-p/1085383#M74120</link>
    <description>&lt;P&gt;I took a quick look and it looks like geopedia.ca is a self-hosted Portal? If so, it's possible something changed on their server-side CORS configuration. Otherwise, you'll need to do some testing to figure out which header within the app is triggering the error, or maybe you are missing a header.&lt;/P&gt;</description>
    <pubDate>Tue, 03 Aug 2021 16:16:12 GMT</pubDate>
    <dc:creator>AndyGup</dc:creator>
    <dc:date>2021-08-03T16:16:12Z</dc:date>
    <item>
      <title>CORS Error - Generate Token</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cors-error-generate-token/m-p/1085379#M74119</link>
      <description>&lt;P&gt;Good Day&lt;BR /&gt;&lt;BR /&gt;A function which retrieves the token for a client, and uses it to authenticate to the hosted feature layer, started failing out of the blue, throwing CORS errors from Angular.&lt;BR /&gt;&lt;BR /&gt;The specific error we're getting is:&lt;/P&gt;&lt;P&gt;Access to fetch at '&lt;A href="https://community.esri.com/" target="_blank" rel="noopener"&gt;https://&amp;lt;client&amp;gt;.geopedia.ca/portal/sharing/rest/generateToken&lt;/A&gt;' from origin '&lt;A href="http://localhost:4200" target="_blank" rel="noopener"&gt;http://localhost:4200&lt;/A&gt;' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.&lt;BR /&gt;&lt;BR /&gt;When we try to access the resource using Insomnia or Postman, we can get a token, and the code we used to fetch the token was working fine a couple of weeks ago, this is the function:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const tokenParams = {
    username:  'blah',
    password:  'blah',
    ip:  '',
    referer:  '',
    client:  'requestip',
    expiration:  '60',
    f:  'pjson'
}

// -ignore
request(this._tokenURL, {params: tokenParams}).then((esriResponse) =&amp;gt; {
    request(this.testURL, {params: {token: esriResponse.token}}).then((response) =&amp;gt; {
        this._featureLayer = _.cloneDeep(response);
        r(this._featureLayer.fields);
    }).catch((error) =&amp;gt; {
        console.log('Error');
        console.log(error);
        j(error);
    });
}).catch((error) =&amp;gt; {
   console.log('Error');
   console.log(error);
   this.alert.genericError();
   j(error);
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I generated the tokenParams object using: &lt;A href="https://community.esri.com/" target="_blank" rel="noopener"&gt;https://&amp;lt;client&amp;gt;.geopedia.ca/portal/sharing/rest/generateToken&lt;/A&gt;&amp;nbsp; which will also return a token.&amp;nbsp; I haven't changed anything in this code in weeks, so I have to assume it's either something on the clients side or ESRI's.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Has anyone run into similar issues?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 03 Aug 2021 16:00:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cors-error-generate-token/m-p/1085379#M74119</guid>
      <dc:creator>AndrewMurdoch1</dc:creator>
      <dc:date>2021-08-03T16:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: CORS Error - Generate Token</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cors-error-generate-token/m-p/1085383#M74120</link>
      <description>&lt;P&gt;I took a quick look and it looks like geopedia.ca is a self-hosted Portal? If so, it's possible something changed on their server-side CORS configuration. Otherwise, you'll need to do some testing to figure out which header within the app is triggering the error, or maybe you are missing a header.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Aug 2021 16:16:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cors-error-generate-token/m-p/1085383#M74120</guid>
      <dc:creator>AndyGup</dc:creator>
      <dc:date>2021-08-03T16:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: CORS Error - Generate Token</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cors-error-generate-token/m-p/1085389#M74121</link>
      <description>&lt;P&gt;Good Day&lt;BR /&gt;&lt;BR /&gt;We can have them look, it's self-hosted, and they've been troubleshooting a problem with ESRI, so they may have changed the settings to something invalid.&amp;nbsp; It's odd the request works from Post Man / Insomnia, but not from Angular.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;My co-worker also ran the token query from C# and was able to retrieve the token.&amp;nbsp; We'll reach out to the client in question.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 03 Aug 2021 16:32:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cors-error-generate-token/m-p/1085389#M74121</guid>
      <dc:creator>AndrewMurdoch1</dc:creator>
      <dc:date>2021-08-03T16:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: CORS Error - Generate Token</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cors-error-generate-token/m-p/1085404#M74123</link>
      <description>&lt;P&gt;Postman gives precise control over headers, in comparison you may not be aware of all the headers that are being generated by the JavaScript-based request() method.&amp;nbsp;That's why we recommend comparing headers between requests that are successful and requests that aren't.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Aug 2021 17:08:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cors-error-generate-token/m-p/1085404#M74123</guid>
      <dc:creator>AndyGup</dc:creator>
      <dc:date>2021-08-03T17:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: CORS Error - Generate Token</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cors-error-generate-token/m-p/1085838#M74141</link>
      <description>&lt;P&gt;Good Day&lt;BR /&gt;&lt;BR /&gt;The problem is on the client's server, but they don't know how to resolve it.&amp;nbsp; We've bypassed the issue for now, by using a token and passing it to the request API.&lt;BR /&gt;&lt;BR /&gt;Thanks for your help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Aug 2021 16:59:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/cors-error-generate-token/m-p/1085838#M74141</guid>
      <dc:creator>AndrewMurdoch1</dc:creator>
      <dc:date>2021-08-04T16:59:33Z</dc:date>
    </item>
  </channel>
</rss>

