add group from keycloak
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 7s
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 7s
This commit is contained in:
parent
3bf2446611
commit
94c7de89eb
3 changed files with 92 additions and 1 deletions
|
|
@ -346,6 +346,74 @@ export async function removeUserRoles(userId: string, roles: { id: string; name:
|
|||
return true;
|
||||
}
|
||||
|
||||
export async function getGroup() {
|
||||
const res = await fetch(`${KC_URL}/admin/realms/${KC_REALM}/groups`, {
|
||||
headers: {
|
||||
authorization: `Bearer ${await getToken()}`,
|
||||
"content-type": `application/json`,
|
||||
},
|
||||
method: "GET",
|
||||
});
|
||||
|
||||
const dataMainGroup = await res.json();
|
||||
|
||||
const fetchSubGroups = async (group: any) => {
|
||||
const resSub = await fetch(`${KC_URL}/admin/realms/${KC_REALM}/groups/${group.id}/children`, {
|
||||
headers: {
|
||||
authorization: `Bearer ${await getToken()}`,
|
||||
"content-type": `application/json`,
|
||||
},
|
||||
method: "GET",
|
||||
});
|
||||
|
||||
const dataSubGroup = await resSub.json();
|
||||
let fullSubGroup = await Promise.all(
|
||||
dataSubGroup.map(async (subGroupsData: any) => {
|
||||
if (subGroupsData.subGroupCount > 0) {
|
||||
return await fetchSubGroups(subGroupsData);
|
||||
} else {
|
||||
return {
|
||||
id: subGroupsData.id,
|
||||
name: subGroupsData.name,
|
||||
path: subGroupsData.path,
|
||||
subGroupCount: subGroupsData.subGroupCount,
|
||||
subGroups: [],
|
||||
};
|
||||
}
|
||||
}),
|
||||
);
|
||||
return {
|
||||
id: group.id,
|
||||
name: group.name,
|
||||
path: group.path,
|
||||
subGroupCount: group.subGroupCount,
|
||||
subGroups: fullSubGroup,
|
||||
};
|
||||
};
|
||||
|
||||
const fullMainGroup = await Promise.all(dataMainGroup.map(fetchSubGroups));
|
||||
return fullMainGroup;
|
||||
}
|
||||
|
||||
export async function getGroupUser(userId: string) {
|
||||
const res = await fetch(`${KC_URL}/admin/realms/${KC_REALM}/users/${userId}/groups`, {
|
||||
headers: {
|
||||
authorization: `Bearer ${await getToken()}`,
|
||||
"content-type": `application/json`,
|
||||
},
|
||||
method: "GET",
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
return data.map((item: any) => {
|
||||
return {
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
path: item.path,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
createUser,
|
||||
listRole,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue