GithubHelp home page GithubHelp logo

jasonbdaro / laravel-sharepoint-upload-client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jakub-klapka/laravel-sharepoint-upload-client

0.0 0.0 0.0 14 KB

Simple library for file uploading to Microsoft Sharepoint site

PHP 100.00%

laravel-sharepoint-upload-client's Introduction

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

laravel-sharepoint-upload-client's People

Contributors

jasonbdaro avatar jakub-klapka avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.