jakub-klapka/laravel-sharepoint-upload-client

Simple library for file uploading to Microsoft Sharepoint site
11,194 7
Install
composer require jakub-klapka/laravel-sharepoint-upload-client
Latest Version:v1.0.2
PHP:>=5.6
License:MIT
Last Updated:Dec 28, 2020
Links: GitHub  ·  Packagist
Maintainer: jakub-klapka

Laravel Sharepoint Upload Client

Simple Client for uploading files to Sharepoint Online library. Integrated Laravel Service Provider.

Uses accesscontrol.windows.net OAuth2, so it works with MS ADFS or Azure AAD Authentication.

Usage:

Register ServiceProvider in your app.php:

\JakubKlapka\LaravelSharepointUploadClient\LaravelSharepointUploadProvider::class

Use Client factory to make Client instance:

class Controller {

	protected $sharepointClient;

	public function __construct( \JakubKlapka\LaravelSharepointUploadClient\Factories\ClientFactory $sharepointClient ) {
		$this->sharepointClient = $sharepointClient;
	}
	
	public function upload() {
		$client = $this->sharepointClient->makeClient( $site_url, $app_id, $app_secret, $redirect_uri );
	}

}

You will need those attributes, you can register Sharepoint App on: https://contoso.sharepoint.com/sites/MySite/_layouts/15/appregnew.aspx

Attribute Description Example
site_url Abosolute path to root of your sharepoint site https://contoso.sharepoint.com/sites/MySite
app_id ID of your app
app_secret Secret of your app
redirect_uri Redirect URI has to match the one, entered on appregnew.aspx https://myapp.com/shp-oauth/

Point you user to retrieve Consent:

$url = $client->getUserConsentUri()

Get refresh token from auth code, returned based on Consent:

$auth_code = $_REQUEST['code'];
$refreshToken = $client->getRefreshTokenFromAuthCode( $auth_code );

This client does not handle token persistence, feel free to save it to file/db/redis or wherever it is fit for your app.

Refresh token is valid for 6 months.

Use refresh token to upload a file

$upload_result = $client->uploadFile(
	$refresh_token,
	'/sites/mySite/myLibrary/',
	'file.txt',
	$this->transfer_storage->readStream( 'file.txt' )
);

Resources

Related Packages

socialiteproviders/microsoft-graph

Microsoft Graph OAuth2 Provider for Laravel Socialite

2,019,231 17
thomaswelton/laravel-oauth

Laravel package for the simplification and integration of many of your users mos...

961 41
socialiteproviders/microsoft-live

Microsoft Live OAuth2 Provider for Laravel Socialite

353,650 7
socialiteproviders/microsoft-azure

Microsoft Azure OAuth2 Provider for Laravel Socialite

7,679,779 60
socialiteproviders/sharepoint

SharePoint OAuth2 Provider for Laravel Socialite

112,416 0