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.
- π 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
- PHP 8.1 or higher
- Composer for dependency management
- Azure AD application for authentication
composer require grim-reapper/msgraph-php
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);
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');
use GrimReapper\MsGraph\Services\DocumentService;
$documentService = new DocumentService($graphClient);
// Convert DOCX to PDF
$convertedContent = $documentService->convertDocument(
'/Documents/document.docx',
'pdf'
);
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();
- API Documentation - Complete API reference
- Authentication Guide - Setup OAuth 2.0
- Examples - Code examples and use cases
- Contributing - Development guidelines
$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
]);
// Custom HTTP client
$httpClient = new GuzzleHttp\Client([
'timeout' => 30,
'headers' => ['User-Agent' => 'MyApp/1.0']
]);
$graphClient = new GraphClient($config, $httpClient);
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() |
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();
}
# 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"
This package implements security best practices:
- Secure token storage and refresh
- Input validation and sanitization
- Protection against common vulnerabilities
- HTTPS enforcement
- Rate limiting support
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
This project is licensed under the MIT License - see the LICENSE file for details.
- π Documentation
- π Issues
- π¬ Discussions
- π§ Email Support
See CHANGELOG.md for a list of changes and version history.
Made with β€οΈ by Grim Reapper Corp