samuelvi / spreadsheet-translator-provider-onedriveauth
Spreadsheet Translator - One Drive Provider with Authentication
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/samuelvi/spreadsheet-translator-provider-onedriveauth
Requires
- php: >=8.4
- guzzlehttp/guzzle: ^7.7
- samuelvi/spreadsheet-translator-core: ^8.0
Requires (Dev)
- mockery/mockery: ^1.6
- phpstan/phpstan: ^2.0
- phpstan/phpstan-mockery: ^2.0
- phpunit/phpunit: ^11.0
- rector/rector: ^2.1
README
This package provides a provider for the Spreadsheet Translator project that fetches shared spreadsheet documents from Microsoft OneDrive using OAuth 2.0 authentication.
Features
- OAuth 2.0 authentication with Microsoft Live
- Supports both direct access token and interactive authentication flow
- Downloads Excel files from OneDrive via the Microsoft Live API
- Integrates seamlessly with the Spreadsheet Translator ecosystem
- Built with modern PHP 8.4 features
Installation
Install via Composer:
composer require samuelvi/spreadsheet-translator-provider-onedriveauth
Requirements
- PHP >= 8.4
- Guzzle HTTP client ^7.7
- Microsoft Azure application credentials (client ID and secret)
- OneDrive file ID of the spreadsheet to fetch
Usage
Configuration Options
The provider requires the following configuration options:
client_id: Your Microsoft application client IDclient_secret: Your Microsoft application client secretcallback_uri: OAuth redirect URI configured in your Microsoft appdocument_id: The OneDrive file ID to fetchaccess_token: (Optional) Pre-obtained access tokenprompt_for_access_token: (Optional) Enable interactive OAuth flowprompt_access_token_browser: (Optional) Browser preference for OAuth (e.g., 'chrome', 'firefox')scopes: (Optional) Comma-separated OAuth scopes (e.g., 'wl.offline_access,wl.skydrive_update')
Example Configuration
use Atico\SpreadsheetTranslator\Core\Configuration\Configuration; use Atico\SpreadsheetTranslator\Provider\OneDriveAuth\OneDriveAuthProvider; $config = new Configuration([ 'provider' => [ 'options' => [ 'client_id' => 'your-client-id', 'client_secret' => 'your-client-secret', 'callback_uri' => 'http://localhost/callback', 'document_id' => 'file.abc123.ABC123', 'access_token' => 'your-access-token', // or use prompt_for_access_token 'temp_local_source_file' => '/tmp/spreadsheet.xlsx', 'format' => 'xlsx' ] ] ]); $provider = new OneDriveAuthProvider($config); $resource = $provider->handleSourceResource();
Interactive Authentication
If you don't have an access token, enable interactive authentication:
$config = new Configuration([ 'provider' => [ 'options' => [ 'client_id' => 'your-client-id', 'client_secret' => 'your-client-secret', 'callback_uri' => 'http://localhost/callback', 'document_id' => 'file.abc123.ABC123', 'prompt_for_access_token' => true, 'prompt_access_token_browser' => 'chrome', 'scopes' => 'wl.offline_access,wl.skydrive_update', 'temp_local_source_file' => '/tmp/spreadsheet.xlsx', 'format' => 'xlsx' ] ] ]);
Development
Available Commands
The project includes a Makefile with common development tasks:
make help # Show all available commands make install # Install dependencies make update # Update dependencies make test # Run unit tests make test-coverage # Run tests with coverage report make phpstan # Run PHPStan static analysis make rector # Run Rector to upgrade code make rector-dry # Run Rector in dry-run mode (preview changes) make lint # Run all linting tools make fix # Auto-fix code with Rector make clean # Clean generated files make all # Install, lint, and test make ci # Run CI pipeline
Running Tests
# Run all tests make test # Run tests with coverage make test-coverage # Run specific test vendor/bin/phpunit tests/AuthTest.php
Code Quality
# Static analysis with PHPStan (level 8 + Mockery extension) make phpstan # Code refactoring (dry-run) make rector-dry # Apply code refactoring make rector
Architecture
This provider implements the ProviderInterface from the Core package and consists of:
- OneDriveAuthProvider: Main provider class that orchestrates the OAuth flow
- Auth: Handles OAuth 2.0 authentication with Microsoft Live
- Client: OneDrive API client for fetching file content
- CommandLineAccessTokenManager: Interactive CLI tool for obtaining OAuth tokens
- OneDriveAuthConfigurationManager: Configuration management
Related Packages
- Core Bundle - Base interfaces and utilities
- Symfony Bundle - Symfony integration
Contributing
We welcome contributions to this project, including pull requests and issues (and discussions on existing issues).
If you'd like to contribute code but aren't sure what, the issues list is a good place to start. If you're a first-time code contributor, you may find Github's guide to forking projects helpful.
All contributors (whether contributing code, involved in issue discussions, or involved in any other way) must abide by our code of conduct.
Development Setup
- Clone the repository
- Run
make installto install dependencies - Run
make testto ensure tests pass - Make your changes
- Run
make lintto check code quality - Run
make testto verify tests still pass - Submit a pull request
License
Spreadsheet Translator OneDrive Auth Provider is licensed under the MIT License. See the LICENSE file for full details.