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) { // ... }}Parameters
builderIDistributedApplicationBuilder The Hosting.IDistributedApplicationBuilder .namestringThe name of the resource. portint?optionalThe host port that the underlying container is bound to when running locally.adminUsername IResourceBuilder<ParameterResource> optionalThe parameter used as the admin for the Keycloak resource. If null a default value will be used.adminPassword IResourceBuilder<ParameterResource> optionalThe parameter used as the admin password for the Keycloak resource. If null a default password will be used.Returns
IResourceBuilder<KeycloakResource> A reference to the ApplicationModel.IResourceBuilder`1 .Remarks
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.AddDotnetProject( "myservice", "../MyService/MyService.csproj") .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) { // ... }}Parameters
builderIResourceBuilder<KeycloakResource> The resource builder.sourcestringThe source directory on the host to mount into the container.Returns
IResourceBuilder<KeycloakResource> The ApplicationModel.IResourceBuilder`1 .Remarks
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) { // ... }}Parameters
builderIResourceBuilder<KeycloakResource> The resource builder.namestring?optionalThe name of the volume. Defaults to an auto-generated name based on the application and resource names.Returns
IResourceBuilder<KeycloakResource> The ApplicationModel.IResourceBuilder`1 .Remarks
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) { // ... }}Parameters
builderIResourceBuilder<KeycloakResource> The resource builder.featuresstring[]Names of features to disable for the keycloak resourceReturns
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) { // ... }}Parameters
builderIResourceBuilder<KeycloakResource> The resource builder.featuresstring[]Names of features to enable for the keycloak resourceReturns
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.
- It ensures the "opentelemetry" Keycloak feature is enabled
- It sets the OTLP endpoint to the value of the
ASPIRE_environment variable.DASHBOARD_ OTLP_ ENDPOINT_ URL - It sets the service name and instance id to the resource name and UID. Values are injected by the orchestrator.
- 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) { // ... }}Parameters
builderIResourceBuilder<KeycloakResource> The keycloak resource builder.Returns
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.
- It ensures the "opentelemetry" Keycloak feature is enabled
- It sets the OTLP endpoint to the value of the
ASPIRE_environment variable.DASHBOARD_ OTLP_ ENDPOINT_ URL - It sets the service name and instance id to the resource name and UID. Values are injected by the orchestrator.
- 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) { // ... }}Parameters
builderIResourceBuilder<KeycloakResource> The keycloak resource builder.protocolOtlpProtocol The protocol to use for the OTLP exporter. If not set, it will try gRPC then Http.Returns
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) { // ... }}Parameters
builderIResourceBuilder<KeycloakResource> The resource builder.importstringThe directory containing the realm import files or a single import file.isReadOnly boolA flag that indicates if the realm import directory is read-only.Returns
IResourceBuilder<KeycloakResource> The ApplicationModel.IResourceBuilder`1 .Remarks
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) { // ... }}Parameters
builderIResourceBuilder<KeycloakResource> The resource builder.importstringThe directory containing the realm import files or a single import file.Returns
IResourceBuilder<KeycloakResource> The ApplicationModel.IResourceBuilder`1 .Remarks
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");