Download the PHP package antogkou/laravel-oauth2-client without Composer
On this page you can find all versions of the php package antogkou/laravel-oauth2-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download antogkou/laravel-oauth2-client
More information about antogkou/laravel-oauth2-client
Files in antogkou/laravel-oauth2-client
Package laravel-oauth2-client
Short Description A Laravel package for OAuth2 integration
License MIT
Informations about the package laravel-oauth2-client
Laravel OAuth2 Client
A robust Laravel package for OAuth2 Client Credentials flow integration with automatic token management.
Features
- 🚀 Automatic Token Management - Handles token acquisition and refresh
- 🔧 Multiple Service Support - Configure multiple OAuth2 providers
- 📦 Caching - Stores tokens securely using Laravel Cache
- 📝 Structured Logging - Detailed error logging for failed requests
- 🛡️ Security - Sensitive data redaction in logs
- ✅ Laravel 11+ Ready - Full support for latest Laravel versions
Installation
Publish configuration file:
Configuration
Config File (config/oauth2-client.php
)
Environment Variables
Enabling IDE Autocompletion for Services
To enable IDE autocompletion for your OAuth2 service names in OAuth2::for('...')
, this package provides a type generation command:
This command scans your config/oauth2-client.php
and generates a PHP interface listing all configured service names. IDEs like PHPStorm and VSCode (with PHP Intelephense) will then offer autocompletion and static analysis for the available services.
Workflow:
- Add or update your services in
config/oauth2-client.php
under theservices
key. - Run
php artisan oauth2:generate-types
to regenerate the types. - Enjoy autocompletion in your IDE for
OAuth2::for('your_service')
.
Example:
After running the command, your IDE will suggest 'service1' and 'service2' in:
Usage
Basic API Calls
Request Options
The package supports various request options that can be passed as an array:
JSON Payload
Form Data
Multipart/Form-Data (File Uploads)
Custom Headers
Available Methods
Response Handling
Error Handling
The package throws Antogkou\LaravelOAuth2Client\Exceptions\OAuth2Exception
for errors:
Automatic JSON Error Responses
To make error handling seamless, you can configure your Laravel application's global exception handler to automatically return JSON responses for OAuth2 errors. This way, users of your API will always receive a structured JSON error response, and you don't need to manually catch exceptions in your controllers.
How to set up:
- Open (or create)
app/Exceptions/Handler.php
in your Laravel application. - Add the following to your
render
method:
Debug Mode:
- If you include an
X-Debug: 1
header or a?debug=1
query parameter in your request, the error response will include additional debug information (stack trace, exception class). - This is useful for development and debugging, but should be used with care in production.
Example error response (with debug):
This setup is optional but highly recommended for API projects using this package.
Testing
The package uses Pest PHP for testing. To run all tests:
To run only unit tests:
To run static analysis:
To check code style:
To test the artisan type generation command:
Adding New Services for Testing:
- Add your service to the
services
array inconfig/oauth2-client.php
. - Run the type generation command to update IDE support.
Troubleshooting & FAQ
Q: I added a new service but it doesn't autocomplete in my IDE.
- Run
php artisan oauth2:generate-types
after updating your config. - Restart your IDE if needed.
Q: I get an exception about missing or invalid service configuration.
- Ensure your service is correctly defined in
config/oauth2-client.php
. - Check for typos in the service name.
Q: How do I test error handling or simulate network/cache failures?
- See the feature tests for examples of simulating HTTP and cache errors using Laravel's testing tools.
Q: How do I contribute tests or features?
- See the 'Contributing' section below. All new features should include tests.
Contributing
Contributions welcome! Please follow:
- Fork the repository
- Create a feature branch
- Submit a pull request
License
MIT License - See LICENSE for details.
Support
For issues and feature requests, please create a GitHub issue.
All versions of laravel-oauth2-client with dependencies
laravel/framework Version ^11.0|^12.0
guzzlehttp/guzzle Version ^7.8