PHPackages                             workupsrl/flysystem-sharepoint-adapter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. workupsrl/flysystem-sharepoint-adapter

ActiveLibrary[File &amp; Storage](/categories/file-storage)

workupsrl/flysystem-sharepoint-adapter
======================================

\[beta\] Adapter for flysystem to use sharepoint as filestore

1.0.4.002(2y ago)024MITPHPPHP ^8.0

Since Aug 24Pushed 2y agoCompare

[ Source](https://github.com/workupsrl/flysystem-sharepoint-adapter)[ Packagist](https://packagist.org/packages/workupsrl/flysystem-sharepoint-adapter)[ Docs](https://github.com/gwsn/packages/flysystem-sharepoint-adapter)[ RSS](/packages/workupsrl-flysystem-sharepoint-adapter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

Flysystem adapter for the Sharepoint Graph API
==============================================

[](#flysystem-adapter-for-the-sharepoint-graph-api)

This package contains a adapter for [Flysystem](https://flysystem.thephpleague.com/) to use Sharepoint as filestorage.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require workupsrl/flysystem-sharepoint-adapter
```

Usage
-----

[](#usage)

You need to request a new clientId and clientSecret for a new application on Azure.

1. Go to `Azure portal`
2. Go to `Active Directory`
3. Go to `App registrations`
4. Click on `new Registration` and follow the wizard.
    (give it a name like mine is 'gwsn-sharepoint-connector' and make a decision on the supported accounts, single tenant should be enough but this depends on your organisation)
5. When created the application is created write down the following details
6. 'Application (client) id', this will be your `$clientId`
7. 'Directory (tenant) id', this will be your `$tenantId`
8. Then we go in the menu to the `API permissions` to set the permissions that are required
9. The click on `Add a permission` and add the following permissions:
    Microsoft Graph:

    - Files.ReadWrite.All
    - Sites.ReadWrite.All
    - User.Read
10. Click on the `Grant admin consent for ...Company...`
11. Go in the menu to `Certificates & secrets`
12. Click on `new client secret`
13. Give it a description and expiry date and the value will be your `$clientSecret`
14. The last parameter will be the sharepoint 'slug', this is part of the url of the sharepoint site what you want to use and creation of sharepoint site is out of scope of this readme.
    When you sharepoint url is like `https://{tenant}.sharepoint.com/sites/{site-slug}/Shared%20Documents/Forms/AllItems.aspx`
    You need to set the `$sharepointSite` as `{site-slug}`

    Example:

    - Sharepoint site url: `https://GWSN.sharepoint.com/sites/gwsn-documents-store/Shared%20Documents/Forms/AllItems.aspx`
    - Sharepoint site variable: `$sharepointSite = 'gwsn-documents-store'`

```
use GWSN\FlysystemSharepoint\FlysystemSharepointAdapter;
use GWSN\FlysystemSharepoint\SharepointConnector;
use League\Flysystem\Filesystem;

$tenantId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
$clientId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
$clientSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$sharepointSite = 'your-path-to-your-site';

$connector = new SharepointConnector($tenantId, $clientId, $clientSecret, $sharepointSite);

$prefix = '/test'; // optional
$adapter = new FlysystemSharepointAdapter($connector, $prefix);

$flysystem = new Filesystem($adapter);
```

Testing
-------

[](#testing)

```
$ composer run-script test
```

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Laravel
-------

[](#laravel)

To use the flysystem in Laravel there are additional steps required:

First we need to create a `FlySystemSharepointProvider` and register this in the `config/app.php`

Then we need to create the config into the `config/filesystem.php`

### Create the FlySystemSharepointProvider

[](#create-the-flysystemsharepointprovider)

we need to create a provider to register the custom FlySystem Adapter

create a new file in the `app/Providers` directory called `FlySystemSharepointProvider.php` with the following content:

```
