PHP sample for accessing Azure AD Graph Service now available

We have just released a PHP sample that shows how to work with the AAD Graph Service. In a previous post we saw the format of HTTP requests and JSON responses for several interesting Graph operations. The PHP sample just shows how to put together these requests and parse the JSON responses using PHP.

Here are some things to know about this sample:

  • You can use WebMatrix to work with this PHP sample. WebMatrix is a free and light weight tool that will let you create web sites using various technologies like PHP, Asp.Net, Node.js etc. In order to run this sample in Web matrix, choose "Open Site" -> "Folder as Site" and select the folder that contains all the downloaded files.
  • The sample comes with a demo tenant that you can use for Read operations. If you want to see Write operations like Edit User, Delete User etc. in action, you can create a sample tenant and an associated Service principal. The first section in the "walk through for building a .Net application" talks about how to create a test tenant and create an associated service principal. You can use the powershell script( CreateServicePrincipal.ps1) to create the service principal.
  • Replace the information in Settings.php file with the information you got from the Powershell script( AppId, Password and Tenant name) when you created the service principal.
  • The code in AuthorizationHelperForAADGraphService puts together the request for getting the Access token from Azure AD for accessing Graph Service for the tenant using the AppId, password and the tenant domain name.
  • All the Graph access related code is in GraphServiceAccessHelper.php and the code is pretty straight forward. It puts together HTTP GET, POST, PATCH and DELETE operations and depending on the request it parses the JSON response from the service.

 

Let us know if you have any questions about the sample code or if you have any particular requests for the sample.