keycloak logo
Keycloak v5.0.0, Jan 25 23

keycloak.getUserRealmRoles

This data source can be used to fetch the realm roles of a user within Keycloak.

Example Usage

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

return await Deployment.RunAsync(() => 
{
    var masterRealm = Keycloak.GetRealm.Invoke(new()
    {
        Realm = "master",
    });

    var defaultAdminUser = Keycloak.GetUser.Invoke(new()
    {
        RealmId = masterRealm.Apply(getRealmResult => getRealmResult.Id),
        Username = "keycloak",
    });

    var userRealmRoles = Keycloak.GetUserRealmRoles.Invoke(new()
    {
        RealmId = masterRealm.Apply(getRealmResult => getRealmResult.Id),
        UserId = defaultAdminUser.Apply(getUserResult => getUserResult.Id),
    });

    return new Dictionary<string, object?>
    {
        ["keycloakUserRoleNames"] = userRealmRoles.Apply(getUserRealmRolesResult => getUserRealmRolesResult.RoleNames),
    };
});
package main

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

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		masterRealm, err := keycloak.LookupRealm(ctx, &keycloak.LookupRealmArgs{
			Realm: "master",
		}, nil)
		if err != nil {
			return err
		}
		defaultAdminUser, err := keycloak.LookupUser(ctx, &keycloak.LookupUserArgs{
			RealmId:  masterRealm.Id,
			Username: "keycloak",
		}, nil)
		if err != nil {
			return err
		}
		userRealmRoles, err := keycloak.GetUserRealmRoles(ctx, &keycloak.GetUserRealmRolesArgs{
			RealmId: masterRealm.Id,
			UserId:  defaultAdminUser.Id,
		}, nil)
		if err != nil {
			return err
		}
		ctx.Export("keycloakUserRoleNames", userRealmRoles.RoleNames)
		return nil
	})
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.keycloak.KeycloakFunctions;
import com.pulumi.keycloak.inputs.GetRealmArgs;
import com.pulumi.keycloak.inputs.GetUserArgs;
import com.pulumi.keycloak.inputs.GetUserRealmRolesArgs;
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) {
        final var masterRealm = KeycloakFunctions.getRealm(GetRealmArgs.builder()
            .realm("master")
            .build());

        final var defaultAdminUser = KeycloakFunctions.getUser(GetUserArgs.builder()
            .realmId(masterRealm.applyValue(getRealmResult -> getRealmResult.id()))
            .username("keycloak")
            .build());

        final var userRealmRoles = KeycloakFunctions.getUserRealmRoles(GetUserRealmRolesArgs.builder()
            .realmId(masterRealm.applyValue(getRealmResult -> getRealmResult.id()))
            .userId(defaultAdminUser.applyValue(getUserResult -> getUserResult.id()))
            .build());

        ctx.export("keycloakUserRoleNames", userRealmRoles.applyValue(getUserRealmRolesResult -> getUserRealmRolesResult.roleNames()));
    }
}
import pulumi
import pulumi_keycloak as keycloak

master_realm = keycloak.get_realm(realm="master")
default_admin_user = keycloak.get_user(realm_id=master_realm.id,
    username="keycloak")
user_realm_roles = keycloak.get_user_realm_roles(realm_id=master_realm.id,
    user_id=default_admin_user.id)
pulumi.export("keycloakUserRoleNames", user_realm_roles.role_names)
import * as pulumi from "@pulumi/pulumi";
import * as keycloak from "@pulumi/keycloak";

const masterRealm = keycloak.getRealm({
    realm: "master",
});
const defaultAdminUser = masterRealm.then(masterRealm => keycloak.getUser({
    realmId: masterRealm.id,
    username: "keycloak",
}));
const userRealmRoles = Promise.all([masterRealm, defaultAdminUser]).then(([masterRealm, defaultAdminUser]) => keycloak.getUserRealmRoles({
    realmId: masterRealm.id,
    userId: defaultAdminUser.id,
}));
export const keycloakUserRoleNames = userRealmRoles.then(userRealmRoles => userRealmRoles.roleNames);
variables:
  masterRealm:
    fn::invoke:
      Function: keycloak:getRealm
      Arguments:
        realm: master
  defaultAdminUser:
    fn::invoke:
      Function: keycloak:getUser
      Arguments:
        realmId: ${masterRealm.id}
        username: keycloak
  userRealmRoles:
    fn::invoke:
      Function: keycloak:getUserRealmRoles
      Arguments:
        realmId: ${masterRealm.id}
        userId: ${defaultAdminUser.id}
outputs:
  keycloakUserRoleNames: ${userRealmRoles.roleNames}

Using getUserRealmRoles

Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

function getUserRealmRoles(args: GetUserRealmRolesArgs, opts?: InvokeOptions): Promise<GetUserRealmRolesResult>
function getUserRealmRolesOutput(args: GetUserRealmRolesOutputArgs, opts?: InvokeOptions): Output<GetUserRealmRolesResult>
def get_user_realm_roles(realm_id: Optional[str] = None,
                         user_id: Optional[str] = None,
                         opts: Optional[InvokeOptions] = None) -> GetUserRealmRolesResult
def get_user_realm_roles_output(realm_id: Optional[pulumi.Input[str]] = None,
                         user_id: Optional[pulumi.Input[str]] = None,
                         opts: Optional[InvokeOptions] = None) -> Output[GetUserRealmRolesResult]
func GetUserRealmRoles(ctx *Context, args *GetUserRealmRolesArgs, opts ...InvokeOption) (*GetUserRealmRolesResult, error)
func GetUserRealmRolesOutput(ctx *Context, args *GetUserRealmRolesOutputArgs, opts ...InvokeOption) GetUserRealmRolesResultOutput

> Note: This function is named GetUserRealmRoles in the Go SDK.

public static class GetUserRealmRoles 
{
    public static Task<GetUserRealmRolesResult> InvokeAsync(GetUserRealmRolesArgs args, InvokeOptions? opts = null)
    public static Output<GetUserRealmRolesResult> Invoke(GetUserRealmRolesInvokeArgs args, InvokeOptions? opts = null)
}
public static CompletableFuture<GetUserRealmRolesResult> getUserRealmRoles(GetUserRealmRolesArgs args, InvokeOptions options)
// Output-based functions aren't available in Java yet
fn::invoke:
  function: keycloak:index/getUserRealmRoles:getUserRealmRoles
  arguments:
    # arguments dictionary

The following arguments are supported:

RealmId string

The realm this user belongs to.

UserId string

The ID of the user to query realm roles for.

RealmId string

The realm this user belongs to.

UserId string

The ID of the user to query realm roles for.

realmId String

The realm this user belongs to.

userId String

The ID of the user to query realm roles for.

realmId string

The realm this user belongs to.

userId string

The ID of the user to query realm roles for.

realm_id str

The realm this user belongs to.

user_id str

The ID of the user to query realm roles for.

realmId String

The realm this user belongs to.

userId String

The ID of the user to query realm roles for.

getUserRealmRoles Result

The following output properties are available:

Id string

The provider-assigned unique ID for this managed resource.

RealmId string
RoleNames List<string>

(Computed) A list of realm roles that belong to this user.

UserId string
Id string

The provider-assigned unique ID for this managed resource.

RealmId string
RoleNames []string

(Computed) A list of realm roles that belong to this user.

UserId string
id String

The provider-assigned unique ID for this managed resource.

realmId String
roleNames List<String>

(Computed) A list of realm roles that belong to this user.

userId String
id string

The provider-assigned unique ID for this managed resource.

realmId string
roleNames string[]

(Computed) A list of realm roles that belong to this user.

userId string
id str

The provider-assigned unique ID for this managed resource.

realm_id str
role_names Sequence[str]

(Computed) A list of realm roles that belong to this user.

user_id str
id String

The provider-assigned unique ID for this managed resource.

realmId String
roleNames List<String>

(Computed) A list of realm roles that belong to this user.

userId String

Package Details

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

This Pulumi package is based on the keycloak Terraform Provider.