TUTORIAL – PHP – MICROSOFT GRAPH – IMPLEMENT OFFICE365 INTO ANY WEBSITE
Let's start
Microsoft Graph SDK for PHP
You’ll need to install microsoft/microsoft-graph via composer into your PHP project. You can do this by:
composer require microsoft/microsoft-graph
or via your composer file composer.json
{“require”:{“microsoft/microsoft-graph”: “^1.5”}}


If you don’t know how to install composer you can read about it here: How to install composer to your php project
The GIT repository of msgraph-sdk-php can be found here: https://github.com/microsoftgraph/msgraph-sdk-php
The overview of GRAPH can be found here: https://docs.microsoft.com/en-us/graph/overview
ONEDRIVE GRAPH: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/index?view=odsp-graph-online
The complete reference of possible usages with explanation for API v.1.0: https://docs.microsoft.com/en-us/graph/api/overview?view=graph-rest-1.0


CURL
adapt your php curl so you won't get into trouble


cacert.pem can be downloaded directly from our site: cacert.pem
if you don’t set the certificate you will encounter errors like:
RequestException in CurlFactory.php line 187: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
GRAPH has no authentication method included, so you will need to install one with oauth2.
You can do that via composer require league/oauth2-client






Please take note that we are working with callbacks in order to get our access tokens, so we need to provide the corresponding function for this callback "localhost\mscallback" or however you want to name this endpoint, also replace localhost with your domain. We will do that later.
This is the content of our TokenCache.php:




You see that we point each route to a specific function inside of our AuthController.
To have a very rudimentary Login and Logout possibility for connection with GRAPH you can use the following HTML:




You need to be a registered member to rate this.

