Last active
September 21, 2022 09:09
-
-
Save cyanide-burnout/5211807c396554b76b909f482fdcdda1 to your computer and use it in GitHub Desktop.
Check user group membership in Azure AD (including inheritance)
This file contains hidden or 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
<?php | |
if (array_key_exists("access_token", $_SESSION)) | |
{ | |
$handle = curl_init(); | |
curl_setopt($handle, CURLOPT_POST, true); | |
curl_setopt($handle, CURLOPT_URL, "https://graph.microsoft.com/v1.0/me/checkMemberGroups"); | |
curl_setopt($handle, CURLOPT_HTTPHEADER, array("Authorization: Bearer " . $_SESSION["access_token"], "Content-Type: application/json")); | |
curl_setopt($handle, CURLOPT_POSTFIELDS, "{\"groupIds\":[" . GRAPH_GROUP_LIST . "]}"); | |
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); | |
$response = curl_exec($handle); | |
$data = json_decode($response, true); | |
curl_close($handle); | |
if (array_key_exists("value", $data)) | |
{ | |
$_SESSION["membership"] = array("groups" => $data["value"]); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment