Henara.MetabaseEmbed.Client 1.1.0
Henara.MetabaseEmbed.Client
Client for the Henara Metabase token service (gRPC). Exchanges the user's Keycloak access token for Metabase embed tokens and lists the dashboards the user may embed.
Setup
Sign-in is up to the host. Register the client; the options are bound from the host's IConfiguration, which reads the
environment variables:
services.AddMetabaseEmbed(configuration);
The Keycloak access token reaches the client in one of two ways:
- Pass it to each call:
GetAccessibleDashboardsAsync(accessToken),GetEmbedTokenAsync(accessToken, databaseId, type), or theAccessTokenparameter of the dashboard components. Nothing else needs to be registered. - Or register an
IKeycloakAccessTokenProviderand call the overloads without a token:
public sealed class KeycloakAccessTokenProvider : IKeycloakAccessTokenProvider
{
private readonly MyTokenStore _tokens;
public KeycloakAccessTokenProvider(MyTokenStore tokens) => _tokens = tokens;
public Task<string?> GetAccessTokenAsync(CancellationToken ct = default) => _tokens.GetAccessTokenAsync(ct);
}
services.AddSingleton<IKeycloakAccessTokenProvider, KeycloakAccessTokenProvider>();
A passed token is used even when a provider is registered.
| Variable | Description |
|---|---|
METABASE_EMBED_GRPC_ADDRESS |
Token service address |
METABASE_EMBED_TIMEOUT_SECONDS |
Deadline of each call in seconds |
METABASE_INSTANCE_URL |
Browser-facing Metabase base URL |
All are required. AddMetabaseEmbed validates them immediately and throws OptionsValidationException when one is missing or invalid, in any host (ASP.NET Core, MAUI, WPF, Windows Forms).
The optional second argument changes the options after binding, before validation:
services.AddMetabaseEmbed(configuration, options =>
options.CreateHttpHandler = () => new GrpcWebHandler(GrpcWebMode.GrpcWeb, new HttpClientHandler()));
CreateHttpHandler sets the HTTP handler of the token service channel.
Register an IGrpcAddressProvider before AddMetabaseEmbed to resolve the address at runtime.
Usage
Inject IMetabaseTokenProvider:
var dashboards = await tokenProvider.GetAccessibleDashboardsAsync(accessToken);
var token = await tokenProvider.GetEmbedTokenAsync(accessToken, databaseId, DashboardType.MeinePraxis);
With a registered IKeycloakAccessTokenProvider, omit accessToken.
Errors
Failures throw MetabaseTokenServiceException with the server's message and a Reason:
| Reason | Cause |
|---|---|
NotAuthenticated |
No or an invalid Keycloak access token |
PermissionDenied |
The user may not access the dashboard or database |
InvalidRequest |
The request was rejected as invalid |
NotConfigured |
The token service is missing configuration |
Unavailable |
The token service could not be reached |
Timeout |
The call exceeded the configured timeout |
Unknown |
Any other failure |
Cancelling the CancellationToken throws OperationCanceledException.
Showing the top 20 packages that depend on Henara.MetabaseEmbed.Client.
| Packages | Downloads |
|---|---|
|
Henara.MetabaseEmbed.Core
The MetabaseDashboard component the Henara Metabase dashboard components render.
|
9 |
|
Henara.MetabaseEmbed.Core
The MetabaseDashboard component the Henara Metabase dashboard components render.
|
5 |
.NET 10.0
- Google.Protobuf (>= 3.36.2)
- Grpc.Net.Client (>= 2.84.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.14)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.14)
- Microsoft.Extensions.Options (>= 10.0.14)