GenericClientRoleMapper
Allow for creating and managing a client’s scope mappings within Keycloak.
By default, all the user role mappings of the user are added as claims within the token (OIDC) or assertion (SAML). When
full_scope_allowed
is set to false
for a client, role scope mapping allows you to limit the roles that get declared
inside an access token for a client.
Example Usage
Realm Role To Client)
using Pulumi;
using Keycloak = Pulumi.Keycloak;
class MyStack : Stack
{
public MyStack()
{
var realm = new Keycloak.Realm("realm", new Keycloak.RealmArgs
{
Realm = "my-realm",
Enabled = true,
});
var client = new Keycloak.OpenId.Client("client", new Keycloak.OpenId.ClientArgs
{
RealmId = realm.Id,
ClientId = "client",
Enabled = true,
AccessType = "BEARER-ONLY",
});
var realmRole = new Keycloak.Role("realmRole", new Keycloak.RoleArgs
{
RealmId = realm.Id,
Description = "My Realm Role",
});
var clientRoleMapper = new Keycloak.GenericClientRoleMapper("clientRoleMapper", new Keycloak.GenericClientRoleMapperArgs
{
RealmId = realm.Id,
ClientId = client.Id,
RoleId = realmRole.Id,
});
}
}
package main
import (
"github.com/pulumi/pulumi-keycloak/sdk/v3/go/keycloak"
"github.com/pulumi/pulumi-keycloak/sdk/v3/go/keycloak/openid"
"github.com/pulumi/pulumi/sdk/v2/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
}
client, err := openid.NewClient(ctx, "client", &openid.ClientArgs{
RealmId: realm.ID(),
ClientId: pulumi.String("client"),
Enabled: pulumi.Bool(true),
AccessType: pulumi.String("BEARER-ONLY"),
})
if err != nil {
return err
}
realmRole, err := keycloak.NewRole(ctx, "realmRole", &keycloak.RoleArgs{
RealmId: realm.ID(),
Description: pulumi.String("My Realm Role"),
})
if err != nil {
return err
}
_, err = keycloak.NewGenericClientRoleMapper(ctx, "clientRoleMapper", &keycloak.GenericClientRoleMapperArgs{
RealmId: realm.ID(),
ClientId: client.ID(),
RoleId: realmRole.ID(),
})
if err != nil {
return err
}
return nil
})
}
import pulumi
import pulumi_keycloak as keycloak
realm = keycloak.Realm("realm",
realm="my-realm",
enabled=True)
client = keycloak.openid.Client("client",
realm_id=realm.id,
client_id="client",
enabled=True,
access_type="BEARER-ONLY")
realm_role = keycloak.Role("realmRole",
realm_id=realm.id,
description="My Realm Role")
client_role_mapper = keycloak.GenericClientRoleMapper("clientRoleMapper",
realm_id=realm.id,
client_id=client.id,
role_id=realm_role.id)
import * as pulumi from "@pulumi/pulumi";
import * as keycloak from "@pulumi/keycloak";
const realm = new keycloak.Realm("realm", {
realm: "my-realm",
enabled: true,
});
const client = new keycloak.openid.Client("client", {
realmId: realm.id,
clientId: "client",
enabled: true,
accessType: "BEARER-ONLY",
});
const realmRole = new keycloak.Role("realmRole", {
realmId: realm.id,
description: "My Realm Role",
});
const clientRoleMapper = new keycloak.GenericClientRoleMapper("clientRoleMapper", {
realmId: realm.id,
clientId: client.id,
roleId: realmRole.id,
});
Client Role To Client)
using Pulumi;
using Keycloak = Pulumi.Keycloak;
class MyStack : Stack
{
public MyStack()
{
var realm = new Keycloak.Realm("realm", new Keycloak.RealmArgs
{
Realm = "my-realm",
Enabled = true,
});
var clientA = new Keycloak.OpenId.Client("clientA", new Keycloak.OpenId.ClientArgs
{
RealmId = realm.Id,
ClientId = "client-a",
Enabled = true,
AccessType = "BEARER-ONLY",
FullScopeAllowed = false,
});
var clientRoleA = new Keycloak.Role("clientRoleA", new Keycloak.RoleArgs
{
RealmId = realm.Id,
ClientId = clientA.Id,
Description = "My Client Role",
});
var clientB = new Keycloak.OpenId.Client("clientB", new Keycloak.OpenId.ClientArgs
{
RealmId = realm.Id,
ClientId = "client-b",
Enabled = true,
AccessType = "BEARER-ONLY",
});
var clientRoleB = new Keycloak.Role("clientRoleB", new Keycloak.RoleArgs
{
RealmId = realm.Id,
ClientId = clientB.Id,
Description = "My Client Role",
});
var clientBRoleMapper = new Keycloak.GenericClientRoleMapper("clientBRoleMapper", new Keycloak.GenericClientRoleMapperArgs
{
RealmId = realm.Id,
ClientId = keycloak_client.Client_b.Id,
RoleId = clientRoleA.Id,
});
}
}
package main
import (
"github.com/pulumi/pulumi-keycloak/sdk/v3/go/keycloak"
"github.com/pulumi/pulumi-keycloak/sdk/v3/go/keycloak/openid"
"github.com/pulumi/pulumi/sdk/v2/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
}
clientA, err := openid.NewClient(ctx, "clientA", &openid.ClientArgs{
RealmId: realm.ID(),
ClientId: pulumi.String("client-a"),
Enabled: pulumi.Bool(true),
AccessType: pulumi.String("BEARER-ONLY"),
FullScopeAllowed: pulumi.Bool(false),
})
if err != nil {
return err
}
clientRoleA, err := keycloak.NewRole(ctx, "clientRoleA", &keycloak.RoleArgs{
RealmId: realm.ID(),
ClientId: clientA.ID(),
Description: pulumi.String("My Client Role"),
})
if err != nil {
return err
}
clientB, err := openid.NewClient(ctx, "clientB", &openid.ClientArgs{
RealmId: realm.ID(),
ClientId: pulumi.String("client-b"),
Enabled: pulumi.Bool(true),
AccessType: pulumi.String("BEARER-ONLY"),
})
if err != nil {
return err
}
_, err = keycloak.NewRole(ctx, "clientRoleB", &keycloak.RoleArgs{
RealmId: realm.ID(),
ClientId: clientB.ID(),
Description: pulumi.String("My Client Role"),
})
if err != nil {
return err
}
_, err = keycloak.NewGenericClientRoleMapper(ctx, "clientBRoleMapper", &keycloak.GenericClientRoleMapperArgs{
RealmId: realm.ID(),
ClientId: pulumi.Any(keycloak_client.Client_b.Id),
RoleId: clientRoleA.ID(),
})
if err != nil {
return err
}
return nil
})
}
import pulumi
import pulumi_keycloak as keycloak
realm = keycloak.Realm("realm",
realm="my-realm",
enabled=True)
client_a = keycloak.openid.Client("clientA",
realm_id=realm.id,
client_id="client-a",
enabled=True,
access_type="BEARER-ONLY",
full_scope_allowed=False)
client_role_a = keycloak.Role("clientRoleA",
realm_id=realm.id,
client_id=client_a.id,
description="My Client Role")
client_b = keycloak.openid.Client("clientB",
realm_id=realm.id,
client_id="client-b",
enabled=True,
access_type="BEARER-ONLY")
client_role_b = keycloak.Role("clientRoleB",
realm_id=realm.id,
client_id=client_b.id,
description="My Client Role")
client_b_role_mapper = keycloak.GenericClientRoleMapper("clientBRoleMapper",
realm_id=realm.id,
client_id=keycloak_client["client_b"]["id"],
role_id=client_role_a.id)
import * as pulumi from "@pulumi/pulumi";
import * as keycloak from "@pulumi/keycloak";
const realm = new keycloak.Realm("realm", {
realm: "my-realm",
enabled: true,
});
const clientA = new keycloak.openid.Client("clientA", {
realmId: realm.id,
clientId: "client-a",
enabled: true,
accessType: "BEARER-ONLY",
fullScopeAllowed: false,
});
const clientRoleA = new keycloak.Role("clientRoleA", {
realmId: realm.id,
clientId: clientA.id,
description: "My Client Role",
});
const clientB = new keycloak.openid.Client("clientB", {
realmId: realm.id,
clientId: "client-b",
enabled: true,
accessType: "BEARER-ONLY",
});
const clientRoleB = new keycloak.Role("clientRoleB", {
realmId: realm.id,
clientId: clientB.id,
description: "My Client Role",
});
const clientBRoleMapper = new keycloak.GenericClientRoleMapper("clientBRoleMapper", {
realmId: realm.id,
clientId: keycloak_client.client_b.id,
roleId: clientRoleA.id,
});
Realm Role To Client Scope)
using Pulumi;
using Keycloak = Pulumi.Keycloak;
class MyStack : Stack
{
public MyStack()
{
var realm = new Keycloak.Realm("realm", new Keycloak.RealmArgs
{
Realm = "my-realm",
Enabled = true,
});
var clientScope = new Keycloak.OpenId.ClientScope("clientScope", new Keycloak.OpenId.ClientScopeArgs
{
RealmId = realm.Id,
});
var realmRole = new Keycloak.Role("realmRole", new Keycloak.RoleArgs
{
RealmId = realm.Id,
Description = "My Realm Role",
});
var clientRoleMapper = new Keycloak.GenericClientRoleMapper("clientRoleMapper", new Keycloak.GenericClientRoleMapperArgs
{
RealmId = realm.Id,
ClientScopeId = clientScope.Id,
RoleId = realmRole.Id,
});
}
}
package main
import (
"github.com/pulumi/pulumi-keycloak/sdk/v3/go/keycloak"
"github.com/pulumi/pulumi-keycloak/sdk/v3/go/keycloak/openid"
"github.com/pulumi/pulumi/sdk/v2/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
}
clientScope, err := openid.NewClientScope(ctx, "clientScope", &openid.ClientScopeArgs{
RealmId: realm.ID(),
})
if err != nil {
return err
}
realmRole, err := keycloak.NewRole(ctx, "realmRole", &keycloak.RoleArgs{
RealmId: realm.ID(),
Description: pulumi.String("My Realm Role"),
})
if err != nil {
return err
}
_, err = keycloak.NewGenericClientRoleMapper(ctx, "clientRoleMapper", &keycloak.GenericClientRoleMapperArgs{
RealmId: realm.ID(),
ClientScopeId: clientScope.ID(),
RoleId: realmRole.ID(),
})
if err != nil {
return err
}
return nil
})
}
import pulumi
import pulumi_keycloak as keycloak
realm = keycloak.Realm("realm",
realm="my-realm",
enabled=True)
client_scope = keycloak.openid.ClientScope("clientScope", realm_id=realm.id)
realm_role = keycloak.Role("realmRole",
realm_id=realm.id,
description="My Realm Role")
client_role_mapper = keycloak.GenericClientRoleMapper("clientRoleMapper",
realm_id=realm.id,
client_scope_id=client_scope.id,
role_id=realm_role.id)
import * as pulumi from "@pulumi/pulumi";
import * as keycloak from "@pulumi/keycloak";
const realm = new keycloak.Realm("realm", {
realm: "my-realm",
enabled: true,
});
const clientScope = new keycloak.openid.ClientScope("clientScope", {realmId: realm.id});
const realmRole = new keycloak.Role("realmRole", {
realmId: realm.id,
description: "My Realm Role",
});
const clientRoleMapper = new keycloak.GenericClientRoleMapper("clientRoleMapper", {
realmId: realm.id,
clientScopeId: clientScope.id,
roleId: realmRole.id,
});
Client Role To Client Scope)
using Pulumi;
using Keycloak = Pulumi.Keycloak;
class MyStack : Stack
{
public MyStack()
{
var realm = new Keycloak.Realm("realm", new Keycloak.RealmArgs
{
Realm = "my-realm",
Enabled = true,
});
var client = new Keycloak.OpenId.Client("client", new Keycloak.OpenId.ClientArgs
{
RealmId = realm.Id,
ClientId = "client",
Enabled = true,
AccessType = "BEARER-ONLY",
});
var clientRole = new Keycloak.Role("clientRole", new Keycloak.RoleArgs
{
RealmId = realm.Id,
ClientId = client.Id,
Description = "My Client Role",
});
var clientScope = new Keycloak.OpenId.ClientScope("clientScope", new Keycloak.OpenId.ClientScopeArgs
{
RealmId = realm.Id,
});
var clientBRoleMapper = new Keycloak.GenericClientRoleMapper("clientBRoleMapper", new Keycloak.GenericClientRoleMapperArgs
{
RealmId = realm.Id,
ClientScopeId = keycloak_client_scope.Client_scope.Id,
RoleId = clientRole.Id,
});
}
}
package main
import (
"github.com/pulumi/pulumi-keycloak/sdk/v3/go/keycloak"
"github.com/pulumi/pulumi-keycloak/sdk/v3/go/keycloak/openid"
"github.com/pulumi/pulumi/sdk/v2/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
}
client, err := openid.NewClient(ctx, "client", &openid.ClientArgs{
RealmId: realm.ID(),
ClientId: pulumi.String("client"),
Enabled: pulumi.Bool(true),
AccessType: pulumi.String("BEARER-ONLY"),
})
if err != nil {
return err
}
clientRole, err := keycloak.NewRole(ctx, "clientRole", &keycloak.RoleArgs{
RealmId: realm.ID(),
ClientId: client.ID(),
Description: pulumi.String("My Client Role"),
})
if err != nil {
return err
}
_, err = openid.NewClientScope(ctx, "clientScope", &openid.ClientScopeArgs{
RealmId: realm.ID(),
})
if err != nil {
return err
}
_, err = keycloak.NewGenericClientRoleMapper(ctx, "clientBRoleMapper", &keycloak.GenericClientRoleMapperArgs{
RealmId: realm.ID(),
ClientScopeId: pulumi.Any(keycloak_client_scope.Client_scope.Id),
RoleId: clientRole.ID(),
})
if err != nil {
return err
}
return nil
})
}
import pulumi
import pulumi_keycloak as keycloak
realm = keycloak.Realm("realm",
realm="my-realm",
enabled=True)
client = keycloak.openid.Client("client",
realm_id=realm.id,
client_id="client",
enabled=True,
access_type="BEARER-ONLY")
client_role = keycloak.Role("clientRole",
realm_id=realm.id,
client_id=client.id,
description="My Client Role")
client_scope = keycloak.openid.ClientScope("clientScope", realm_id=realm.id)
client_b_role_mapper = keycloak.GenericClientRoleMapper("clientBRoleMapper",
realm_id=realm.id,
client_scope_id=keycloak_client_scope["client_scope"]["id"],
role_id=client_role.id)
import * as pulumi from "@pulumi/pulumi";
import * as keycloak from "@pulumi/keycloak";
const realm = new keycloak.Realm("realm", {
realm: "my-realm",
enabled: true,
});
const client = new keycloak.openid.Client("client", {
realmId: realm.id,
clientId: "client",
enabled: true,
accessType: "BEARER-ONLY",
});
const clientRole = new keycloak.Role("clientRole", {
realmId: realm.id,
clientId: client.id,
description: "My Client Role",
});
const clientScope = new keycloak.openid.ClientScope("clientScope", {realmId: realm.id});
const clientBRoleMapper = new keycloak.GenericClientRoleMapper("clientBRoleMapper", {
realmId: realm.id,
clientScopeId: keycloak_client_scope.client_scope.id,
roleId: clientRole.id,
});
Create a GenericClientRoleMapper Resource
new GenericClientRoleMapper(name: string, args: GenericClientRoleMapperArgs, opts?: CustomResourceOptions);
def GenericClientRoleMapper(resource_name: str, opts: Optional[ResourceOptions] = None, client_id: Optional[str] = None, client_scope_id: Optional[str] = None, realm_id: Optional[str] = None, role_id: Optional[str] = None)
func NewGenericClientRoleMapper(ctx *Context, name string, args GenericClientRoleMapperArgs, opts ...ResourceOption) (*GenericClientRoleMapper, error)
public GenericClientRoleMapper(string name, GenericClientRoleMapperArgs args, CustomResourceOptions? opts = null)
- name string
- The unique name of the resource.
- args GenericClientRoleMapperArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- resource_name str
- The unique name of the resource.
- opts ResourceOptions
- A bag of options that control this resource's behavior.
- ctx Context
- Context object for the current deployment.
- name string
- The unique name of the resource.
- args GenericClientRoleMapperArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args GenericClientRoleMapperArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
GenericClientRoleMapper Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Programming Model docs.
Inputs
The GenericClientRoleMapper resource accepts the following input properties:
- Realm
Id string The realm this role mapper exists within.
- Role
Id string The ID of the role to be added to this role mapper.
- Client
Id string The ID of the client this role mapper should be added to. Conflicts with
client_scope_id
. This argument is required ifclient_scope_id
is not set.- Client
Scope stringId The ID of the client scope this role mapper should be added to. Conflicts with
client_id
. This argument is required ifclient_id
is not set.
- Realm
Id string The realm this role mapper exists within.
- Role
Id string The ID of the role to be added to this role mapper.
- Client
Id string The ID of the client this role mapper should be added to. Conflicts with
client_scope_id
. This argument is required ifclient_scope_id
is not set.- Client
Scope stringId The ID of the client scope this role mapper should be added to. Conflicts with
client_id
. This argument is required ifclient_id
is not set.
- realm
Id string The realm this role mapper exists within.
- role
Id string The ID of the role to be added to this role mapper.
- client
Id string The ID of the client this role mapper should be added to. Conflicts with
client_scope_id
. This argument is required ifclient_scope_id
is not set.- client
Scope stringId The ID of the client scope this role mapper should be added to. Conflicts with
client_id
. This argument is required ifclient_id
is not set.
- realm_
id str The realm this role mapper exists within.
- role_
id str The ID of the role to be added to this role mapper.
- client_
id str The ID of the client this role mapper should be added to. Conflicts with
client_scope_id
. This argument is required ifclient_scope_id
is not set.- client_
scope_ strid The ID of the client scope this role mapper should be added to. Conflicts with
client_id
. This argument is required ifclient_id
is not set.
Outputs
All input properties are implicitly available as output properties. Additionally, the GenericClientRoleMapper 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 str
- The provider-assigned unique ID for this managed resource.
Look up an Existing GenericClientRoleMapper Resource
Get an existing GenericClientRoleMapper 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?: GenericClientRoleMapperState, opts?: CustomResourceOptions): GenericClientRoleMapper
@staticmethod
def get(resource_name: str, id: str, opts: Optional[ResourceOptions] = None, client_id: Optional[str] = None, client_scope_id: Optional[str] = None, realm_id: Optional[str] = None, role_id: Optional[str] = None) -> GenericClientRoleMapper
func GetGenericClientRoleMapper(ctx *Context, name string, id IDInput, state *GenericClientRoleMapperState, opts ...ResourceOption) (*GenericClientRoleMapper, error)
public static GenericClientRoleMapper Get(string name, Input<string> id, GenericClientRoleMapperState? state, CustomResourceOptions? opts = null)
- 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.
The following state arguments are supported:
- Client
Id string The ID of the client this role mapper should be added to. Conflicts with
client_scope_id
. This argument is required ifclient_scope_id
is not set.- Client
Scope stringId The ID of the client scope this role mapper should be added to. Conflicts with
client_id
. This argument is required ifclient_id
is not set.- Realm
Id string The realm this role mapper exists within.
- Role
Id string The ID of the role to be added to this role mapper.
- Client
Id string The ID of the client this role mapper should be added to. Conflicts with
client_scope_id
. This argument is required ifclient_scope_id
is not set.- Client
Scope stringId The ID of the client scope this role mapper should be added to. Conflicts with
client_id
. This argument is required ifclient_id
is not set.- Realm
Id string The realm this role mapper exists within.
- Role
Id string The ID of the role to be added to this role mapper.
- client
Id string The ID of the client this role mapper should be added to. Conflicts with
client_scope_id
. This argument is required ifclient_scope_id
is not set.- client
Scope stringId The ID of the client scope this role mapper should be added to. Conflicts with
client_id
. This argument is required ifclient_id
is not set.- realm
Id string The realm this role mapper exists within.
- role
Id string The ID of the role to be added to this role mapper.
- client_
id str The ID of the client this role mapper should be added to. Conflicts with
client_scope_id
. This argument is required ifclient_scope_id
is not set.- client_
scope_ strid The ID of the client scope this role mapper should be added to. Conflicts with
client_id
. This argument is required ifclient_id
is not set.- realm_
id str The realm this role mapper exists within.
- role_
id str The ID of the role to be added to this role mapper.
Import
Generic client role mappers can be imported using one of the following two formats- When mapping a role to a client, use the format {{realmId}}/client/{{clientId}}/scope-mappings/{{roleClientId}}/{{roleId}}
- When mapping a role to a client scope, use the format {{realmId}}/client-scope/{{clientScopeId}}/scope-mappings/{{roleClientId}}/{{roleId}}
Examplebash
$ pulumi import keycloak:index/genericClientRoleMapper:GenericClientRoleMapper client_role_mapper my-realm/client/23888550-5dcd-41f6-85ba-554233021e9c/scope-mappings/ce51f004-bdfb-4dd5-a963-c4487d2dec5b/ff3aa49f-bc07-4030-8783-41918c3614a3
Package Details
- Repository
- https://github.com/pulumi/pulumi-keycloak
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
keycloak
Terraform Provider.