diff --git a/server/services/msgraph/MSGraphService.ts b/server/services/msgraph/MSGraphService.ts index 95ae15f52..59fdba194 100644 --- a/server/services/msgraph/MSGraphService.ts +++ b/server/services/msgraph/MSGraphService.ts @@ -314,4 +314,29 @@ export class MSGraphService { throw new MSGraphError('getEvents', error.message) } } + + /** + * Checks if a user is a member of a security group. + * + * @param groupId The ID of the security group. + * @param mail The email address of the user. + * + * @public + * + * @memberof MSGraphService + */ + public async isUserMemberOfSecurityGroup( + groupId: string, + mail: string + ): Promise { + try { + const client = await this._getClient() + const response = await (client + .api(`/groups/${groupId}/members?$select=id,mail`) + .get() as Promise<{ value: any[] }>) + return response.value.some((member) => member.mail === mail) + } catch { + return false + } + } }