leapt / flysystem-onedrive
OneDrive API 的 Flysystem 适配器
v1.0.1
2022-08-29 12:46 UTC
Requires
- php: ^8.1
- league/flysystem: ^3.0
- microsoft/microsoft-graph: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.10.0
- phpstan/phpstan: ^1.8.2
- phpstan/phpstan-deprecation-rules: ^1.0.0
- phpunit/phpunit: ^9.5.23
- symfony/var-dumper: ^6.1
README
此包包含一个 OneDrive 的 Flysystem 适配器。底层使用 Microsoft Graph SDK。
安装
此包需要 PHP 8.1+ 和 Flysystem v3。
您可以使用 composer 安装此包
composer require leapt/flysystem-onedrive
使用方法
首先,您需要获取 Microsoft Graph API 的授权令牌。为此,您需要在 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');
获取令牌
如果您正在寻找获取令牌的方法,这里有两个示例
- 第一个示例使用 Symfony HTTP Client
- 第二个示例使用已作为依赖项包含的 Guzzle
使用 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'];
使用 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 了解最近更改的详细信息。
贡献
欢迎贡献,例如发送 pull requests 添加功能/测试或 创建问题 :)
请注意,有一些辅助工具可以维护代码质量,您可以使用以下命令运行
composer cs:dry # Code style check composer phpstan # Static analysis vendor/bin/phpunit # Run tests
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。
历史
此包是维护分支 nicolasbeauvais 和 hevelius 的包。