GitHub user dosubot[bot] added a comment to the discussion: Passing 
authenticated user into Superset iFrame with Keycloak

<!-- Answer -->
To pass the authentication state into the iframe, you can append the Keycloak 
token to the iframe's URL as a query parameter. Here's a Svelte snippet to 
achieve this:

```svelte
<script>
  import { onMount } from 'svelte';
  import Keycloak from 'keycloak-js';

  let iframeSrc = '';

  const keycloak = new Keycloak({
    url: KEYCLOAK_CONFIG['auth-server-url'],
    realm: KEYCLOAK_CONFIG.realm,
    clientId: KEYCLOAK_CONFIG.resource
  });

  onMount(() => {
    keycloak.init({
      onLoad: 'check-sso',
      pkceMethod: 'S256',
      checkLoginIframe: false
    }).then(authenticated => {
      if (authenticated) {
        console.log('User authenticated via Keycloak.');
        // Get the token
        const token = keycloak.token;
        // Set the iframe source with the token as a query parameter
        iframeSrc = `${env.SUPERSET_FRONTEND_URL}/?token=${token}`;
      } else {
        keycloak.login();
      }
    });
  });
</script>

<iframe src={iframeSrc} width="100%" height="600px"></iframe>
```

This snippet initializes Keycloak, checks if the user is authenticated, and if 
so, appends the Keycloak token to the iframe's URL. Ensure your Superset 
instance is configured to accept and validate this token for seamless 
authentication.


<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*

---
<sup>Help Dosu learn! Give it feedback: [Great 
Response](https://app.dosu.dev/response-feedback/930dbc5f-2850-465c-a6a0-6275e7c4910d?feedback_type=great_response)
 | [Irrelevant 
Answer](https://app.dosu.dev/response-feedback/930dbc5f-2850-465c-a6a0-6275e7c4910d?feedback_type=irrelevant_answer)
 | [Incorrect 
Sources](https://app.dosu.dev/response-feedback/930dbc5f-2850-465c-a6a0-6275e7c4910d?feedback_type=incorrect_sources)
 | [Too 
Verbose](https://app.dosu.dev/response-feedback/930dbc5f-2850-465c-a6a0-6275e7c4910d?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/930dbc5f-2850-465c-a6a0-6275e7c4910d?feedback_type=hallucination)
 | [Bug 
Report](https://app.dosu.dev/response-feedback/930dbc5f-2850-465c-a6a0-6275e7c4910d?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/930dbc5f-2850-465c-a6a0-6275e7c4910d?feedback_type=other)</sup>


GitHub link: 
https://github.com/apache/superset/discussions/33151#discussioncomment-12856629

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to