项目作者: Natpnk

项目描述 :
Microsoft Graph wrapper and mail transporter for Laravel
高级语言: PHP
项目地址: git://github.com/Natpnk/microsoft-graph-laravel.git
创建时间: 2021-04-27T22:45:10Z
项目社区:https://github.com/Natpnk/microsoft-graph-laravel

开源协议:MIT License

下载


Microsoft Graph for Laravel

This laravel package contains a wrapper for Microsoft Graph with the following features:

  • Microsoft Graph API calls
  • Mail transport

Requirements

  • Laravel 10 or higher (Use version 1.1.2 for Laravel 9)
  • PHP 8.2 or higher

Installation

To install and use this package follow instructions below:

Step 1: Install via composer

  1. $ composer require natpnk/microsoft-graph-laravel

Step 2: Publish config

Run the following to publish the config

  1. $ php artisan vendor:publish --provider="Natpnk\MicrosoftGraphLaravel\MicrosoftGraphServiceProvider" --tag="config"

The config file will be published as follow:

  1. <?php
  2. return [
  3. /*
  4. |--------------------------------------------------------------------------
  5. | Microsoft Graph Laravel wrapper
  6. |--------------------------------------------------------------------------
  7. |
  8. */
  9. 'tenant_id' => env('MSGRAPH_TENANT_ID'),
  10. 'client_id' => env('MSGRAPH_CLIENT_ID'),
  11. 'client_secret' => env('MSGRAPH_CLIENT_SECRET')
  12. ];

Step 3: Create app registration

To obtain the Tenant, ClientID and ClientSecret. Please follow this article to generate a app registration within Azure.

Step 4: Use Microsoft Graph as mail transport (Optional)

It is possible to use Microsoft Graph as an mail transport within Laravel. Add the following to config/mail.php inside your Laravel installation.

  1. 'microsoftgraph' => [
  2. 'transport' => 'microsoft-graph',
  3. ],

Additional settings are not required due to settings inside config/microsoftgraph.php. Remember to use a from address which is a valid mailbox inside your tenant.

Step 5: Use Microsoft Graph as filesystem (Optional)

It is possible to use Microsoft Graph (OneDrive/ Sharepoint) as storage within Laravel. Add the following to config/filesystems.php inside your Laravel installation.

  1. 'disks' => [
  2. 'microsoft-graph' => [
  3. 'driver' => 'microsoft-graph',
  4. 'drive_id' => 'YOUR DRIVE ID'
  5. ],

To obtain the Drive ID. You can use the Microsoft Graph Explorer to produce a GET request to the following:

  1. https://graph.microsoft.com/v1.0/sites/{SHAREPOINT_DOMAIN},{SITE_ID}/drives

You should also have set the Sites.ReadAll or Sites.ReadWriteAll permission based on your needs.

Usage

A basic example usage example get’s all the users from a tentant:

  1. use MicrosoftGraph;
  2. ....
  3. $Users = MicrosoftGraph::createRequest("GET", "/Users")->setReturnType(\Microsoft\Graph\Model\User::class)->execute();
  4. print_r($Users);

for futher documentation about usage consult: Microsoft Graph API docs

Contributing

Feel free contribute and send pull requests.