leapt/flysystem-onedrive
最新稳定版本:v1.1.0
Composer 安装命令:
composer require leapt/flysystem-onedrive
包简介
Flysystem Adapter for the OneDrive API
README 文档
README
This package contains a Flysystem adapter for OneDrive. Under the hood, the Microsoft Graph SDK is used.
Installation
This package requires PHP 8.3+ and Flysystem v3.
You can install the package using composer:
composer require leapt/flysystem-onedrive
Usage
The first thing you need to do is get an authorization token for the Microsoft Graph API. For that you need to create an app on the Microsoft Azure Portal.
use League\Flysystem\Filesystem; use Leapt\FlysystemOneDrive\OneDriveAdapter; use Microsoft\Graph\Graph; $graph = new Graph(); $graph->setAccessToken('EwBIA8l6BAAU7p9QDpi...'); $adapter = new OneDriveAdapter($graph); $filesystem = new Filesystem($adapter); // Or to use the approot endpoint: $adapter = new OneDriveAdapter($graph, 'special/approot');
Retrieve a bearer token
If you are looking for a way to retrieve a bearer token, here are two examples:
- first example using Symfony HTTP Client
- second example using Guzzle, which is already included as a dependency from Microsoft Graph SDK
Using Symfony HTTP Client
$tenantId = 'your tenant id'; $clientId = 'your client id'; $clientSecret = 'your client secret'; $scope = 'https://graph.microsoft.com/.default'; $oauthUrl = sprintf('https://login.microsoftonline.com/%s/oauth2/v2.0/token', $tenantId); $client = \Symfony\Component\HttpClient\HttpClient::create(); $response = $client->request('GET', $oauthUrl, ['body' => [ 'client_id' => $clientId, 'scope' => $scope, 'grant_type' => 'client_credentials', 'client_secret' => $clientSecret, ]]); $bearerToken = $response->toArray()['access_token'];
Using Guzzle
$tenantId = 'your tenant id'; $clientId = 'your client id'; $clientSecret = 'your client secret'; $scope = 'https://graph.microsoft.com/.default'; $oauthUrl = sprintf('https://login.microsoftonline.com/%s/oauth2/v2.0/token', $tenantId); $client = new \GuzzleHttp\Client(); $response = $client->request('POST', $oauthUrl, ['form_params' => [ 'client_id' => $clientId, 'scope' => $scope, 'grant_type' => 'client_credentials', 'client_secret' => $clientSecret, ]]); $bearerToken = json_decode((string) $response->getBody(), true)['access_token'];
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Feel free to contribute, like sending pull requests to add features/tests or creating issues :)
Note there are a few helpers to maintain code quality, that you can run using these commands:
composer cs:dry # Code style check composer phpstan # Static analysis vendor/bin/phpunit # Run tests
License
The MIT License (MIT). Please see License File for more information.
History
This bundle is a maintained fork of the packages nicolasbeauvais and hevelius.
统计信息
- 总下载量: 638
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-08-29