Skip to content

Instantly share code, notes, and snippets.

@cyanide-burnout
Last active September 21, 2022 09:09
Show Gist options
  • Save cyanide-burnout/5211807c396554b76b909f482fdcdda1 to your computer and use it in GitHub Desktop.
Save cyanide-burnout/5211807c396554b76b909f482fdcdda1 to your computer and use it in GitHub Desktop.
Check user group membership in Azure AD (including inheritance)
<?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