cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Administration & Architecture
Explore discussions on Databricks administration, deployment strategies, and architectural best practices. Connect with administrators and architects to optimize your Databricks environment for performance, scalability, and security.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Dashboard id is missing in token claim

AjayKumarM
New Contributor II

When I pass multiple filters using "external_value" while embedding the Databricks dashboard, I encounter an error stating that the dashboard ID is missing.

 

For example, passing a single filter works fine, but when I pass multiple filter values (such as "org_id" and "user_id"), the request fails with this error.

 

Could you please clarify:

 

1. Is there a supported way to pass multiple filters through "external_value"?

2. Is there any specific JSON format or configuration required?

3. Are there any limitations when passing multiple external filter values along with the dashboard ID?

 

If possible, could you share a working example of passing multiple filters in an embedded dashboard?

Example:

var externalValue = JsonSerializer.Serialize(new

{

    org_id = "1001",

    user_id = "2001"

});

 

var url = $"{workspaceUrl}/api/2.0/lakeview/dashboards/{dashboardId}/published/tokeninfo";

 

var builder = new UriBuilder(url);

var query = System.Web.HttpUtility.ParseQueryString("");

 

query["external_viewer_id"] = "user_123";

query["external_value"] = externalValue;

 

builder.Query = query.ToString();

 

var response = await httpClient.GetAsync(builder.Uri);

2 ACCEPTED SOLUTIONS

Accepted Solutions

Isaac_18
Contributor

Hi @AjayKumarM, adding to what @data_pulse found. Since /tokeninfo accepts the JSON fine, I'd look at the next call, where you swap the response for the scoped token. That's usually where a JSON-shaped value goes wrong.

In the documented flow, step 3 takes everything /tokeninfo returns, turns authorization_details back into a JSON string, adds grant_type=client_credentials, and posts all of it form-encoded to /oidc/v1/token. The custom_claim field in that response holds the dashboard ID together with your external values. If that field gets changed on the way (re-serialized, split on a comma or &, or posted without URL encoding), the scoped token ends up without the dashboard ID, and that's the error you're seeing. A plain value like 1001 survives sloppy handling. A JSON object full of quotes, colons and commas usually doesn't.

In C#, the safest way is to let FormUrlEncodedContent encode the body and pass the fields through untouched:

using var tokenInfoDoc = JsonDocument.Parse(await tokenInfoResponse.Content.ReadAsStringAsync());
var form = new List<KeyValuePair<string, string>>
{
    new("grant_type", "client_credentials")
};

foreach (var prop in tokenInfoDoc.RootElement.EnumerateObject())
{
    // authorization_details must go back as a JSON string; everything else as-is
    var value = prop.Name == "authorization_details"
        ? prop.Value.GetRawText()
        : (prop.Value.ValueKind == JsonValueKind.String ? prop.Value.GetString()! : prop.Value.GetRawText());
    form.Add(new(prop.Name, value));
}

var req = new HttpRequestMessage(HttpMethod.Post, $"{workspaceUrl}/oidc/v1/token?o={workspaceId}")
{
    Content = new FormUrlEncodedContent(form)
};
req.Headers.Authorization = new AuthenticationHeaderValue("Basic", basicAuth);
var scoped = await httpClient.SendAsync(req);

Don't build the body by joining strings, and don't parse and rebuild custom_claim yourself.

On your three questions:

  1. external_value is one string, not a set of filters. You can still pack several values into it.
  2. There's no special schema. Whatever string you send shows up in SQL as __aibi_external_value. If you send JSON, you can read it in the dataset like this:
SELECT *
FROM sales
WHERE org_id  = get_json_object(__aibi_external_value, '$.org_id')
  AND user_id = get_json_object(__aibi_external_value, '$.user_id')

If you'd rather keep it simple, send a delimited string like 1001|2001 and use split_part(__aibi_external_value, '|', 1) and split_part(__aibi_external_value, '|', 2). 3. external_viewer_id and external_value together can't be more than 1 KB. Also keep personal data out of external_viewer_id, since that one ends up in the audit logs.

If it still fails after that change, could you say whether the error comes back from /oidc/v1/token or later when the dashboard renders? And try the delimited string version once. If that works and the JSON doesn't, it's the encoding for sure.

Docs: https://docs.databricks.com/aws/en/dashboards/share/embedding/external-embed

View solution in original post

Thank you so much this solution now it works with comma separated.

View solution in original post

3 REPLIES 3

data_pulse
Contributor

Hi @AjayKumarM 

I ran a few checks against a published dashboard using both the Databricks CLI and REST API. Here are my observations on your questions.

1. external_value is documented as a single string parameter, rather than a collection of dashboard filter parameters.

I tested single values, comma-separated values, colon-separated values, JSON arrays and a JSON object. All /published/tokeninfo requests succeeded.

For multiple region values, one possible approach is to pass a comma-separated string and interpret it in the dashboard dataset SQL:

WHERE array_contains(split(__aibi_external_value, ','), region)

This is a suggested approach and any access restrictions should be based on authenticated viewer entitlements.

2. The documentation doesn't specify a special multi-filter JSON schema for external_value.

I also tested a JSON object containing org_id and user_id. The token-info API accepted it, and the returned custom_claim preserved the input and expected dashboard UUID.

However, I couldn't validate the complete scoped OAuth and browser-rendering flow.

3.The documented combined size limit for external_value and external_viewer_id  is 1 KB.

I couldn't reproduce the dashboard ID error at the /published/tokeninfo stage. It would be worth checking whether the error occurs during scoped-token generation (/oidc/v1/token) or dashboard rendering and whether the returned custom_claim is forwarded unchanged.

Could you share which step fails and any error details? Happy to help investigate further.

Thank you so much this solution now it works with comma separated.

Isaac_18
Contributor

Hi @AjayKumarM, adding to what @data_pulse found. Since /tokeninfo accepts the JSON fine, I'd look at the next call, where you swap the response for the scoped token. That's usually where a JSON-shaped value goes wrong.

In the documented flow, step 3 takes everything /tokeninfo returns, turns authorization_details back into a JSON string, adds grant_type=client_credentials, and posts all of it form-encoded to /oidc/v1/token. The custom_claim field in that response holds the dashboard ID together with your external values. If that field gets changed on the way (re-serialized, split on a comma or &, or posted without URL encoding), the scoped token ends up without the dashboard ID, and that's the error you're seeing. A plain value like 1001 survives sloppy handling. A JSON object full of quotes, colons and commas usually doesn't.

In C#, the safest way is to let FormUrlEncodedContent encode the body and pass the fields through untouched:

using var tokenInfoDoc = JsonDocument.Parse(await tokenInfoResponse.Content.ReadAsStringAsync());
var form = new List<KeyValuePair<string, string>>
{
    new("grant_type", "client_credentials")
};

foreach (var prop in tokenInfoDoc.RootElement.EnumerateObject())
{
    // authorization_details must go back as a JSON string; everything else as-is
    var value = prop.Name == "authorization_details"
        ? prop.Value.GetRawText()
        : (prop.Value.ValueKind == JsonValueKind.String ? prop.Value.GetString()! : prop.Value.GetRawText());
    form.Add(new(prop.Name, value));
}

var req = new HttpRequestMessage(HttpMethod.Post, $"{workspaceUrl}/oidc/v1/token?o={workspaceId}")
{
    Content = new FormUrlEncodedContent(form)
};
req.Headers.Authorization = new AuthenticationHeaderValue("Basic", basicAuth);
var scoped = await httpClient.SendAsync(req);

Don't build the body by joining strings, and don't parse and rebuild custom_claim yourself.

On your three questions:

  1. external_value is one string, not a set of filters. You can still pack several values into it.
  2. There's no special schema. Whatever string you send shows up in SQL as __aibi_external_value. If you send JSON, you can read it in the dataset like this:
SELECT *
FROM sales
WHERE org_id  = get_json_object(__aibi_external_value, '$.org_id')
  AND user_id = get_json_object(__aibi_external_value, '$.user_id')

If you'd rather keep it simple, send a delimited string like 1001|2001 and use split_part(__aibi_external_value, '|', 1) and split_part(__aibi_external_value, '|', 2). 3. external_viewer_id and external_value together can't be more than 1 KB. Also keep personal data out of external_viewer_id, since that one ends up in the audit logs.

If it still fails after that change, could you say whether the error comes back from /oidc/v1/token or later when the dashboard renders? And try the delimited string version once. If that works and the JSON doesn't, it's the encoding for sure.

Docs: https://docs.databricks.com/aws/en/dashboards/share/embedding/external-embed