jakub-klapka / laravel-sharepoint-upload-client
Simple library for file uploading to Microsoft Sharepoint site
Installs: 3 803
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 3
Forks: 5
Open Issues: 2
Requires
- php: >=5.6
- guzzlehttp/guzzle: ^7.0
- laravel/framework: >=5.3
Requires (Dev)
- php: >=7.1
- phpunit/phpunit: ~5.5
This package is auto-updated.
Last update: 2024-10-28 18:29:53 UTC
README
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
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' ) );