chore(keycloak): code cleanup

This commit is contained in:
Masaki Yatsu
2025-10-29 15:33:20 +09:00
parent fd0c359407
commit 82f90f621b
35 changed files with 613 additions and 599 deletions

View File

@@ -33,43 +33,41 @@ const main = async () => {
kcAdminClient.setConfig({ realmName });
// Find the client
const clients = await kcAdminClient.clients.find({ clientId });
const client = clients.find(c => c.clientId === clientId);
const client = clients.find((c) => c.clientId === clientId);
if (!client) {
throw new Error(`Client '${clientId}' not found`);
}
// Check if groups mapper already exists
const existingMappers = await kcAdminClient.clients.listProtocolMappers({
id: client.id!,
});
const groupsMapper = existingMappers.find(mapper =>
mapper.name === "groups" || mapper.config?.["claim.name"] === "groups"
const groupsMapper = existingMappers.find(
(mapper) => mapper.name === "groups" || mapper.config?.["claim.name"] === "groups"
);
if (groupsMapper) {
console.log("Groups mapper already exists for the client.");
return;
}
// Add groups mapper
await kcAdminClient.clients.addProtocolMapper({
id: client.id!,
}, {
name: "groups",
protocol: "openid-connect",
protocolMapper: "oidc-group-membership-mapper",
config: {
"claim.name": "groups",
"full.path": "false",
"id.token.claim": "true",
"access.token.claim": "true",
"userinfo.token.claim": "true",
await kcAdminClient.clients.addProtocolMapper(
{
id: client.id!,
},
});
{
name: "groups",
protocol: "openid-connect",
protocolMapper: "oidc-group-membership-mapper",
config: {
"claim.name": "groups",
"full.path": "false",
"id.token.claim": "true",
"access.token.claim": "true",
"userinfo.token.claim": "true",
},
}
);
console.log("Groups mapper added to the client.");
} catch (error) {
@@ -79,4 +77,4 @@ const main = async () => {
}
};
main();
main();