Need Help- Passing customer ID to metabse Dashboard in Drupal


#1

Hello,
I have a Drupal website that is integrated with Microsoft Active Directory.
Also, I have created a metabase dashboard and embedded it in the Drupal website where it doesn’t display any data unless a customer ID is passed to it.
My challenge is how can I pass the customer ID to the embedded filtered dashboard once the customer logs in with Microsoft AD credentials to display just the data for that specific customer?

I would really appreciate you help

Thank you in advance


#2

You embed the dashboard in an iframe and pass the id as a parameter.


#3

Thanks Andrew for you response,
I still son’t know how to do it if you can help further.
I have a drupal website integrated with Active Directory server. once the user logs in with the AD credintials, I would like to use the login customer ID to pass it to my embedded filtered metabse dashboard. I saw that I have to use nodes.js but not quite sure.
it would be great if you can advice here


#4

Sounds like you are already far with having the concepts - so it’s only missing what @AndrewMBaines mention. The magic sauce in the this final part is that you have to have the ID parameter to be locked so that it requires to be signed with a jwt token in your Drupal embedding code. Refer to the official docs pointed to on the Wiki I mention below.

No need to use node.js you can do it with PHP code as well. If you search https://discourse.metabase.com there are plenty of examples of embedding - here’s a wiki collecting various pointers (contributions on that page are welcome BTW :slight_smile:): WIKI: SDK (covers API, embedding etc?)

Here’s another fairly recent updated thread regarding PHP embedding with SECRET (HOW TO?) related to Wordpress, not Drupal though.


#5

Thank you ornh,
I saw the thread, I have installed composer require lcobucci/jwt
but where should I add the following code within my app?

$metabaseSiteUrl = ‘http://your-metabase-installation.com’;
$metabaseSecretKey = ‘YOUR_SECRET_KEY’;

    $signer = new \Lcobucci\JWT\Signer\Hmac\Sha256();
    $token = (new \Lcobucci\JWT\Builder())
        ->set('resource', ['dashboard' => 1])
        ->set('params', ['your_custom_param' => 0])
        ->sign($signer, $metabaseSecretKey)
        ->getToken();

    $iframeUrl = "$metabaseSiteUrl/embed/dashboard/$token#bordered=true&titled=true";

#6

Sorry, I’ve got no Drupal experience. So apart from a https://www.drupal.org/developers and a https://www.drupal.org/docs/8/creating-custom-modules link — where I see there’s a guide for building a “Hello, World” module — I can’t really help.

Maybe someone else here will, but your chances are probably better in a Drupal forum.

Would be great though if you can share a bit back here of what you learn.


Embedding Filtered Dashboard