Skip to content
DocsTry Aspire
DocsTry

KeycloakResourceBuilderExtensions Methods

ClassMethods9 members
Provides extension methods for adding Keycloak resources to an Hosting.IDistributedApplicationBuilder.
AddKeycloak(IDistributedApplicationBuilder, string, int?, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>)Section titled AddKeycloak(IDistributedApplicationBuilder, string, int?, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<KeycloakResource>
Adds a Keycloak container to the application model.
public static class KeycloakResourceBuilderExtensions
{
public static IResourceBuilder<KeycloakResource> AddKeycloak(
this IDistributedApplicationBuilder builder,
string name,
int? port = null,
IResourceBuilder<ParameterResource>? adminUsername = null,
IResourceBuilder<ParameterResource>? adminPassword = null)
{
// ...
}
}
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder.
namestringThe name of the resource.
portint?optionalThe host port that the underlying container is bound to when running locally.
adminUsernameIResourceBuilder<ParameterResource>optionalThe parameter used as the admin for the Keycloak resource. If null a default value will be used.
adminPasswordIResourceBuilder<ParameterResource>optionalThe parameter used as the admin password for the Keycloak resource. If null a default password will be used.
IResourceBuilder<KeycloakResource>A reference to the ApplicationModel.IResourceBuilder`1.
The container exposes port 8080 by default. This version of the package defaults to the tag of the / container image. Use in application host
var keycloak = builder.AddKeycloak("keycloak");
var myService = builder.AddProject<Projects.MyService<()
.WithReference(keycloak);
WithDataBindMount(IResourceBuilder<KeycloakResource>, string)Section titled WithDataBindMount(IResourceBuilder<KeycloakResource>, string)extensionIResourceBuilder<KeycloakResource>
Adds a bind mount for the data folder to a Keycloak container resource.
public static class KeycloakResourceBuilderExtensions
{
public static IResourceBuilder<KeycloakResource> WithDataBindMount(
this IResourceBuilder<KeycloakResource> builder,
string source)
{
// ...
}
}
builderIResourceBuilder<KeycloakResource>The resource builder.
sourcestringThe source directory on the host to mount into the container.
IResourceBuilder<KeycloakResource>The ApplicationModel.IResourceBuilder`1.
The source directory is mounted at /opt/keycloak/data in the container. Use a bind mount
var keycloak = builder.AddKeycloak("keycloak")
.WithDataBindMount("mydata");
WithDataVolume(IResourceBuilder<KeycloakResource>, string?)Section titled WithDataVolume(IResourceBuilder<KeycloakResource>, string?)extensionIResourceBuilder<KeycloakResource>
Adds a named volume for the data folder to a Keycloak container resource.
public static class KeycloakResourceBuilderExtensions
{
public static IResourceBuilder<KeycloakResource> WithDataVolume(
this IResourceBuilder<KeycloakResource> builder,
string? name = null)
{
// ...
}
}
builderIResourceBuilder<KeycloakResource>The resource builder.
namestring?optionalThe name of the volume. Defaults to an auto-generated name based on the application and resource names.
IResourceBuilder<KeycloakResource>The ApplicationModel.IResourceBuilder`1.
The volume is mounted at /opt/keycloak/data in the container. Use a data volume
var keycloak = builder.AddKeycloak("keycloak")
.WithDataVolume();
WithDisabledFeatures(IResourceBuilder<KeycloakResource>, string[])Section titled WithDisabledFeatures(IResourceBuilder<KeycloakResource>, string[])extensionIResourceBuilder<KeycloakResource>
Additional feature names to disable for the keycloak resource
public static class KeycloakResourceBuilderExtensions
{
public static IResourceBuilder<KeycloakResource> WithDisabledFeatures(
this IResourceBuilder<KeycloakResource> builder,
params string[] features)
{
// ...
}
}
builderIResourceBuilder<KeycloakResource>The resource builder.
featuresstring[]Names of features to disable for the keycloak resource
IResourceBuilder<KeycloakResource>The ApplicationModel.IResourceBuilder`1.
WithEnabledFeatures(IResourceBuilder<KeycloakResource>, string[])Section titled WithEnabledFeatures(IResourceBuilder<KeycloakResource>, string[])extensionIResourceBuilder<KeycloakResource>
Additional feature names to enable for the keycloak resource
public static class KeycloakResourceBuilderExtensions
{
public static IResourceBuilder<KeycloakResource> WithEnabledFeatures(
this IResourceBuilder<KeycloakResource> builder,
params string[] features)
{
// ...
}
}
builderIResourceBuilder<KeycloakResource>The resource builder.
featuresstring[]Names of features to enable for the keycloak resource
IResourceBuilder<KeycloakResource>The ApplicationModel.IResourceBuilder`1.
WithOtlpExporter(IResourceBuilder<KeycloakResource>)Section titled WithOtlpExporter(IResourceBuilder<KeycloakResource>)extensionIResourceBuilder<KeycloakResource>
Injects the appropriate environment variables to allow the resource to enable sending telemetry to the dashboard.
  1. It ensures the "opentelemetry" Keycloak feature is enabled
  2. It sets the OTLP endpoint to the value of the ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL environment variable.
  3. It sets the service name and instance id to the resource name and UID. Values are injected by the orchestrator.
  4. It sets a small batch schedule delay in development. This reduces the delay that OTLP exporter waits to sends telemetry and makes the dashboard telemetry pages responsive.
public static class KeycloakResourceBuilderExtensions
{
public static IResourceBuilder<KeycloakResource> WithOtlpExporter(
this IResourceBuilder<KeycloakResource> builder)
{
// ...
}
}
builderIResourceBuilder<KeycloakResource>The keycloak resource builder.
IResourceBuilder<KeycloakResource>The ApplicationModel.IResourceBuilder`1.
WithOtlpExporter(IResourceBuilder<KeycloakResource>, OtlpProtocol)Section titled WithOtlpExporter(IResourceBuilder<KeycloakResource>, OtlpProtocol)extensionIResourceBuilder<KeycloakResource>
Injects the appropriate environment variables to allow the resource to enable sending telemetry to the dashboard.
  1. It ensures the "opentelemetry" Keycloak feature is enabled
  2. It sets the OTLP endpoint to the value of the ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL environment variable.
  3. It sets the service name and instance id to the resource name and UID. Values are injected by the orchestrator.
  4. It sets a small batch schedule delay in development. This reduces the delay that OTLP exporter waits to sends telemetry and makes the dashboard telemetry pages responsive.
public static class KeycloakResourceBuilderExtensions
{
public static IResourceBuilder<KeycloakResource> WithOtlpExporter(
this IResourceBuilder<KeycloakResource> builder,
OtlpProtocol protocol)
{
// ...
}
}
builderIResourceBuilder<KeycloakResource>The keycloak resource builder.
protocolOtlpProtocolThe protocol to use for the OTLP exporter. If not set, it will try gRPC then Http.
IResourceBuilder<KeycloakResource>The ApplicationModel.IResourceBuilder`1.
WithRealmImport(IResourceBuilder<KeycloakResource>, string, bool)Section titled WithRealmImport(IResourceBuilder<KeycloakResource>, string, bool)extensionIResourceBuilder<KeycloakResource>
Adds a realm import to a Keycloak container resource.
public static class KeycloakResourceBuilderExtensions
{
public static IResourceBuilder<KeycloakResource> WithRealmImport(
this IResourceBuilder<KeycloakResource> builder,
string import,
bool isReadOnly)
{
// ...
}
}
builderIResourceBuilder<KeycloakResource>The resource builder.
importstringThe directory containing the realm import files or a single import file.
isReadOnlyboolA flag that indicates if the realm import directory is read-only.
IResourceBuilder<KeycloakResource>The ApplicationModel.IResourceBuilder`1.
The realm import files are copied to /opt/keycloak/data/import in the container. Import the realms from a directory
var keycloak = builder.AddKeycloak("keycloak")
.WithRealmImport("../realms");
WithRealmImport(IResourceBuilder<KeycloakResource>, string)Section titled WithRealmImport(IResourceBuilder<KeycloakResource>, string)extensionIResourceBuilder<KeycloakResource>
Adds a realm import to a Keycloak container resource.
public static class KeycloakResourceBuilderExtensions
{
public static IResourceBuilder<KeycloakResource> WithRealmImport(
this IResourceBuilder<KeycloakResource> builder,
string import)
{
// ...
}
}
builderIResourceBuilder<KeycloakResource>The resource builder.
importstringThe directory containing the realm import files or a single import file.
IResourceBuilder<KeycloakResource>The ApplicationModel.IResourceBuilder`1.
The realm import files are copied to /opt/keycloak/data/import in the container. Import the realms from a directory
var keycloak = builder.AddKeycloak("keycloak")
.WithRealmImport("../realms");