<?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 Do I need a webscript to call external rest server (CORS)? in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/do-i-need-a-webscript-to-call-external-rest-server-cors/m-p/26807#M11555</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I try to access another Rest service outside from Alfresco via ADF. Everytime I try to execute the call. I get the following error:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Access to XMLHttpRequest at 'https:/host/endpoint' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also added the endpoint to the proxy.conf.json&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE style="background-color: #2b2b2b; color: #a9b7c6; font-family: 'Courier New'; font-size: 9.0pt;"&gt;&lt;SPAN style="color: #9876aa;"&gt;"/endpoint"&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;: &lt;/SPAN&gt;{&lt;BR /&gt;  &lt;SPAN style="color: #9876aa;"&gt;"target"&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;: &lt;/SPAN&gt;&lt;SPAN style="color: #6a8759;"&gt;"https://hostname"&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;,&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;  &lt;/SPAN&gt;&lt;SPAN style="color: #9876aa;"&gt;"secure"&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;: false,&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;  &lt;/SPAN&gt;&lt;SPAN style="color: #9876aa;"&gt;"changeOrigin"&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;: true&lt;BR /&gt;&lt;/SPAN&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;With the same result as before.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I use the following class:&lt;/P&gt;&lt;PRE style="background-color: #2b2b2b; color: #a9b7c6; font-family: 'Courier New'; font-size: 9.0pt;"&gt;&lt;SPAN style="color: #cc7832;"&gt;export class &lt;/SPAN&gt;ClassService {&lt;BR /&gt;&lt;BR /&gt;  &lt;SPAN style="color: #cc7832;"&gt;constructor&lt;/SPAN&gt;(&lt;SPAN style="color: #cc7832;"&gt;private &lt;/SPAN&gt;&lt;SPAN style="color: #9876aa;"&gt;http&lt;/SPAN&gt;: HttpClient) {&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;  &lt;SPAN style="color: #cc7832;"&gt;private &lt;/SPAN&gt;&lt;SPAN style="color: #ffc66d;"&gt;getLoginHeader&lt;/SPAN&gt;(username: &lt;SPAN style="color: #cc7832;"&gt;string, &lt;/SPAN&gt;password: &lt;SPAN style="color: #cc7832;"&gt;string&lt;/SPAN&gt;) {&lt;BR /&gt;&lt;BR /&gt;    &lt;SPAN style="color: #cc7832;"&gt;let &lt;/SPAN&gt;Headers: HttpHeaders = &lt;SPAN style="color: #cc7832;"&gt;new &lt;/SPAN&gt;HttpHeaders()&lt;SPAN style="color: #cc7832;"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;    &lt;/SPAN&gt;console.&lt;SPAN style="color: #ffc66d;"&gt;log&lt;/SPAN&gt;(&lt;SPAN style="color: #6a8759;"&gt;'Header ' &lt;/SPAN&gt;+ &lt;SPAN style="color: #6a8759;"&gt;'Basic ' &lt;/SPAN&gt;+ &lt;SPAN style="color: #ffc66d;"&gt;btoa&lt;/SPAN&gt;(username + &lt;SPAN style="color: #6a8759;"&gt;':' &lt;/SPAN&gt;+ password))&lt;SPAN style="color: #cc7832;"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;    &lt;/SPAN&gt;Headers = Headers.&lt;SPAN style="color: #ffc66d;"&gt;append&lt;/SPAN&gt;(&lt;SPAN style="color: #6a8759;"&gt;'Authorization'&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #6a8759;"&gt;'Basic ' &lt;/SPAN&gt;+ &lt;SPAN style="color: #ffc66d;"&gt;btoa&lt;/SPAN&gt;(username + &lt;SPAN style="color: #6a8759;"&gt;':' &lt;/SPAN&gt;+ password))&lt;SPAN style="color: #cc7832;"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;    &lt;/SPAN&gt;Headers = Headers.&lt;SPAN style="color: #ffc66d;"&gt;append&lt;/SPAN&gt;(&lt;SPAN style="color: #6a8759;"&gt;'Access-Control-Allow-Origin'&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #6a8759;"&gt;'*'&lt;/SPAN&gt;)&lt;SPAN style="color: #cc7832;"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;    &lt;/SPAN&gt;Headers =  Headers.&lt;SPAN style="color: #ffc66d;"&gt;append&lt;/SPAN&gt;(&lt;SPAN style="color: #6a8759;"&gt;'Content-Type'&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #6a8759;"&gt;'application/x-www-form-urlencoded'&lt;/SPAN&gt;)&lt;SPAN style="color: #cc7832;"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;    &lt;/SPAN&gt;console.&lt;SPAN style="color: #ffc66d;"&gt;log&lt;/SPAN&gt;(Headers)&lt;SPAN style="color: #cc7832;"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;    return &lt;/SPAN&gt;Headers&lt;SPAN style="color: #cc7832;"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;  &lt;/SPAN&gt;}&lt;BR /&gt;&lt;BR /&gt;  &lt;SPAN style="color: #ffc66d;"&gt;getBatchClasses&lt;/SPAN&gt;(username: &lt;SPAN style="color: #cc7832;"&gt;string, &lt;/SPAN&gt;password: &lt;SPAN style="color: #cc7832;"&gt;string &lt;/SPAN&gt;) {&lt;BR /&gt;&lt;BR /&gt;    &lt;SPAN style="color: #cc7832;"&gt;return this&lt;/SPAN&gt;.&lt;SPAN style="color: #9876aa;"&gt;http&lt;/SPAN&gt;.&lt;SPAN style="color: #ffc66d;"&gt;get&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="color: #cc7832;"&gt;any&lt;/SPAN&gt;&amp;gt;(&lt;SPAN style="color: #6a8759;"&gt;'/dendpoint'&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;,&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;      &lt;/SPAN&gt;{&lt;SPAN style="color: #9876aa;"&gt;headers&lt;/SPAN&gt;: &lt;SPAN style="color: #cc7832;"&gt;this&lt;/SPAN&gt;.&lt;SPAN style="color: #ffc66d;"&gt;getLoginHeader&lt;/SPAN&gt;(username&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;password)}).&lt;SPAN style="color: #ffc66d;"&gt;subscribe&lt;/SPAN&gt;(response =&amp;gt; {&lt;BR /&gt;      console.&lt;SPAN style="color: #ffc66d;"&gt;log&lt;/SPAN&gt;(response)&lt;SPAN style="color: #cc7832;"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;    &lt;/SPAN&gt;}&lt;SPAN style="color: #cc7832;"&gt;, &lt;/SPAN&gt;err =&amp;gt; {&lt;BR /&gt;      console.&lt;SPAN style="color: #ffc66d;"&gt;log&lt;/SPAN&gt;(&lt;SPAN style="color: #6a8759;"&gt;'User authentication failed!'&lt;/SPAN&gt;)&lt;SPAN style="color: #cc7832;"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;    &lt;/SPAN&gt;})&lt;SPAN style="color: #cc7832;"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;  &lt;/SPAN&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;  &lt;SPAN style="color: #ffc66d;"&gt;logout&lt;/SPAN&gt;() {&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;    localStorage.&lt;SPAN style="color: #ffc66d;"&gt;removeItem&lt;/SPAN&gt;(&lt;SPAN style="color: #6a8759;"&gt;'token'&lt;/SPAN&gt;)&lt;SPAN style="color: #cc7832;"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #cc7832;"&gt;  &lt;/SPAN&gt;}&lt;BR /&gt;&lt;BR /&gt;}&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I try to access it with Postman it works properly. That sounds for me, that ADF forces to use a repository webscript to access external resources. Is this correct? If not can somebody give me a hint?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Kaffi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 04 Apr 2019 11:43:11 GMT</pubDate>
    <dc:creator>kaffi</dc:creator>
    <dc:date>2019-04-04T11:43:11Z</dc:date>
    <item>
      <title>Do I need a webscript to call external rest server (CORS)?</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/do-i-need-a-webscript-to-call-external-rest-server-cors/m-p/26807#M11555</link>
      <description>I try to access another Rest service outside from Alfresco via ADF. Everytime I try to execute the call. I get the following error:Access to XMLHttpRequest at 'https:/host/endpoint' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access</description>
      <pubDate>Thu, 04 Apr 2019 11:43:11 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/do-i-need-a-webscript-to-call-external-rest-server-cors/m-p/26807#M11555</guid>
      <dc:creator>kaffi</dc:creator>
      <dc:date>2019-04-04T11:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: Do I need a webscript to call external rest server (CORS)?</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/do-i-need-a-webscript-to-call-external-rest-server-cors/m-p/26808#M11556</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you have made a change on proxy.conf.json then make sure that you are not touching app.config.json file.&lt;/P&gt;&lt;P&gt;OR&amp;nbsp; else enable CORS in alfresco.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please follow the link for ref&amp;nbsp;&lt;A _jive_internal="true" href="https://community.alfresco.com/community/application-development-framework/blog/2017/06/20/adf-cors-solving-strategies#jive_content_id_4_Enabling_CORS_in_Apache" rel="nofollow noopener noreferrer"&gt;https://community.alfresco.com/community/application-development-framework/blog/2017/06/20/adf-cors-solving-strategies#jive_content_id_4_Enabling_CORS_in_Apache&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Apr 2019 17:37:24 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/do-i-need-a-webscript-to-call-external-rest-server-cors/m-p/26808#M11556</guid>
      <dc:creator>yogeshpj</dc:creator>
      <dc:date>2019-04-04T17:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: Do I need a webscript to call external rest server (CORS)?</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/do-i-need-a-webscript-to-call-external-rest-server-cors/m-p/26809#M11557</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the answer, but my question was more about the external rest service I want to call which is not running in Alfresco. Is it possible to access this external rest service directly, because I always get the CORS error, or do I need to access it over a webscript?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Apr 2019 06:19:15 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/do-i-need-a-webscript-to-call-external-rest-server-cors/m-p/26809#M11557</guid>
      <dc:creator>kaffi</dc:creator>
      <dc:date>2019-04-05T06:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: Do I need a webscript to call external rest server (CORS)?</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/do-i-need-a-webscript-to-call-external-rest-server-cors/m-p/26810#M11558</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In that external rest service ,you need to enable CORS.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Apr 2019 04:32:44 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/do-i-need-a-webscript-to-call-external-rest-server-cors/m-p/26810#M11558</guid>
      <dc:creator>sp2</dc:creator>
      <dc:date>2019-04-07T04:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: Do I need a webscript to call external rest server (CORS)?</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/do-i-need-a-webscript-to-call-external-rest-server-cors/m-p/26811#M11559</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you are running ADF application on nginx then you can use proxy and then allow CORS on your system.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Apr 2019 05:30:38 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/do-i-need-a-webscript-to-call-external-rest-server-cors/m-p/26811#M11559</guid>
      <dc:creator>mdtabrezmca</dc:creator>
      <dc:date>2019-04-08T05:30:38Z</dc:date>
    </item>
    <item>
      <title>Re: Do I need a webscript to call external rest server (CORS)?</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/do-i-need-a-webscript-to-call-external-rest-server-cors/m-p/26812#M11560</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This actually isn't an ADF specific question. It doesn't depend on ADF if you need CORS to access an external REST service or not.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Do you need to configure CORS? It depends.&lt;BR /&gt;Does the REST service run on the same domain &amp;amp; port or on another domain or port?&lt;/P&gt;&lt;P&gt;In the first case you don't need it, in the second case you do.&lt;BR /&gt;Also read this:&amp;nbsp;&lt;A href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS" rel="nofollow noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If it is an external resource (like in not a company resource), why isn't CORS already&amp;nbsp;enabled on the resource? CORS needs to be configured on the external service, not on in ADF/Angular.&amp;nbsp;Adding a CORS header client side won't help you.&lt;BR /&gt;You always could proxy that resource (that's basically what proxy.conf.js does), but if CORS isn't present, are you allowed to consume that resource in that way?&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Jun 2019 12:53:04 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/do-i-need-a-webscript-to-call-external-rest-server-cors/m-p/26812#M11560</guid>
      <dc:creator>d_m</dc:creator>
      <dc:date>2019-06-28T12:53:04Z</dc:date>
    </item>
  </channel>
</rss>

