Skip to content

Commit

Permalink
other: checksecuritygroupmembership to check for security group membe…
Browse files Browse the repository at this point in the history
…rship 🔧
  • Loading branch information
olemp committed Mar 21, 2024
1 parent 260e4fc commit 396ad25
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { MSGraphService, MSOAuthService } from '../../../services'
import { Subscription } from '../../../graphql/resolvers/types'

/**
* Checks if a user is a member of the security group defined
* in the subscription settings.
*
* @param subscription The subscription object.
* @param tokenParameters The token parameters.
* @param mail The email of the user.
*
* @returns A boolean indicating whether the user is a member of the security group.
*/
export const checkSecurityGroupMembership = async (
subscription: Subscription,
tokenParameters: any,
mail: string
) => {
if (!subscription.settings?.security?.securityGroupId) return false
const msAuthSvc = new MSOAuthService({
user: {
subscription,
tokenParams: tokenParameters
}
})

const msGraphSvc = new MSGraphService(msAuthSvc)

return await msGraphSvc.isUserMemberOfSecurityGroup(
subscription.settings?.security?.securityGroupId,
mail
)
}

0 comments on commit 396ad25

Please sign in to comment.