|
| 1 | +# Laravel Doctrine ApiKey |
| 2 | + |
| 3 | +[](https://github.com/API-Skeletons/laravel-doctrine-apikey/actions/workflows/continuous-integration.yml?query=branch%3Amain) |
| 4 | +[](https://codecov.io/gh/API-Skeletons/laravel-doctrine-apikey/branch/main) |
| 5 | +[](https://img.shields.io/badge/PHP-8.0-blue) |
| 6 | +[](//packagist.org/packages/api-skeletons/laravel-doctrine-apikey) |
| 7 | +[](//packagist.org/packages/api-skeletons/laravel-doctrine-apikey) |
| 8 | + |
| 9 | +This repository provides a driver for Doctrine which can be added to an existing entity manager. |
| 10 | +The driver provies a set of entities which enable ApiKey authorization through HTTP middleware. |
| 11 | +Scopes are supported! This was the missing piece of other repositories which catalyzed the creation of this library. |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +Run the following to install this library using [Composer](https://getcomposer.org/): |
| 16 | + |
| 17 | +```bash |
| 18 | +composer require api-skeletons/laravel-doctrine-apikey |
| 19 | +``` |
| 20 | + |
| 21 | +## Quick Start |
| 22 | + |
| 23 | +Add Service Provider to app.php |
| 24 | +```php |
| 25 | + 'providers' => [ |
| 26 | + ... |
| 27 | + ApiSkeletons\Laravel\Doctrine\ApiKey\ServiceProvider::class, |
| 28 | + ], |
| 29 | +``` |
| 30 | + |
| 31 | +Initialize the ApiKey service for your entity manager in `App\Providers\AppServiceProvider` |
| 32 | +```php |
| 33 | +use ApiSkeletons\Laravel\Doctrine\ApiKey\Service\ApiKeyService; |
| 34 | + |
| 35 | +public function boot() |
| 36 | +{ |
| 37 | + app(ApiKeyService::class)->init(app('em')); |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +Add an API key through the console |
| 42 | +```shell |
| 43 | +$ php artisan apikey:generate yourapikeyname |
| 44 | +``` |
| 45 | + |
| 46 | +Add the middleware to a protected route |
| 47 | +```php |
| 48 | +Route::name('api.resource::fetch') |
| 49 | + ->get('resource', 'ResourceController::fetch') |
| 50 | + ->middleware('auth.apikey'); |
| 51 | +``` |
| 52 | + |
| 53 | +Begin making requests to your ApiKey protected resource using you key as a Bearer token in the Authorization header |
| 54 | +```sh |
| 55 | +Authorization: Bearer {key} |
| 56 | +``` |
| 57 | + |
0 commit comments