keycloak get role

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-05-29 16:17:53 +07:00
parent 2fb1f4f841
commit 27500667a3
2 changed files with 44 additions and 3 deletions

View file

@ -206,6 +206,31 @@ export async function deleteUser(userId: string) {
return true;
}
/**
* Get keycloak user by uuid
*
* Client must have permission to manage realm's user
*
* @returns user if success, false otherwise.
*/
export async function getRoleMappings(userId: string) {
const res = await fetch(
`${KC_URL}/admin/realms/${KC_REALM}/users/${userId}/role-mappings/realm`,
{
headers: {
authorization: `Bearer ${await getToken()}`,
"content-type": `application/json`,
},
},
).catch((e) => console.log("Keycloak Error: ", e));
if (!res) return false;
if (!res.ok) {
return Boolean(console.error("Keycloak Error Response: ", await res.json()));
}
return await res.json();
}
/**
* Get roles list or specific role data
*