@@ -97,6 +97,7 @@ async function prepareKeycloak() {
9797 console . log ( 'creating client roles' )
9898 for ( let roleName of clientRoleNames ) {
9999 await createClientRole ( BEARER_CLIENT , roleName )
100+ await createClientRole ( PUBLIC_CLIENT , roleName )
100101 }
101102
102103 console . log ( 'creating realm roles' )
@@ -107,7 +108,8 @@ async function prepareKeycloak() {
107108 // get the actual role objects from keycloak after creating them
108109 // need to get the ids that were created on them
109110 realmRoles = await getRealmRoles ( )
110- clientRoles = await getClientRoles ( BEARER_CLIENT )
111+ bearerClientRoles = await getClientRoles ( BEARER_CLIENT )
112+ publicClientRoles = await getClientRoles ( PUBLIC_CLIENT )
111113
112114 for ( let user of users ) {
113115 // Create a new user
@@ -116,7 +118,8 @@ async function prepareKeycloak() {
116118
117119 // Assign roles to the user
118120 await assignRealmRolesToUser ( user , userIdUrl )
119- await assignClientRolesToUser ( user , BEARER_CLIENT , userIdUrl )
121+ await assignClientRolesToUser ( user , BEARER_CLIENT , bearerClientRoles , userIdUrl )
122+ await assignClientRolesToUser ( user , PUBLIC_CLIENT , publicClientRoles , userIdUrl )
120123 }
121124
122125 const publicInstallation = await getClientInstallation ( PUBLIC_CLIENT )
@@ -162,14 +165,14 @@ async function assignRealmRolesToUser(user, userIdUrl) {
162165 }
163166}
164167
165- async function assignClientRolesToUser ( user , client , userIdUrl ) {
168+ async function assignClientRolesToUser ( user , client , clientRoles , userIdUrl ) {
166169 for ( let roleToAssign of user . clientRoles ) {
167- console . log ( `assigning client role ${ roleToAssign } from client ${ PUBLIC_CLIENT_NAME } on user ${ user . name } ` )
170+ console . log ( `assigning client role ${ roleToAssign } from client ${ client . clientId } on user ${ user . name } ` )
168171 const selectedClientRole = clientRoles . find ( clientRole => clientRole . name === roleToAssign )
169172 if ( selectedClientRole ) {
170173 await assignClientRoleToUser ( userIdUrl , client , selectedClientRole )
171174 } else {
172- console . error ( `client role ${ roleToAssign } does not exist on client ${ PUBLIC_CLIENT_NAME } ` )
175+ console . error ( `client role ${ roleToAssign } does not exist on client ${ client . clientId } ` )
173176 }
174177 }
175178}
0 commit comments