<?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: How to obtain CSRF token from Qlik Cloud in Integration, Extension &amp; APIs</title>
    <link>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2490738#M21458</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Following this post, you're right, you cannot use bearer auth token .&amp;nbsp;&amp;nbsp;&lt;A href="https://community.qlik.com/t5/Integration-Extension-APIs/How-can-i-fetch-a-csrf-token-with-an-access-token/td-p/1900614" target="_blank"&gt;Solved: How can i fetch a csrf token with an access token? - Qlik Community - 1900614&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regards&lt;/P&gt;</description>
    <pubDate>Tue, 05 Nov 2024 09:06:50 GMT</pubDate>
    <dc:creator>mpc</dc:creator>
    <dc:date>2024-11-05T09:06:50Z</dc:date>
    <item>
      <title>How to obtain CSRF token from Qlik Cloud</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2490618#M21453</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I’m currently migrating a mashup from Qlik On-Premise to Qlik Cloud.&lt;/P&gt;
&lt;P&gt;My mashup uses Enigma.js and Nebula.js for visualizations, but I’m running into issues while trying to obtain the CSRF token. I’ve tried two different approaches:&lt;/P&gt;
&lt;H3&gt;1. Qlik Cloud with standard Identity Provider and frontend with Keycloak as Identity Provider&lt;/H3&gt;
&lt;P&gt;Here’s the scenario:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The frontend authenticates users through Keycloak.&lt;/LI&gt;
&lt;LI&gt;The frontend calls a Node.js API, passing the Qlik &lt;CODE&gt;userId&lt;/CODE&gt;&amp;nbsp;as parameter, and retrieves a web token via OAuth impersonation.&lt;/LI&gt;
&lt;LI&gt;After obtaining the web token, the frontend calls a separate Node.js API to retrieve the CSRF token. However, this results in a 404 error ("token not found").&lt;/LI&gt;
&lt;/UL&gt;
&lt;H3&gt;2. Qlik Cloud with Keycloak as Identity Provider&lt;/H3&gt;
&lt;P&gt;In this scenario:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The frontend authenticates users through Keycloak.&lt;/LI&gt;
&lt;LI&gt;The frontend calls a Node.js API, passing the Keycloak session token to obtain the CSRF token. Unfortunately, I’m still getting the same 404 error.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I suspect the issue might be that the &lt;CODE&gt;/api/v1/csrf-token&lt;/CODE&gt; endpoint isn’t designed to issue a CSRF token when a web token is used as an authorization bearer token. The documentation includes an example with an API key, but that solution isn’t feasible in my case because multiple users need access to the mashup.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone offer some guidance on this?&lt;/P&gt;
&lt;P&gt;Thanks for the support!&lt;/P&gt;
&lt;P&gt;Cristian&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2024 15:45:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2490618#M21453</guid>
      <dc:creator>cristian_dalsanto</dc:creator>
      <dc:date>2024-11-04T15:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to obtain CSRF token from Qlik Cloud</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2490738#M21458</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Following this post, you're right, you cannot use bearer auth token .&amp;nbsp;&amp;nbsp;&lt;A href="https://community.qlik.com/t5/Integration-Extension-APIs/How-can-i-fetch-a-csrf-token-with-an-access-token/td-p/1900614" target="_blank"&gt;Solved: How can i fetch a csrf token with an access token? - Qlik Community - 1900614&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regards&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2024 09:06:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2490738#M21458</guid>
      <dc:creator>mpc</dc:creator>
      <dc:date>2024-11-05T09:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to obtain CSRF token from Qlik Cloud</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2490852#M21461</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/81045"&gt;@cristian_dalsanto&lt;/a&gt;&amp;nbsp;, if you are using a M2M impersonation token you should not need to use CRSF token. What is your goal? You want to get a CSRF token for doing what?&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2024 14:21:00 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2490852#M21461</guid>
      <dc:creator>alex_colombo</dc:creator>
      <dc:date>2024-11-05T14:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to obtain CSRF token from Qlik Cloud</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2490859#M21463</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/145804"&gt;@alex_colombo&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The M2M impersonation token works well when embedding visualizations using the Qlik-embed framework—I’ve successfully used it in a different mashup scenario.&lt;/P&gt;
&lt;P&gt;Here, though, I need to establish a WebSocket connection to Qlik Cloud, and from what I read in the documentation, a CSRF token is required for this connection. Am I mistaken? Is it possible to create a WebSocket connection directly using the M2M impersonation token? If so, could you please point me to any documentation on that?&lt;/P&gt;
&lt;P&gt;Thank you very much for your support!&lt;/P&gt;
&lt;P&gt;Cristian&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2024 14:34:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2490859#M21463</guid>
      <dc:creator>cristian_dalsanto</dc:creator>
      <dc:date>2024-11-05T14:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to obtain CSRF token from Qlik Cloud</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2490876#M21464</link>
      <description>&lt;P&gt;You are referring to &lt;A href="https://community.qlik.com/t5/Support-Updates/Upgrade-advisory-for-Qlik-Sense-on-premise-November-2024/ba-p/2480385" target="_self"&gt;this&lt;/A&gt; article about CRSF token? This is needed only for onprem version of the product, and not Qlik Cloud.&lt;/P&gt;
&lt;P&gt;What are you using for creating WebSocket connection? enigma.js, qlik/api or custom code? In any case, you should be able to use M2M impersonation token without CSRF token. Please give it a try.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2024 15:34:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2490876#M21464</guid>
      <dc:creator>alex_colombo</dc:creator>
      <dc:date>2024-11-05T15:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to obtain CSRF token from Qlik Cloud</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2490906#M21468</link>
      <description>&lt;P&gt;I create the web socket using enigma.create method as the following code:&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt; const session = enigma.create({
    schema,
    // url: `wss://${environment.QLIK_URL}/app/${environment.QLIK_APPID}`,
    url: `wss://${environment.QLIK_URL}/app/${environment.QLIK_APPID}?qlik-web-integration-id=${environment.WEBINTEGRATIONID}`,
    responseInterceptors: [{
      // We only want to handle failed responses from QIX Engine:
      onRejected: function retryAbortedError(sessionReference, request: any, error: any) {
        console.log('Request: Rejected', error);

        if (error.code == -1) {
          console.log('not connected to qlik - app refresh');
          window.location.reload();
        }
        // We only want to handle aborted QIX errors:
        if (error.code === schema.enums.LocalizedErrorCode.LOCERR_GENERIC_ABORTED) {
          // We keep track of how many consecutive times we have tried to do this call:
          request.tries = (request.tries || 0) + 1;
          console.log(`Request: Retry #${request.tries}`);
          // We do not want to get stuck in an infinite loop here if something has gone
          // awry, so we only retry until we have reached MAX_RETRIES:
          if (request.tries &amp;lt;= MAX_RETRIES) {
            return request.retry();
          }
        }
        // If it was not an aborted QIX call, or if we reached MAX_RETRIES, we let the error
        // trickle down to potential other interceptors, and finally down to resolving/rejecting
        // the initial promise that the user got when invoking the QIX method:
        return (error);
      },
    }],
  });&lt;/LI-CODE&gt;
&lt;P&gt;I tried 2 different scenario.&lt;/P&gt;
&lt;P&gt;1. Qlik and Mashup using the same Identity provider (keycloak).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Qlik with standard IdP and Mashup under Keycloak. In this case, before creating the web socket I retrieve a M2M impersonation token from a node.js backend. But I don't know how to pass it to the enigma.create method...&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Any suggestions would be greatly appreciated.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Cris&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2024 17:38:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2490906#M21468</guid>
      <dc:creator>cristian_dalsanto</dc:creator>
      <dc:date>2024-11-05T17:38:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to obtain CSRF token from Qlik Cloud</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2491120#M21471</link>
      <description>&lt;P&gt;If you are using enigma.js, just update enigma at latest version and enigma will take care about CRSF token. For M2M impersonation, try to attach it to websocket header. For using websocket header try to do this like did it &lt;A href="https://medium.com/@andrewfu_17838/client-side-jwt-authentication-with-enigma-js-in-angular2-2d20c821cce6" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2024 12:56:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2491120#M21471</guid>
      <dc:creator>alex_colombo</dc:creator>
      <dc:date>2024-11-06T12:56:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to obtain CSRF token from Qlik Cloud</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2492233#M21497</link>
      <description>&lt;P&gt;Thanks Alex for the support.&lt;/P&gt;
&lt;P&gt;However, despite trying different methods, I still can't find the right way to authenticate my WebSocket without going through the login process.&lt;/P&gt;
&lt;P&gt;I'll try to describe my situation more clearly:&lt;/P&gt;
&lt;P&gt;My mashup is an Angular application that uses Keycloak for security management. When the application starts, during the initialization phase, a Keycloak service checks if I'm authenticated. If not, it redirects me to the Keycloak login page. After logging in, I can obtain the Qlik Cloud user ID among the attributes of the logged-in user.&lt;/P&gt;
&lt;P&gt;With this user ID, I can call a backend service (node.js) that, through an M2M OAuth2 impersonation, provides me with an access token.&lt;/P&gt;
&lt;P&gt;In my previous mashup, where I used &lt;CODE&gt;qlik-embed&lt;/CODE&gt;, I passed this web token directly to Qlik Embed following this example:&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;&amp;lt;script
  crossorigin="anonymous"
  type="application/javascript"
  src="https://cdn.jsdelivr.net/npm/@qlik/embed-web-components@1/dist/index.min.js"
  data-host="https://tenantName.region.qlikcloud.com"
  data-client-id="OAuth impersonation client Id"
  data-get-access-token="getAccessToken"
  data-auth-type="Oauth2"
&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script&amp;gt;
  async function getAccessToken() {
    const response = await fetch("/access-token", {
      method: "POST",
      credentials: "include",
      mode: "same-origin",
      redirect: "follow",
    });
    if (response.status === 200) {
      return response.text();
    }
    const err = new Error("Unexpected serverside authentication error");
    err.status = response.status;
    err.detail;
    throw err;
  }
&amp;lt;/script&amp;gt;&lt;/LI-CODE&gt;
&lt;P&gt;and everything worked fine.&lt;/P&gt;
&lt;P&gt;In this case, however, I need to interact with the engine, as I require variables and hypercubes. So I need to establish a WebSocket connection to the engine. But I can’t find a way to do this without having to go through Qlik Cloud’s login again.&lt;/P&gt;
&lt;P&gt;Am I perhaps using the wrong approach? Is &lt;CODE&gt;enigma.js&lt;/CODE&gt; on the client side maybe not the best choice?&lt;/P&gt;
&lt;P&gt;I’ve also looked at &lt;CODE&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/229862"&gt;@qlik&lt;/a&gt;/api&lt;/CODE&gt;, which does roughly the same thing, but even there, authentication via token isn’t supported (at most, &lt;CODE&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/229862"&gt;@qlik&lt;/a&gt;/api&lt;/CODE&gt; accepts an API key, which isn’t suitable for my case).&lt;/P&gt;
&lt;P&gt;Do you have any suggestions for me?&lt;BR /&gt;&lt;BR /&gt;Many Thanks&lt;BR /&gt;&lt;BR /&gt;Cristian&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2024 10:17:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2492233#M21497</guid>
      <dc:creator>cristian_dalsanto</dc:creator>
      <dc:date>2024-11-12T10:17:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to obtain CSRF token from Qlik Cloud</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2492261#M21499</link>
      <description>&lt;P&gt;Ok now it is more clear. The right approach is to use qlik/api and using Engine APIs. I know, it is not documented yet but you can use OAuth M2M token with qlik/api. Below how to do it (replace oauthToken variable with your M2M token):&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;const config = {
    authType: "oauth2",
    host: configParams.tenantHostname,
    clientId: configParams.oAuthClientId,
    getAccessToken: oauthToken
};

qlikApi.auth.setDefaultHostConfig(config);

//Open an app using qix
const appSession = qlikApi.qix.openAppSession(configParams.appId);
// get the "qix document (qlik app)"
const app = await appSession.getDoc();&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2024 11:40:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2492261#M21499</guid>
      <dc:creator>alex_colombo</dc:creator>
      <dc:date>2024-11-12T11:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to obtain CSRF token from Qlik Cloud</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2492322#M21501</link>
      <description>&lt;P&gt;Thanks Alex,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I was looking for a method just like this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I’ve just implemented it as follows:&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;async function getEnigmaSessionAndApp2(webToken: string) {
  const hostConfig: any = {
    authType: "oauth2",
    host: environment.QLIK_PARAMETERS.QLIK_URL,
    clientId: environment.QLIK_PARAMETERS.CLIENT_ID,
    getAccessToken: webToken
  }
  auth.setDefaultHostConfig(hostConfig);
  const session = qix.openAppSession({ appId: environment.QLIK_PARAMETERS.QLIK_APPID });
  const app = await session.getDoc();
  return [session, app];
}&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;Unfortunately,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;I’m getting a 401 error when I do &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;session.getDoc();&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;as if the token were invalid...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Am I missing something?&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;And here’s the returned error.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cristian_dalsanto_0-1731421989642.png" style="width: 768px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/174258i9CFAE874020EDF7A/image-dimensions/768x190?v=v2" width="768" height="190" role="button" title="cristian_dalsanto_0-1731421989642.png" alt="cristian_dalsanto_0-1731421989642.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Cris&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2024 14:35:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2492322#M21501</guid>
      <dc:creator>cristian_dalsanto</dc:creator>
      <dc:date>2024-11-12T14:35:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to obtain CSRF token from Qlik Cloud</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2492360#M21503</link>
      <description>&lt;P&gt;Are you using in qlik/api configuration the same OAuth client id use in M2M impersonation token request?&lt;/P&gt;
&lt;P&gt;What are the scopes set in OAuth client in Management Console? Can you share the config here?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2024 16:38:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2492360#M21503</guid>
      <dc:creator>alex_colombo</dc:creator>
      <dc:date>2024-11-12T16:38:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to obtain CSRF token from Qlik Cloud</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2492373#M21505</link>
      <description>&lt;P&gt;yes,&lt;/P&gt;
&lt;P&gt;I'm usign the same OAuth client:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cristian_dalsanto_0-1731433393624.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/174265i9FFC8AE793CD1F1F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="cristian_dalsanto_0-1731433393624.png" alt="cristian_dalsanto_0-1731433393624.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cristian_dalsanto_1-1731433435063.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/174266iA2CF78D8F54D415B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="cristian_dalsanto_1-1731433435063.png" alt="cristian_dalsanto_1-1731433435063.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cristian_dalsanto_2-1731433454995.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/174267i2E4CDF5FB0606D32/image-size/medium?v=v2&amp;amp;px=400" role="button" title="cristian_dalsanto_2-1731433454995.png" alt="cristian_dalsanto_2-1731433454995.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cristian_dalsanto_3-1731433512313.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/174268i30BBB8C38172657D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="cristian_dalsanto_3-1731433512313.png" alt="cristian_dalsanto_3-1731433512313.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I use the same client in a second mashup (Qlik-embed) and it's working fine&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2024 17:47:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2492373#M21505</guid>
      <dc:creator>cristian_dalsanto</dc:creator>
      <dc:date>2024-11-12T17:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to obtain CSRF token from Qlik Cloud</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2492453#M21509</link>
      <description>&lt;P&gt;Which scope you are using when you are requesting M2M token? Which userid you are using? Did you check if that userId has access to the app you are trying to open?&lt;/P&gt;
&lt;P&gt;Another thing, try to avoid mixed content, I see you have your webapp running on http but Qlik SaaS uses https. Please change your local websever to https.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Nov 2024 08:43:36 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2492453#M21509</guid>
      <dc:creator>alex_colombo</dc:creator>
      <dc:date>2024-11-13T08:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to obtain CSRF token from Qlik Cloud</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2492531#M21514</link>
      <description>&lt;P&gt;I tested three different scopes: 'user_default,' 'admin_classic,' and 'apps,' but received the same error each time.&lt;/P&gt;
&lt;P&gt;The token impersonates my Qlik user, which has full access to the space/app.&lt;/P&gt;
&lt;P&gt;I also tried running the application on a test web server, but the same error occurs. The web server is whitelisted in the OAuth client configuration.&lt;/P&gt;
&lt;P&gt;Please note that a different mashup, which uses the same service to obtain the token through the Qlik-embed framework, works fine on both my laptop and the test web server with the same token.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Nov 2024 13:28:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2492531#M21514</guid>
      <dc:creator>cristian_dalsanto</dc:creator>
      <dc:date>2024-11-13T13:28:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to obtain CSRF token from Qlik Cloud</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2492780#M21518</link>
      <description>&lt;P&gt;When you are setting qlik/api configuration, M2M OAuth token has to be defined as string. Are you using a function as you are doing with qlik-embed?&lt;/P&gt;
&lt;P&gt;To be clear, in below code&amp;nbsp;&lt;EM&gt;getAccessToken &lt;/EM&gt;has to be the token and not the function for retrieving the token&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;const config = {
    authType: "oauth2",
    host: configParams.tenantHostname,
    clientId: configParams.oAuthClientId,
    getAccessToken: 'ejshajeid.......'
  };&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2024 14:53:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2492780#M21518</guid>
      <dc:creator>alex_colombo</dc:creator>
      <dc:date>2024-11-14T14:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to obtain CSRF token from Qlik Cloud</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2492810#M21519</link>
      <description>&lt;P&gt;Correct.&amp;nbsp;&lt;SPAN&gt;I do exactly that&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;This is my backend API. As you can see accessToken is returned from&amp;nbsp;qlikAuth.getAccessToken and that's a string. As I said before I tried 3 different scopes:&amp;nbsp;&lt;SPAN&gt;'user_default,' 'admin_classic,' and 'apps,' but received the same error each time&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;// Get access token (M2M impersonation) for use in front-end by qlik-embed using qlik/api
app.post("/oauth/access-token", async (req, res) =&amp;gt; {
  console.log('Retrieving access token for', req.body.userId + ' ----------------------------');
  const userId = req.body.userId;

  if (userId != undefined &amp;amp;&amp;amp; userId.length &amp;gt; 0) {
    try {
      const accessToken = await qlikAuth.getAccessToken({
        hostConfig: {
          ...config,
          userId,
          scope: "apps",
        },
      });
      console.log("Retrieved access token for: ", userId, 'token', accessToken);
      res.setHeader('Access-Control-Allow-Origin', '*'); 
      res.setHeader('Access-Control-Allow-Methods', 'POST');
      res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
      res.send(accessToken);
    } catch (err) {
      console.log(err);
      res.status(401).send("No access");
    }
  }
});&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;in the frontend I get the token and I use it to open a session:&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;async function getEnigmaSessionAndApp2(userInfo: any, http: HttpClient) {
  const url = `${environment.JWT_PROVIDER}/oauth/access-token`;
  const headers = new HttpHeaders({ 'Content-Type': 'application/json' });
  const body = { 'userId': userInfo.QlikSUb };
  const webToken: string = await firstValueFrom(http.post(url, body, { headers, responseType: 'text' }));

  const hostConfig: any = {
    authType: "oauth2",
    host: environment.QLIK_PARAMETERS.QLIK_URL,
    clientId: environment.QLIK_PARAMETERS.CLIENT_ID,
    getAccessToken: webToken
  }

  auth.setDefaultHostConfig(hostConfig);
  const session = qix.openAppSession({ appId: environment.QLIK_PARAMETERS.QLIK_APPID });
  const app = await session.getDoc();
  return [session, null, app];
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But when I try to open the session I get the error:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cristian_dalsanto_0-1731604374754.png" style="width: 763px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/174378i70F0237A199C9A9C/image-dimensions/763x246?v=v2" width="763" height="246" role="button" title="cristian_dalsanto_0-1731604374754.png" alt="cristian_dalsanto_0-1731604374754.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;In the network section of Chrome I can't see any web socket...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2024 17:19:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2492810#M21519</guid>
      <dc:creator>cristian_dalsanto</dc:creator>
      <dc:date>2024-11-14T17:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to obtain CSRF token from Qlik Cloud</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2492968#M21524</link>
      <description>&lt;P&gt;Ok, your code is working on my end.&lt;/P&gt;
&lt;P&gt;Looking better at the errors in console, those errors are refrring to your qlik-embed code. Are you using qlik-embed somewhere? You told me that you are trying to use qlik/api.&lt;/P&gt;
&lt;P&gt;Seems that you are trying to use qlik-embed with M2M impersonation token and you are defining the function for evaluated &lt;EM&gt;data-get-access-token&lt;/EM&gt; property in the wrong way. Could you please share your code for qlik-embed? Function for setting&amp;nbsp;&lt;EM&gt;data-get-access-token &lt;/EM&gt;has to be set in html head tag, before your script which will create qlik-embed configuration.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2024 14:25:00 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2492968#M21524</guid>
      <dc:creator>alex_colombo</dc:creator>
      <dc:date>2024-11-15T14:25:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to obtain CSRF token from Qlik Cloud</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2493003#M21526</link>
      <description>&lt;P&gt;Sorry, I don't understand. I'm not using Qlik-embed in any module of my application. I used it in another mashup, but this is a new project where I use "Qlik/api" to open the document and Nebula.js to create the visualizations.&lt;/P&gt;
&lt;P&gt;Just to be sure, I double-checked: none of the HTML components contain the Qlik-embed tag, and I haven't imported the framework either.&lt;/P&gt;
&lt;P&gt;The error in the console appears when I execute the following:&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;const&lt;/SPAN&gt; &lt;SPAN&gt;app&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;await&lt;/SPAN&gt; &lt;SPAN&gt;session&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;getDoc&lt;/SPAN&gt;&lt;SPAN&gt;();&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;In the image below I stopped the&amp;nbsp;&lt;/SPAN&gt;execution at openSession step:&lt;/DIV&gt;
&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cristian_dalsanto_2-1731686891102.png" style="width: 767px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/174415iF2DC52E8C173C42A/image-dimensions/767x598?v=v2" width="767" height="598" role="button" title="cristian_dalsanto_2-1731686891102.png" alt="cristian_dalsanto_2-1731686891102.png" /&gt;&lt;/span&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the next step should be the the getDoc, but at this point, I get the error, &lt;SPAN&gt;even though&amp;nbsp;&lt;/SPAN&gt;all the parameters are set correctly:&lt;/P&gt;
&lt;/DIV&gt;
&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cristian_dalsanto_0-1731686759909.png" style="width: 768px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/174413iEC29647BC544F260/image-dimensions/768x593?v=v2" width="768" height="593" role="button" title="cristian_dalsanto_0-1731686759909.png" alt="cristian_dalsanto_0-1731686759909.png" /&gt;&lt;/span&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BR /&gt;
&lt;P&gt;As you can see I got the error and never reached the breakpoint at 273 line.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here, network elements filtered by "qlik". I think qmfe-api are related to "Qlik_api" api&lt;/P&gt;
&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cristian_dalsanto_1-1731686842831.png" style="width: 767px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/174414i6684E5F0552CF94D/image-dimensions/767x598?v=v2" width="767" height="598" role="button" title="cristian_dalsanto_1-1731686842831.png" alt="cristian_dalsanto_1-1731686842831.png" /&gt;&lt;/span&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2024 16:08:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2493003#M21526</guid>
      <dc:creator>cristian_dalsanto</dc:creator>
      <dc:date>2024-11-15T16:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to obtain CSRF token from Qlik Cloud</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2493011#M21527</link>
      <description>&lt;P&gt;Which qlik/api version you are using?&lt;/P&gt;
&lt;P&gt;Anyway. Can't help more than this here. For reproduce the error on my end I need to connect to your tenant and run the code on my end. For this I need tenant url, OAuth client id and client secret for generate token and userId. A&lt;SPAN&gt;lternatively&lt;/SPAN&gt;, you could send me (with private message) a valid M2M OAuth token and then I can test it&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2024 16:20:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2493011#M21527</guid>
      <dc:creator>alex_colombo</dc:creator>
      <dc:date>2024-11-15T16:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to obtain CSRF token from Qlik Cloud</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2504993#M21807</link>
      <description>&lt;P&gt;Peace, &lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/81045"&gt;@cristian_dalsanto&lt;/a&gt; . Ensure you &lt;STRONG&gt;&lt;EM&gt;do&lt;/EM&gt;&lt;/STRONG&gt; use a function for your &lt;STRONG&gt;getAccessToken&lt;/STRONG&gt; in the &lt;STRONG&gt;setDefaultHostConfig. &lt;/STRONG&gt;For example&lt;STRONG&gt;: &lt;/STRONG&gt;&lt;/P&gt;
&lt;DIV style="background-color: #1e1e2e; color: #cdd6f4;"&gt;
&lt;PRE style="font-family: 'JetBrains Mono',monospace; font-size: 9.8pt;"&gt;&lt;SPAN&gt;import { auth, qix } from "@qlik/api";&lt;BR /&gt;&lt;BR /&gt;auth&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;setDefaultHostConfig&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;{&lt;BR /&gt;&lt;/SPAN&gt;    host&lt;SPAN&gt;: import&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;meta&lt;SPAN&gt;.&lt;/SPAN&gt;env&lt;SPAN&gt;.&lt;/SPAN&gt;VITE_SENSE_BASE_URI&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;    authType&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"Oauth2"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;    clientId&lt;SPAN&gt;: import&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;meta&lt;SPAN&gt;.&lt;/SPAN&gt;env&lt;SPAN&gt;.&lt;/SPAN&gt;VITE_OAUTH_CLIENT_ID&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;getAccessToken&lt;/SPAN&gt;&lt;SPAN&gt;: async &lt;/SPAN&gt;&lt;SPAN&gt;() &lt;/SPAN&gt;&lt;SPAN&gt;=&amp;gt; &lt;/SPAN&gt;&lt;SPAN&gt;{&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;// console.log('Bearer token string sent from the backend', token);&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;return &lt;/SPAN&gt;&lt;SPAN&gt;token&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;}&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;BR /&gt;const app = await qix&lt;BR /&gt;.openAppSession({&lt;BR /&gt;appId: appId,&lt;BR /&gt;})&lt;BR /&gt;.getDoc();&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;For further details: &lt;A href="https://lab.pendraco.com/-/snippets/43" target="_blank"&gt;https://lab.pendraco.com/-/snippets/43&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2025 18:34:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/How-to-obtain-CSRF-token-from-Qlik-Cloud/m-p/2504993#M21807</guid>
      <dc:creator>SteveAO</dc:creator>
      <dc:date>2025-02-07T18:34:53Z</dc:date>
    </item>
  </channel>
</rss>

