grim-reapper/msgraph-php
Composer 安装命令:
composer require grim-reapper/msgraph-php
包简介
A comprehensive PHP package for Microsoft Graph API integration with OAuth 2.0 authentication, OneDrive file management, and document conversion capabilities
README 文档
README
A comprehensive and robust PHP package for integrating with Microsoft Graph API, providing seamless access to Microsoft 365 services including OneDrive, Outlook, Calendar, Teams, and more.
Features
- 🚀 OAuth 2.0 Authentication - Secure authentication with Azure Active Directory
- 📁 OneDrive Integration - Complete file management capabilities
- 📄 Document Conversion - Convert documents (DOCX to PDF, etc.)
- 📧 Email Operations - Send, read, and manage emails
- 📅 Calendar Management - Create and manage events
- 👥 User Management - User profiles and presence
- 🔒 Enterprise Security - Production-ready security practices
- 🧪 Comprehensive Testing - Unit and integration tests
- 📚 Rich Documentation - Complete API documentation and examples
Requirements
- PHP 8.1 or higher
- Composer for dependency management
- Azure AD application for authentication
Installation
composer require grim-reapper/msgraph-php
Quick Start
1. Authentication Setup
First, create an Azure AD application and obtain your credentials:
use GrimReapper\MsGraph\Authentication\AuthConfig; use GrimReapper\MsGraph\Core\GraphClient; $config = new AuthConfig([ 'clientId' => 'your-client-id', 'clientSecret' => 'your-client-secret', 'tenantId' => 'your-tenant-id', 'redirectUri' => 'https://yourapp.com/callback' ]); $graphClient = new GraphClient($config);
2. OneDrive Operations
use GrimReapper\MsGraph\Services\OneDriveService; $oneDrive = new OneDriveService($graphClient); // List files $files = $oneDrive->listFiles('/'); // Upload a file $oneDrive->uploadFile('/path/to/local/file.pdf', 'Documents/file.pdf'); // Download a file $content = $oneDrive->downloadFile('/Documents/file.pdf');
3. Document Conversion
use GrimReapper\MsGraph\Services\DocumentService; $documentService = new DocumentService($graphClient); // Convert DOCX to PDF $convertedContent = $documentService->convertDocument( '/Documents/document.docx', 'pdf' );
4. Email Operations
use GrimReapper\MsGraph\Services\MailService; $mailService = new MailService($graphClient); // Send email $mailService->sendEmail([ 'to' => 'recipient@example.com', 'subject' => 'Test Email', 'body' => 'This is a test email from Microsoft Graph PHP' ]); // Read emails $messages = $mailService->getMessages();
Documentation
- API Documentation - Complete API reference
- Authentication Guide - Setup OAuth 2.0
- Examples - Code examples and use cases
- Contributing - Development guidelines
Configuration
Authentication Options
$config = new AuthConfig([ 'clientId' => 'your-client-id', 'clientSecret' => 'your-client-secret', 'tenantId' => 'your-tenant-id', 'redirectUri' => 'https://yourapp.com/callback', 'scopes' => ['https://graph.microsoft.com/.default'], 'cache' => new FileCache(), // Optional: Custom cache implementation 'logger' => new Logger(), // Optional: Custom logger ]);
Advanced Configuration
// Custom HTTP client $httpClient = new GuzzleHttp\Client([ 'timeout' => 30, 'headers' => ['User-Agent' => 'MyApp/1.0'] ]); $graphClient = new GraphClient($config, $httpClient);
Services Overview
| Service | Description | Key Methods |
|---|---|---|
OneDriveService |
File management | uploadFile(), downloadFile(), listFiles(), deleteFile() |
DocumentService |
Document conversion | convertDocument(), getSupportedFormats() |
MailService |
Email operations | sendEmail(), getMessages(), getMessage() |
CalendarService |
Calendar management | createEvent(), getEvents(), updateEvent() |
UserService |
User management | getUser(), getUsers(), getUserPhoto() |
Error Handling
use GrimReapper\MsGraph\Exceptions\GraphException; use GrimReapper\MsGraph\Exceptions\AuthenticationException; try { $files = $oneDrive->listFiles('/'); } catch (AuthenticationException $e) { // Handle authentication errors echo "Authentication failed: " . $e->getMessage(); } catch (GraphException $e) { // Handle API errors echo "Graph API error: " . $e->getMessage(); } catch (Exception $e) { // Handle other errors echo "General error: " . $e->getMessage(); }
Testing
# Run all tests composer test # Run with coverage composer test:coverage # Run only unit tests composer test -- --testsuite "Unit Tests" # Run only integration tests composer test -- --testsuite "Integration Tests"
Security
This package implements security best practices:
- Secure token storage and refresh
- Input validation and sanitization
- Protection against common vulnerabilities
- HTTPS enforcement
- Rate limiting support
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Run tests (
composer test) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- 📖 Documentation
- 🐛 Issues
- 💬 Discussions
- 📧 Email Support
Changelog
See CHANGELOG.md for a list of changes and version history.
Made with ❤️ by Grim Reapper Corp
grim-reapper/msgraph-php 适用场景与选型建议
grim-reapper/msgraph-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「oauth2」 「sdk」 「graph」 「azure」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 grim-reapper/msgraph-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 grim-reapper/msgraph-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 grim-reapper/msgraph-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
A PSR-7 compatible library for making CRUD API endpoints
Email Toolkit Plugin for CakePHP
The missing social authentication for thephpleague/oauth2-server, adapted from schedula/league-oauth2-social
Alfabank REST API integration
Oauth 2 client for Ubiquity framework
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-28