@@ -32,7 +32,7 @@ import {
3232 EntraGroupActions ,
3333 entraProfilePatchRequest ,
3434} from "../../common/types/iam.js" ;
35- import { getGroupRoles } from "../functions/authorization.js" ;
35+ import { clearAuthCache , getGroupRoles } from "../functions/authorization.js" ;
3636import { getRoleCredentials } from "api/functions/sts.js" ;
3737import { SecretsManagerClient } from "@aws-sdk/client-secrets-manager" ;
3838import { createAuditLogEntry } from "api/functions/auditLog.js" ;
@@ -162,6 +162,14 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
162162 const groupId = ( request . params as Record < string , string > ) . groupId ;
163163 try {
164164 const timestamp = new Date ( ) . toISOString ( ) ;
165+ const entraIdToken = await getEntraIdToken ( {
166+ clients : await getAuthorizedClients ( ) ,
167+ clientId : fastify . environmentConfig . AadValidClientId ,
168+ secretName : genericConfig . EntraSecretName ,
169+ encryptionSecret : fastify . secretConfig . encryption_key ,
170+ logger : request . log ,
171+ } ) ;
172+ const groupMembers = listGroupMembers ( entraIdToken , groupId ) ;
165173 const command = new PutItemCommand ( {
166174 TableName : `${ genericConfig . IAMTablePrefix } -grouproles` ,
167175 Item : marshall ( {
@@ -187,6 +195,13 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
187195 request . body . roles ,
188196 GENERIC_CACHE_SECONDS ,
189197 ) ;
198+ const groupMemberEmails = ( await groupMembers ) . map ( ( x ) => x . email ) ;
199+ await clearAuthCache ( {
200+ redisClient : fastify . redisClient ,
201+ username : groupMemberEmails ,
202+ logger : request . log ,
203+ } ) ;
204+ reply . send ( { message : "OK" } ) ;
190205 } catch ( e : unknown ) {
191206 fastify . nodeCache . del ( `grouproles-${ groupId } ` ) ;
192207 if ( e instanceof BaseError ) {
@@ -198,7 +213,6 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
198213 message : "Could not create group role mapping." ,
199214 } ) ;
200215 }
201- reply . send ( { message : "OK" } ) ;
202216 } ,
203217 ) ;
204218 fastify . withTypeProvider < FastifyZodOpenApiTypeProvider > ( ) . post (
@@ -525,6 +539,14 @@ No action is required from you at this time.
525539 ) ;
526540 }
527541 }
542+ const allEmailsModified = response . success . map ( ( x ) => x . email ) ;
543+ const { redisClient } = fastify ;
544+ const { log : logger } = request ;
545+ await clearAuthCache ( {
546+ redisClient,
547+ username : allEmailsModified ,
548+ logger,
549+ } ) ;
528550 await Promise . allSettled ( logPromises ) ;
529551 reply . status ( 202 ) . send ( response ) ;
530552 } ,
0 commit comments