keycloak.UserTemplateImporterIdentityProviderMapper

Allows for creating and managing an username template importer identity provider mapper within Keycloak.

The username template importer mapper can be used to map externally defined OIDC claims or SAML attributes with a template to the username of the imported Keycloak user:

  • Substitutions are enclosed in ${}. For example: ‘${ALIAS}.${CLAIM.sub}’. ALIAS is the provider alias. CLAIM.<NAME> references an ID or Access token claim.

If you are using Keycloak 10 or higher, you will need to specify the extra_config argument in order to define a syncMode for the mapper.

Example Usage

using System.Collections.Generic;
using Pulumi;
using Keycloak = Pulumi.Keycloak;

return await Deployment.RunAsync(() => 
{
    var realm = new Keycloak.Realm("realm", new()
    {
        RealmName = "my-realm",
        Enabled = true,
    });

    var oidc = new Keycloak.Oidc.IdentityProvider("oidc", new()
    {
        Realm = realm.Id,
        Alias = "oidc",
        AuthorizationUrl = "https://example.com/auth",
        TokenUrl = "https://example.com/token",
        ClientId = "example_id",
        ClientSecret = "example_token",
        DefaultScopes = "openid random profile",
    });

    var usernameImporter = new Keycloak.UserTemplateImporterIdentityProviderMapper("usernameImporter", new()
    {
        Realm = realm.Id,
        IdentityProviderAlias = oidc.Alias,
        Template = "${ALIAS}.${CLAIM.email}",
        ExtraConfig = 
        {
            { "syncMode", "INHERIT" },
        },
    });

});
package main

import (
	"github.com/pulumi/pulumi-keycloak/sdk/v5/go/keycloak"
	"github.com/pulumi/pulumi-keycloak/sdk/v5/go/keycloak/oidc"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		realm, err := keycloak.NewRealm(ctx, "realm", &keycloak.RealmArgs{
			Realm:   pulumi.String("my-realm"),
			Enabled: pulumi.Bool(true),
		})
		if err != nil {
			return err
		}
		oidc, err := oidc.NewIdentityProvider(ctx, "oidc", &oidc.IdentityProviderArgs{
			Realm:            realm.ID(),
			Alias:            pulumi.String("oidc"),
			AuthorizationUrl: pulumi.String("https://example.com/auth"),
			TokenUrl:         pulumi.String("https://example.com/token"),
			ClientId:         pulumi.String("example_id"),
			ClientSecret:     pulumi.String("example_token"),
			DefaultScopes:    pulumi.String("openid random profile"),
		})
		if err != nil {
			return err
		}
		_, err = keycloak.NewUserTemplateImporterIdentityProviderMapper(ctx, "usernameImporter", &keycloak.UserTemplateImporterIdentityProviderMapperArgs{
			Realm:                 realm.ID(),
			IdentityProviderAlias: oidc.Alias,
			Template:              pulumi.String("${ALIAS}.${CLAIM.email}"),
			ExtraConfig: pulumi.AnyMap{
				"syncMode": pulumi.Any("INHERIT"),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.keycloak.Realm;
import com.pulumi.keycloak.RealmArgs;
import com.pulumi.keycloak.oidc.IdentityProvider;
import com.pulumi.keycloak.oidc.IdentityProviderArgs;
import com.pulumi.keycloak.UserTemplateImporterIdentityProviderMapper;
import com.pulumi.keycloak.UserTemplateImporterIdentityProviderMapperArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var realm = new Realm("realm", RealmArgs.builder()        
            .realm("my-realm")
            .enabled(true)
            .build());

        var oidc = new IdentityProvider("oidc", IdentityProviderArgs.builder()        
            .realm(realm.id())
            .alias("oidc")
            .authorizationUrl("https://example.com/auth")
            .tokenUrl("https://example.com/token")
            .clientId("example_id")
            .clientSecret("example_token")
            .defaultScopes("openid random profile")
            .build());

        var usernameImporter = new UserTemplateImporterIdentityProviderMapper("usernameImporter", UserTemplateImporterIdentityProviderMapperArgs.builder()        
            .realm(realm.id())
            .identityProviderAlias(oidc.alias())
            .template("${ALIAS}.${CLAIM.email}")
            .extraConfig(Map.of("syncMode", "INHERIT"))
            .build());

    }
}
import pulumi
import pulumi_keycloak as keycloak

realm = keycloak.Realm("realm",
    realm="my-realm",
    enabled=True)
oidc = keycloak.oidc.IdentityProvider("oidc",
    realm=realm.id,
    alias="oidc",
    authorization_url="https://example.com/auth",
    token_url="https://example.com/token",
    client_id="example_id",
    client_secret="example_token",
    default_scopes="openid random profile")
username_importer = keycloak.UserTemplateImporterIdentityProviderMapper("usernameImporter",
    realm=realm.id,
    identity_provider_alias=oidc.alias,
    template="${ALIAS}.${CLAIM.email}",
    extra_config={
        "syncMode": "INHERIT",
    })
import * as pulumi from "@pulumi/pulumi";
import * as keycloak from "@pulumi/keycloak";

const realm = new keycloak.Realm("realm", {
    realm: "my-realm",
    enabled: true,
});
const oidc = new keycloak.oidc.IdentityProvider("oidc", {
    realm: realm.id,
    alias: "oidc",
    authorizationUrl: "https://example.com/auth",
    tokenUrl: "https://example.com/token",
    clientId: "example_id",
    clientSecret: "example_token",
    defaultScopes: "openid random profile",
});
const usernameImporter = new keycloak.UserTemplateImporterIdentityProviderMapper("usernameImporter", {
    realm: realm.id,
    identityProviderAlias: oidc.alias,
    template: "${ALIAS}.${CLAIM.email}",
    extraConfig: {
        syncMode: "INHERIT",
    },
});
resources:
  realm:
    type: keycloak:Realm
    properties:
      realm: my-realm
      enabled: true
  oidc:
    type: keycloak:oidc:IdentityProvider
    properties:
      realm: ${realm.id}
      alias: oidc
      authorizationUrl: https://example.com/auth
      tokenUrl: https://example.com/token
      clientId: example_id
      clientSecret: example_token
      defaultScopes: openid random profile
  usernameImporter:
    type: keycloak:UserTemplateImporterIdentityProviderMapper
    properties:
      realm: ${realm.id}
      identityProviderAlias: ${oidc.alias}
      template: ${ALIAS}.${CLAIM.email}
      # extra_config with syncMode is required in Keycloak 10+
      extraConfig:
        syncMode: INHERIT

Create UserTemplateImporterIdentityProviderMapper Resource

new UserTemplateImporterIdentityProviderMapper(name: string, args: UserTemplateImporterIdentityProviderMapperArgs, opts?: CustomResourceOptions);
@overload
def UserTemplateImporterIdentityProviderMapper(resource_name: str,
                                               opts: Optional[ResourceOptions] = None,
                                               extra_config: Optional[Mapping[str, Any]] = None,
                                               identity_provider_alias: Optional[str] = None,
                                               name: Optional[str] = None,
                                               realm: Optional[str] = None,
                                               template: Optional[str] = None)
@overload
def UserTemplateImporterIdentityProviderMapper(resource_name: str,
                                               args: UserTemplateImporterIdentityProviderMapperArgs,
                                               opts: Optional[ResourceOptions] = None)
func NewUserTemplateImporterIdentityProviderMapper(ctx *Context, name string, args UserTemplateImporterIdentityProviderMapperArgs, opts ...ResourceOption) (*UserTemplateImporterIdentityProviderMapper, error)
public UserTemplateImporterIdentityProviderMapper(string name, UserTemplateImporterIdentityProviderMapperArgs args, CustomResourceOptions? opts = null)
public UserTemplateImporterIdentityProviderMapper(String name, UserTemplateImporterIdentityProviderMapperArgs args)
public UserTemplateImporterIdentityProviderMapper(String name, UserTemplateImporterIdentityProviderMapperArgs args, CustomResourceOptions options)
type: keycloak:UserTemplateImporterIdentityProviderMapper
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

name string
The unique name of the resource.
args UserTemplateImporterIdentityProviderMapperArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
args UserTemplateImporterIdentityProviderMapperArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args UserTemplateImporterIdentityProviderMapperArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args UserTemplateImporterIdentityProviderMapperArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name String
The unique name of the resource.
args UserTemplateImporterIdentityProviderMapperArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

UserTemplateImporterIdentityProviderMapper Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

The UserTemplateImporterIdentityProviderMapper resource accepts the following input properties:

IdentityProviderAlias string

The alias of the associated identity provider.

Realm string

The name of the realm.

ExtraConfig Dictionary<string, object>

Key/value attributes to add to the identity provider mapper model that is persisted to Keycloak. This can be used to extend the base model with new Keycloak features.

Name string

The name of the mapper.

Template string

Template to use to format the username to import. Substitutions are enclosed in ${}. For example: '$${ALIAS}.$${CLAIM.sub}'. ALIAS is the provider alias. CLAIM.<NAME> references an ID or Access token claim.

IdentityProviderAlias string

The alias of the associated identity provider.

Realm string

The name of the realm.

ExtraConfig map[string]interface{}

Key/value attributes to add to the identity provider mapper model that is persisted to Keycloak. This can be used to extend the base model with new Keycloak features.

Name string

The name of the mapper.

Template string

Template to use to format the username to import. Substitutions are enclosed in ${}. For example: '$${ALIAS}.$${CLAIM.sub}'. ALIAS is the provider alias. CLAIM.<NAME> references an ID or Access token claim.

identityProviderAlias String

The alias of the associated identity provider.

realm String

The name of the realm.

extraConfig Map<String,Object>

Key/value attributes to add to the identity provider mapper model that is persisted to Keycloak. This can be used to extend the base model with new Keycloak features.

name String

The name of the mapper.

template String

Template to use to format the username to import. Substitutions are enclosed in ${}. For example: '$${ALIAS}.$${CLAIM.sub}'. ALIAS is the provider alias. CLAIM.<NAME> references an ID or Access token claim.

identityProviderAlias string

The alias of the associated identity provider.

realm string

The name of the realm.

extraConfig {[key: string]: any}

Key/value attributes to add to the identity provider mapper model that is persisted to Keycloak. This can be used to extend the base model with new Keycloak features.

name string

The name of the mapper.

template string

Template to use to format the username to import. Substitutions are enclosed in ${}. For example: '$${ALIAS}.$${CLAIM.sub}'. ALIAS is the provider alias. CLAIM.<NAME> references an ID or Access token claim.

identity_provider_alias str

The alias of the associated identity provider.

realm str

The name of the realm.

extra_config Mapping[str, Any]

Key/value attributes to add to the identity provider mapper model that is persisted to Keycloak. This can be used to extend the base model with new Keycloak features.

name str

The name of the mapper.

template str

Template to use to format the username to import. Substitutions are enclosed in ${}. For example: '$${ALIAS}.$${CLAIM.sub}'. ALIAS is the provider alias. CLAIM.<NAME> references an ID or Access token claim.

identityProviderAlias String

The alias of the associated identity provider.

realm String

The name of the realm.

extraConfig Map<Any>

Key/value attributes to add to the identity provider mapper model that is persisted to Keycloak. This can be used to extend the base model with new Keycloak features.

name String

The name of the mapper.

template String

Template to use to format the username to import. Substitutions are enclosed in ${}. For example: '$${ALIAS}.$${CLAIM.sub}'. ALIAS is the provider alias. CLAIM.<NAME> references an ID or Access token claim.

Outputs

All input properties are implicitly available as output properties. Additionally, the UserTemplateImporterIdentityProviderMapper resource produces the following output properties:

Id string

The provider-assigned unique ID for this managed resource.

Id string

The provider-assigned unique ID for this managed resource.

id String

The provider-assigned unique ID for this managed resource.

id string

The provider-assigned unique ID for this managed resource.

id str

The provider-assigned unique ID for this managed resource.

id String

The provider-assigned unique ID for this managed resource.

Look up Existing UserTemplateImporterIdentityProviderMapper Resource

Get an existing UserTemplateImporterIdentityProviderMapper resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: UserTemplateImporterIdentityProviderMapperState, opts?: CustomResourceOptions): UserTemplateImporterIdentityProviderMapper
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        extra_config: Optional[Mapping[str, Any]] = None,
        identity_provider_alias: Optional[str] = None,
        name: Optional[str] = None,
        realm: Optional[str] = None,
        template: Optional[str] = None) -> UserTemplateImporterIdentityProviderMapper
func GetUserTemplateImporterIdentityProviderMapper(ctx *Context, name string, id IDInput, state *UserTemplateImporterIdentityProviderMapperState, opts ...ResourceOption) (*UserTemplateImporterIdentityProviderMapper, error)
public static UserTemplateImporterIdentityProviderMapper Get(string name, Input<string> id, UserTemplateImporterIdentityProviderMapperState? state, CustomResourceOptions? opts = null)
public static UserTemplateImporterIdentityProviderMapper get(String name, Output<String> id, UserTemplateImporterIdentityProviderMapperState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
ExtraConfig Dictionary<string, object>

Key/value attributes to add to the identity provider mapper model that is persisted to Keycloak. This can be used to extend the base model with new Keycloak features.

IdentityProviderAlias string

The alias of the associated identity provider.

Name string

The name of the mapper.

Realm string

The name of the realm.

Template string

Template to use to format the username to import. Substitutions are enclosed in ${}. For example: '$${ALIAS}.$${CLAIM.sub}'. ALIAS is the provider alias. CLAIM.<NAME> references an ID or Access token claim.

ExtraConfig map[string]interface{}

Key/value attributes to add to the identity provider mapper model that is persisted to Keycloak. This can be used to extend the base model with new Keycloak features.

IdentityProviderAlias string

The alias of the associated identity provider.

Name string

The name of the mapper.

Realm string

The name of the realm.

Template string

Template to use to format the username to import. Substitutions are enclosed in ${}. For example: '$${ALIAS}.$${CLAIM.sub}'. ALIAS is the provider alias. CLAIM.<NAME> references an ID or Access token claim.

extraConfig Map<String,Object>

Key/value attributes to add to the identity provider mapper model that is persisted to Keycloak. This can be used to extend the base model with new Keycloak features.

identityProviderAlias String

The alias of the associated identity provider.

name String

The name of the mapper.

realm String

The name of the realm.

template String

Template to use to format the username to import. Substitutions are enclosed in ${}. For example: '$${ALIAS}.$${CLAIM.sub}'. ALIAS is the provider alias. CLAIM.<NAME> references an ID or Access token claim.

extraConfig {[key: string]: any}

Key/value attributes to add to the identity provider mapper model that is persisted to Keycloak. This can be used to extend the base model with new Keycloak features.

identityProviderAlias string

The alias of the associated identity provider.

name string

The name of the mapper.

realm string

The name of the realm.

template string

Template to use to format the username to import. Substitutions are enclosed in ${}. For example: '$${ALIAS}.$${CLAIM.sub}'. ALIAS is the provider alias. CLAIM.<NAME> references an ID or Access token claim.

extra_config Mapping[str, Any]

Key/value attributes to add to the identity provider mapper model that is persisted to Keycloak. This can be used to extend the base model with new Keycloak features.

identity_provider_alias str

The alias of the associated identity provider.

name str

The name of the mapper.

realm str

The name of the realm.

template str

Template to use to format the username to import. Substitutions are enclosed in ${}. For example: '$${ALIAS}.$${CLAIM.sub}'. ALIAS is the provider alias. CLAIM.<NAME> references an ID or Access token claim.

extraConfig Map<Any>

Key/value attributes to add to the identity provider mapper model that is persisted to Keycloak. This can be used to extend the base model with new Keycloak features.

identityProviderAlias String

The alias of the associated identity provider.

name String

The name of the mapper.

realm String

The name of the realm.

template String

Template to use to format the username to import. Substitutions are enclosed in ${}. For example: '$${ALIAS}.$${CLAIM.sub}'. ALIAS is the provider alias. CLAIM.<NAME> references an ID or Access token claim.

Import

Identity provider mappers can be imported using the format {{realm_id}}/{{idp_alias}}/{{idp_mapper_id}}, where idp_alias is the identity provider alias, and idp_mapper_id is the unique ID that Keycloak assigns to the mapper upon creation. This value can be found in the URI when editing this mapper in the GUI, and is typically a GUID. Examplebash

 $ pulumi import keycloak:index/userTemplateImporterIdentityProviderMapper:UserTemplateImporterIdentityProviderMapper username_importer my-realm/my-mapper/f446db98-7133-4e30-b18a-3d28fde7ca1b

Package Details

Repository
Keycloak pulumi/pulumi-keycloak
License
Apache-2.0
Notes

This Pulumi package is based on the keycloak Terraform Provider.