Quick example of how to connect to Microsoft's services using the authorization code flow.
- Register a new app with Microsoft at https://apps.dev.microsoft.com
- Click "Generate new password" to create an application secret (client secret) and copy it to the clipboard
- Click "Add Platform" and select "Web". Then, enter the redirect URI (in this example, http://localhost:8000/login)
- Hit "Save"
- Paste the application secret into the LoginController
- Insert your client ID (application ID)
- Run
composer install
to install PHP packages - Run
php artisan serve
to start the server!
The application will provide you with an access token that can be used to grab resources from Microsoft Graph. You can change the scopes of the data that you request from your users by updating the SCOPES
constant.
You can use this token to query against Graph like this:
curl_setopt($curl, CURLOPT_HEADER, array('Authorization: bearer <token>'));
To see more uses of grabbing data from Graph, check out this PHP Connect Sample