<?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>Question Re: adding CSRF parameter in service.tx(request).run(request.query) in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257484#M4590643</link>
    <description>&lt;P&gt;Hi &lt;SPAN class="mention-scrubbed"&gt;karthiheyan.murugesan1&lt;/SPAN&gt;, &lt;SPAN class="mention-scrubbed"&gt;jhodel18&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;Please see the &lt;A href="https://sap.github.io/cloud-sdk/docs/js/features/odata/use-typed-odata-client-for-javascript-and-typescript/#handling-of-csrf-tokens"&gt;SAP Cloud SDK&lt;/A&gt; for such functionality.&lt;/P&gt;&lt;P&gt;Best,&lt;BR /&gt;Sebastian&lt;/P&gt;</description>
    <pubDate>Mon, 20 Jul 2020 16:50:21 GMT</pubDate>
    <dc:creator>vansyckel</dc:creator>
    <dc:date>2020-07-20T16:50:21Z</dc:date>
    <item>
      <title>adding CSRF parameter in service.tx(request).run(request.query)</title>
      <link>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaq-p/12257482</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;
  &lt;P&gt;Any lead on how to use service.tx(request).run(request.query) for a post call to S/4 odata. &lt;/P&gt;
  &lt;P&gt;More details&lt;/P&gt;
  &lt;P&gt;When I use service.tx(request).run(request.query) for a post call, Iam getting CSRF token invalid error in S/4 and thus 403 error in CF.&lt;/P&gt;
  &lt;P&gt;Iam able to get CSRF token with S/4 URL directly in Tcode /iwfnd/maint_service with header as [X-CSRF-TOKEN : Fetch ].&lt;/P&gt;
  &lt;P&gt;Iam not able to get CSRF token if i use post using service.tx(request).run(request.query) of SAP CAP Service. [HTTP header is not having the [X-CSRF-TOKEN : Fetch] ]&lt;/P&gt;
  &lt;P&gt;Exact question &lt;/P&gt;
  &lt;OL&gt; 
   &lt;LI&gt;How to set header parameter for getting CSRF token in [ service.tx(request).run(request.query) ] . I want to set [X-CSRF-TOKEN : Fetch] in a GET request header so i can set back CSRF token in post call.&lt;/LI&gt; 
  &lt;/OL&gt;
  &lt;P&gt;Regards,&lt;/P&gt;
  &lt;P&gt;Karthi &lt;/P&gt;</description>
      <pubDate>Mon, 20 Jul 2020 09:39:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaq-p/12257482</guid>
      <dc:creator>karthiheyan_murugesan1</dc:creator>
      <dc:date>2020-07-20T09:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: adding CSRF parameter in service.tx(request).run(request.query)</title>
      <link>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257483#M4590642</link>
      <description>&lt;P&gt;I’m afraid that you are going to code the logic for that on your own. According to the documentation below:&lt;/P&gt;&lt;P&gt;&lt;A href="https://cap.cloud.sap/docs/guides/consuming-services#sending-requests"&gt;https://cap.cloud.sap/docs/guides/consuming-services#sending-requests&lt;/A&gt;&lt;/P&gt;&lt;P&gt;the fluent API can cater to do &lt;STRONG&gt;create&lt;/STRONG&gt; (POST) request, however, from my experience, it didn’t work when it starts to use the service via connectivity proxy. So what I did, is I have coded the solution my self using the &lt;A href="https://www.npmjs.com/package/axios"&gt;&lt;STRONG&gt;axios&lt;/STRONG&gt;&lt;/A&gt; node module — it is the same node module that cap for node.js use.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jul 2020 13:13:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257483#M4590642</guid>
      <dc:creator>jhodel18</dc:creator>
      <dc:date>2020-07-20T13:13:15Z</dc:date>
    </item>
    <item>
      <title>Re: adding CSRF parameter in service.tx(request).run(request.query)</title>
      <link>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257484#M4590643</link>
      <description>&lt;P&gt;Hi &lt;SPAN class="mention-scrubbed"&gt;karthiheyan.murugesan1&lt;/SPAN&gt;, &lt;SPAN class="mention-scrubbed"&gt;jhodel18&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;Please see the &lt;A href="https://sap.github.io/cloud-sdk/docs/js/features/odata/use-typed-odata-client-for-javascript-and-typescript/#handling-of-csrf-tokens"&gt;SAP Cloud SDK&lt;/A&gt; for such functionality.&lt;/P&gt;&lt;P&gt;Best,&lt;BR /&gt;Sebastian&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jul 2020 16:50:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257484#M4590643</guid>
      <dc:creator>vansyckel</dc:creator>
      <dc:date>2020-07-20T16:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: adding CSRF parameter in service.tx(request).run(request.query)</title>
      <link>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257485#M4590644</link>
      <description>&lt;P&gt;Thanks Sebastian, As Iam a beginner , i need more info. &lt;/P&gt;&lt;P&gt;Assume i want to execute a simple GET &lt;/P&gt;&lt;P&gt;
1) I generated odata client from edmx. &lt;/P&gt;&lt;P&gt;2) I have my service definition in service.cds. and its corresponding implementation in service.js. &lt;/P&gt;&lt;P&gt;Will my service.js look like this ? Can you help with a demo GITHUB repos &lt;/P&gt;&lt;P&gt;import { header } from './odata_gen/z-operation-service'; 
//this line 1 is giving error &lt;/P&gt;&lt;P&gt;srv.on('READ', 'header', request =&amp;gt; {
return header.requestBuilder().getAll().execute("dest"); })&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jul 2020 21:51:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257485#M4590644</guid>
      <dc:creator>karthiheyan_murugesan1</dc:creator>
      <dc:date>2020-07-20T21:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: adding CSRF parameter in service.tx(request).run(request.query)</title>
      <link>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257486#M4590645</link>
      <description>&lt;P&gt;thanks Jhodel .Iam exploring this &lt;A href="https://blogs.sap.com/2019/11/13/consuming-destinations-in-cloud-foundry-using-axios-in-a-nodejs-application/"&gt;https://blogs.sap.com/2019/11/13/consuming-destinations-in-cloud-foundry-using-axios-in-a-nodejs-application/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jul 2020 21:55:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257486#M4590645</guid>
      <dc:creator>karthiheyan_murugesan1</dc:creator>
      <dc:date>2020-07-20T21:55:08Z</dc:date>
    </item>
    <item>
      <title>Re: adding CSRF parameter in service.tx(request).run(request.query)</title>
      <link>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257487#M4590646</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;I tried implementing a simple sap-cf-axios get method , it was working perfectly. When i call the service second time , it is failing with 407 error. What am I missing ? Any hint ?. This looks strange. It is failing alternatively .&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Karthi &lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 22:17:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257487#M4590646</guid>
      <dc:creator>karthiheyan_murugesan1</dc:creator>
      <dc:date>2020-07-21T22:17:43Z</dc:date>
    </item>
    <item>
      <title>Re: adding CSRF parameter in service.tx(request).run(request.query)</title>
      <link>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257488#M4590647</link>
      <description>&lt;P&gt;There's an issue with the caching of token inside this module &lt;STRONG&gt;sap-cf-destconn&lt;/STRONG&gt;&lt;STRONG&gt;&lt;/STRONG&gt;. So what I did is I hacked the code to disable the passing back of the cached token and it is working fine after that (for subsequent calls). See screenshot below:&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1829682-cached-token.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 01:29:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257488#M4590647</guid>
      <dc:creator>jhodel18</dc:creator>
      <dc:date>2020-07-22T01:29:25Z</dc:date>
    </item>
    <item>
      <title>Re: adding CSRF parameter in service.tx(request).run(request.query)</title>
      <link>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257489#M4590648</link>
      <description>&lt;P&gt;Hi Jhodel,&lt;/P&gt;&lt;P&gt;Thanks a lot &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; :-). I see you raised an issue for this. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; . &lt;/P&gt;&lt;P&gt;This could be dumb question, I see you corrected the .js file of sap-cf-destconn. Assume I do not want to wait for an official fix and want to move on with the local version. How should I handle it in CAP world? Because MTA will not consider my local library and package.json will always install from the library. Is there any way I can copy the library and make as it a local one ,do some config in mta.yaml to consider my local library in deployment and refer the same in service.js .&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 22:38:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257489#M4590648</guid>
      <dc:creator>karthiheyan_murugesan1</dc:creator>
      <dc:date>2020-07-22T22:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: adding CSRF parameter in service.tx(request).run(request.query)</title>
      <link>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257490#M4590649</link>
      <description>&lt;P&gt;Hi Karthiheyan,&lt;/P&gt;&lt;P&gt;You're welcome! About the SAP Cloud SDK, I played around it once and encountered some issues. I'm still new on this tool and haven't really taken a deep look at this. Perhaps when I have some free time, I will look into this again.&lt;/P&gt;&lt;P&gt;Right now I'm comfortable with my current workaround solution, but I need to work on this a little bit more to make it more elegant, what I mean by that is that the workaround solution is working when deployed to SCP, but it is not easy to test locally. Once I have made this solution more compatible with CAP, I plan to write a blog about this.&lt;/P&gt;&lt;P&gt;In order for you to make a local copy of the NPM delivered modules, you can create a lib folder inside your cap "&lt;STRONG&gt;srv&lt;/STRONG&gt;" folder. In my case, I'm not using the module &lt;STRONG&gt;sap-cf-axios&lt;/STRONG&gt;. I'm using &lt;STRONG&gt;axios&lt;/STRONG&gt; + &lt;STRONG&gt;sap-cf-destconn&lt;/STRONG&gt;. I copied &lt;STRONG&gt;connectivity.js&lt;/STRONG&gt; in my &lt;STRONG&gt;srv&lt;/STRONG&gt; &amp;gt; &lt;STRONG&gt;lib&lt;/STRONG&gt; folder. And called it in one of my cap custom .js handlers using this syntax:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;const { readConnectivity } = require("./lib/connectivity");&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Note that when you specify to load a module in this way, you are loading from the local module. But if you are omitting the &lt;STRONG&gt;./&lt;/STRONG&gt; or &lt;STRONG&gt;../&lt;/STRONG&gt; then you are loading from a node_module folder -- like the example below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;const axios = require("axios").default;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Just bear in mind, that if the JS file you copied does call another file within that module you have to copy that JS file as well. In my case, &lt;STRONG&gt;connectivity.js&lt;/STRONG&gt; is calling for &lt;STRONG&gt;tokenCache.js&lt;/STRONG&gt; and that's why I copied it as well. I disabled the returning of the cache but I didn't remove all the logic that is linked to &lt;STRONG&gt;tokenCache.js&lt;/STRONG&gt;. I also cannot wait for a permanent fix for the module so I opted to handle it myself in my own cap project and it is already deployed in SCP.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 08:13:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257490#M4590649</guid>
      <dc:creator>jhodel18</dc:creator>
      <dc:date>2020-07-23T08:13:51Z</dc:date>
    </item>
    <item>
      <title>Re: adding CSRF parameter in service.tx(request).run(request.query)</title>
      <link>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257491#M4590650</link>
      <description>&lt;P&gt;Thanks a lot Jhodel.Sincere thanks for sharing your knowledge.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 14:36:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257491#M4590650</guid>
      <dc:creator>karthiheyan_murugesan1</dc:creator>
      <dc:date>2020-07-23T14:36:36Z</dc:date>
    </item>
    <item>
      <title>Re: adding CSRF parameter in service.tx(request).run(request.query)</title>
      <link>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257492#M4590651</link>
      <description>&lt;P&gt;I was pumped up to finish fixing the code. By this point, it will be easy for you to consume my solution because I already published it in npmjs.com -- see below git repo, and refer to the readme documentation how to install and use it.&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/jcailan/cdse"&gt;https://github.com/jcailan/cdse&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Happy to help Karthiheyan!&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 17:12:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257492#M4590651</guid>
      <dc:creator>jhodel18</dc:creator>
      <dc:date>2020-07-23T17:12:55Z</dc:date>
    </item>
    <item>
      <title>Re: adding CSRF parameter in service.tx(request).run(request.query)</title>
      <link>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257493#M4590652</link>
      <description>&lt;P&gt;Hi Sebastian, Ki &lt;SPAN class="mention-scrubbed"&gt;karthiheyan.murugesan1&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mention-scrubbed"&gt;karthiheyan.murugesan1&lt;/SPAN&gt;: I would suggest you check out &lt;A href="https://cap.cloud.sap/docs/guides/consuming-services"&gt;Consuming Services&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mention-scrubbed"&gt;vansyckel&lt;/SPAN&gt;: can we expect that CAP will hide this complexity from us?&lt;/P&gt;&lt;P&gt;Best regards&lt;BR /&gt;Gregor&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 20:15:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257493#M4590652</guid>
      <dc:creator>gregorw</dc:creator>
      <dc:date>2020-07-23T20:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: adding CSRF parameter in service.tx(request).run(request.query)</title>
      <link>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257494#M4590653</link>
      <description>&lt;P&gt;Thanks a lot Jhodel. I want one more greedy request :-). I think this is not considering the Location id parameter in Destination . When Destination has Location id , this is not able to identify the SCC and resulting in 503 error. I tried configuring a new connection without Location id and it is working for all subsequent calls.&lt;/P&gt;&lt;P&gt;Make this wish true when you have time.Thanks a lot Jhodel.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 23:04:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257494#M4590653</guid>
      <dc:creator>karthiheyan_murugesan1</dc:creator>
      <dc:date>2020-07-23T23:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: adding CSRF parameter in service.tx(request).run(request.query)</title>
      <link>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257495#M4590654</link>
      <description>&lt;P&gt;Hi Karthiheyan, no problem! Yeah, I did not include LocationId in the logic because I'm not using it, and therefore, not able to test. I've applied patch 1.0.2 -- can you try it out and let me know if it works?&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 23:25:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257495#M4590654</guid>
      <dc:creator>jhodel18</dc:creator>
      <dc:date>2020-07-23T23:25:33Z</dc:date>
    </item>
    <item>
      <title>Re: adding CSRF parameter in service.tx(request).run(request.query)</title>
      <link>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257496#M4590655</link>
      <description>&lt;P&gt;Thanks a lot, Jhodel. The latest update is working fine.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Karthi&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jul 2020 12:57:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257496#M4590655</guid>
      <dc:creator>karthiheyan_murugesan1</dc:creator>
      <dc:date>2020-07-24T12:57:12Z</dc:date>
    </item>
    <item>
      <title>Re: adding CSRF parameter in service.tx(request).run(request.query)</title>
      <link>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257497#M4590656</link>
      <description>&lt;P&gt;Hi  Gregor , &lt;/P&gt;&lt;P&gt;There is an open issue in &lt;A href="https://cap.cloud.sap/docs/guides/consuming-services"&gt;Consuming Services&lt;/A&gt;, preventing us from using the POST [csrf token] method to an on-premise system [They might release in Q3/4]. Leaving us with two options &lt;/P&gt;&lt;P&gt;1) Node library like cdse, sap-cf-axios &lt;/P&gt;&lt;P&gt;2) SAP cloud SDK
Here regarding SAP cloud SDK , there are very fewer blog resources for JS world in consuming external services through destination.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Karthi&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jul 2020 13:05:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257497#M4590656</guid>
      <dc:creator>karthiheyan_murugesan1</dc:creator>
      <dc:date>2020-07-24T13:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: adding CSRF parameter in service.tx(request).run(request.query)</title>
      <link>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257498#M4590657</link>
      <description>&lt;P&gt;Hi Karthi,&lt;/P&gt;&lt;P&gt;in Cloud SDK you don't have to do more than provide the destination name in your call to the OData Client. Cloud SDK handles the lookup of the destination and using the Connectivity Proxy behind the scenes: &lt;A href="https://sap.github.io/cloud-sdk/docs/js/features/connectivity/proxy-js-sdk#the-automatic-flow"&gt;https://sap.github.io/cloud-sdk/docs/js/features/connectivity/proxy-js-sdk#the-automatic-flow&lt;/A&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;const businessPartners = BusinessPartner.requestBuilder()
  .getAll().filter(BusinessPartner.BUSINESS_PARTNER_CATEGORY.equals('1'))
  .top(5)
  .execute({"destinationName": 'myDestination'});&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Sebastian&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jul 2020 17:43:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257498#M4590657</guid>
      <dc:creator>SebastianEsch</dc:creator>
      <dc:date>2020-07-24T17:43:05Z</dc:date>
    </item>
    <item>
      <title>Re: adding CSRF parameter in service.tx(request).run(request.query)</title>
      <link>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257499#M4590658</link>
      <description>&lt;P&gt;Hi &lt;SPAN class="mention-scrubbed"&gt;gregorw&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;Improving service consumption is on the roadmap and we'll see what we can do.&lt;/P&gt;&lt;P&gt;Best,&lt;BR /&gt;Sebastian&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jul 2020 14:22:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257499#M4590658</guid>
      <dc:creator>vansyckel</dc:creator>
      <dc:date>2020-07-26T14:22:24Z</dc:date>
    </item>
    <item>
      <title>Re: adding CSRF parameter in service.tx(request).run(request.query)</title>
      <link>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257500#M4590659</link>
      <description>&lt;P&gt;Hi Sebastian Esch!&lt;/P&gt;&lt;P&gt;The Cloud SDK for JS still might have issues with consumption of OData services from the S4/Hana on-premise system.&lt;/P&gt;&lt;P&gt;At least it didn't work in my case. &lt;A href="https://github.com/SAP/cloud-sdk/issues/171"&gt;https://github.com/SAP/cloud-sdk/issues/171&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Though I can get through the proxy to the system I fail with authentication at the on-premise for some reason but when using a standard http request with defined http headers has no issues with authentication.&lt;/P&gt;&lt;P&gt;It could be an issue of the generated odata-client or axios which is used to send a http request to the on-premise.&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Evgeniy&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jul 2020 13:43:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257500#M4590659</guid>
      <dc:creator>Evgenii</dc:creator>
      <dc:date>2020-07-30T13:43:02Z</dc:date>
    </item>
    <item>
      <title>Re: adding CSRF parameter in service.tx(request).run(request.query)</title>
      <link>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257501#M4590660</link>
      <description>&lt;P&gt;I had the same problem when accessing the Cloud 4 Customer OData API through an imported external service. Additionally, the C4C API doens't implement HEAD. &lt;/P&gt;&lt;P&gt;I solved it by modifying http-client.js of  @sap-cloud-sdk . I added the following intercepter at the end of the file (L195 in version 1.28.1). Note that this is targeting C4C and might need some small changes to make it generic. &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;function createRequestInterceptor() {
    const interceptor = axios_1.default.interceptors.request.use(async (config) =&amp;gt; {
        if (config.url.startsWith('/cust/')) {
            // for customer OData resources, reqrite the baseURL to point to the customer namespace
            config.baseURL = config.baseURL.replace(/\/v1\/c4codataapi/, '')
        }
        if (['head', 'get'].includes(config.method)) {
            config.headers['x-csrf-token'] = 'fetch' 
        }
        
        // intercept post/patch/delete and send a head request
        // to the same resource to fetch the CSRF token
        // the intercepter needs to be ejected before sending the head
        // request to avoid endless recursion
        if (['post','delete','patch'].includes(config.method)) {
            let tokenConfig = __assign({}, config)
            // better would be head, but our target system (C4C) doesn't implement HEAD
            tokenConfig.method = 'get'
            delete tokenConfig.data
            delete tokenConfig.headers['content-type']
            delete tokenConfig.headers['content-length']
            tokenConfig.headers.common['x-csrf-token'] = 'fetch'
            tokenConfig.validateStatus = (status) =&amp;gt; {
                return status &amp;gt;= 200 &amp;amp;&amp;amp; status &amp;lt; 300 || status == 400; 
            }
            
            try {
                axios_1.default.interceptors.request.eject(interceptor)
                let tokenResponse = await axios_1.default.request(tokenConfig)
                config.headers.common['x-csrf-token'] = tokenResponse.headers['x-csrf-token']
                const cookies = tokenResponse.headers['set-cookie']
                if (cookies) {
                    config.headers.Cookie = cookies.join('; ')
                }
                
            } catch (e){
                if (e.isAxiosError) {
                    console.log(e.response.status, e.response.statusText)
                } else {
                    console.log(e)
                }
                
            } finally {
                createRequestInterceptor()
            }
        }
        return config
    })
}
createRequestInterceptor()
&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Someone smarter than me can probably come up with a cleaner way to add the interceptor to the http client without having to modify the @sap-cloud-sdk library. Additionally this will request a new CSRF token before every patch/post/delete instead of caching the token. &lt;/P&gt;&lt;P&gt;It's an extremely simple "fix" though and for my purposes it's good enough&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 14:35:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/adding-csrf-parameter-in-service-tx-request-run-request-query/qaa-p/12257501#M4590660</guid>
      <dc:creator>manuel_seeger</dc:creator>
      <dc:date>2020-09-17T14:35:34Z</dc:date>
    </item>
  </channel>
</rss>

