NAME
Kernel::System::OIDC::Keycloak::Base – Interface with Keycloak REST API
DESCRIPTION
Functions for REST communication with Keycloak.
PUBLIC INTERFACE
SystemInfo()
Get keycloak system information
my $Info = $Self->SystemInfo();
Returns
undef - error
{
'fileEncoding' => 'UTF-8',
'userLocale' => 'en_US',
'javaRuntime' => 'OpenJDK Runtime Environment',
'osName' => 'Linux',
'osArchitecture' => 'amd64',
'javaHome' => '/usr/lib/jvm/java-21-openjdk-21.0.5.0.11-2.el9.x86_64',
'javaVm' => 'OpenJDK 64-Bit Server VM',
'uptime' => '0 days, 0 hours, 7 minutes, 18 seconds',
'osVersion' => '6.6.65-1-MANJARO',
'javaVendor' => 'Red Hat, Inc.',
'userName' => 'keycloak',
'javaVersion' => '21.0.5',
'javaVmVersion' => '21.0.5+11-LTS',
'uptimeMillis' => 438675,
'userDir' => '/',
'serverTime' => 'Fri Feb 07 16:24:54 GMT 2025',
'version' => '26.0.7',
'userTimezone' => 'GMT'
}
SearchUsers()
Search for users.
my $AllUsers = $Self->SearchUsers();
my $FilteredUsers = $Self->SearchUsers(
Query => {...}, # TODO
);
Returns
undef - error
[
{
'id' => '3af85848-4169-40c4-bb0f-d70c34a55f33',
'email' => 'agent-1@localhost.com',
'notBefore' => 0,
'disableableCredentialTypes' => [],
'enabled' => bless( do{\(my $o = 1)}, 'JSON::PP::Boolean' ),
'createdTimestamp' => '1702041995104',
'username' => 'agent-1',
'access' => {
'manage' => $VAR1->[0]{'enabled'},
'impersonate' => bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ),
'mapRoles' => $VAR1->[0]{'enabled'},
'view' => $VAR1->[0]{'enabled'},
'manageGroupMembership' => $VAR1->[0]{'enabled'}
},
'totp' => $VAR1->[0]{'access'}{'impersonate'},
'emailVerified' => $VAR1->[0]{'access'}{'impersonate'},
'firstName' => 'agent-1',
'requiredActions' => [],
'lastName' => 'agent-1'
}
]
CountUsers()
Number of users.
my $All = $Self->CountUsers();
my $Filtered = $Self->CountUsers(
Query => {...} # TODO
);
Returns
undef - error
number - success
CreateUser()
Creates a new user.
my $User = $Self->CreateUser(
username => '...',
...,
);
Returns
undef - error
{
...
}
UpdateUser()
Update user information.
my $User = $Self->UpdateUser(
id => 'user-id',
username => '...',
...,
);
Returns
undef - error
1 - success
DeleteUser()
Delete a user.
my $Deleted = $Self->DeleteUser(
id => 'user-id',
);
Returns
undef - error
1 - success
GetRoles()
Get the list of roles.
my $Roles = $Self->GetRoles();
Returns
error - undef
success - [
{
"clientRole" => 1,
"composite" => 0,
"containerId" => "2f156fb3-5534-4732-bfbb-077c5b168a38",
"description" => "Administrator permissions",
"id" => "242fa592-6e6a-48fa-b3a5-da0d7591a512",
"name" => "Administrator",
},
...
];
CreateRole()
Create new role in OIDC client.
my $Success = $Self->CreateRole(
Name => 'Role name', # (required)
Description => 'Role description', # (optional)
);
Returns
error - undef
{
'clientRole' => bless( do{\(my $o = 1)}, 'JSON::PP::Boolean' ),
'description' => 'Administrator permissions',
'composite' => bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ),
'containerId' => '724dfdb0-c1e0-4721-8f85-5a84475018c1',
'id' => '242fa592-6e6a-48fa-b3a5-da0d7591a512',
'attributes' => {},
'name' => 'Administrator'
}
UpdateRole()
Update role in OIDC client.
my $Success = $Self->UpdateRole(
Name => 'Role name', # (required)
Description => 'Role description', # (optional)
);
Returns
error - undef
success - 1
DeleteRole()
Delete role in OIDC client.
my $Success = $Self->DeleteRole(
Name => 'Role name', # (required)
);
Returns
error = undef
success = 1
GetRoleByName()
Get role information.
my $Success = $Self->GetRoleByName(
Name => 'role-name',
);
Returns
error - undef
not found - {}
success - {
'clientRole' => bless( do{\(my $o = 1)}, 'JSON::PP::Boolean' ),
'description' => 'Administrator permissions',
'composite' => bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ),
'containerId' => '724dfdb0-c1e0-4721-8f85-5a84475018c1',
'id' => '242fa592-6e6a-48fa-b3a5-da0d7591a512',
'attributes' => {},
'name' => 'Administrator'
}
AddUserToRoles()
Assign user to roles.
my $Success = $Self->AddUserToRoles(
Roles => [qw(role-names)],
UserID => 'user-id',
);
Returns
undef - error
1 - success
RemoveUserFromRoles()
Unassign user from roles.
my $Success = RemoveUserFromRoles(
Roles => [qw(role-names)],
UserID => 'user-id',
);
Returns
undef - error
1 - success
_AddRemoveUserToFromRoles()
Adds or removes assignments of user to roles.
my $Success = _AddRemoveUserToFromRoles(
Roles => [qw(role-names)],
UserID => 'user-id',
);
Returns
undef - error
1 - success
_DiffRolesLists()
Determines which roles need to be added and removed in order to produce the wanted roles list from the current one.
my $Result = _DiffRolesLists(
Current => [ r1 r2 r3 ],
Wanted => [ r3 r4 r5 ],
);
Returns
my $Result = {
Add => [ r4 r5 ],
Remove => [ r1 r2 ],
};
SetUserRoles()
Sets the user roles in Keycloak to exactly the ones provided. User is added to roles and removed from roles as necessary.
my $Success = $Self->SetUserRoles(
Roles => [qw(role-names)],
UserID => 'user-id',
);
Returns
undef - error
1 - success
VersionRequirements()
Returns the version requirements checks.
my $Requirements = $Self->VersionRequirements();
ActiveUsers()
Returns an hashref with the current active users. The key is the username and the value a list of the open sessions.
my $ActiveUsers = $Self->ActiveUsers();
Returns
undef - error
{
'agent-1' => [
{
ipAddress' => '172.19.0.1',
'rememberMe' => bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ),
'username' => 'agent-2',
'userId' => '44bdd275-4bff-41ec-be3f-9ac76dc10ddd',
'transientUser' => $VAR1->{'agent-2'}[0]{'rememberMe'},
'id' => '3a5b0970-dca0-4708-9c40-8d6523b12435',
'lastAccess' => '1740160368000',
'start' => '1740160127000',
'clients' => {
'724dfdb0-c1e0-4721-8f85-5a84475018c1' => 'otrs-client-dev'
},
},
],
}
GetAdminSessionURL()
Admin session URL link.
my $AdminSessionURL = $Self->GetAdminSessionURL();
Returns
undef - error
string - success
PRIVATE METHODS
_PathServerInfo()
Returns the path to get the server information.
_PathUsers()
Returns the path to get the users information.
_PathUsersCount()
Returns the path to get the number of users information.
_BuildOpenIDConfiguration()
Build open id configuration.
my $OpenIDConfiguration = $Keycloak->_BuildOpenIDConfiguration();
Returns
undef - error
{
...
}
