-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
other: checksecuritygroupmembership to check for security group membe…
…rship 🔧
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
server/middleware/passport/microsoft/checkSecurityGroupMembership.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} |