This repository provides a driver for Doctrine which can be added to an existing entity manager.
The driver provies a set of entities which enable ApiKey authorization through HTTP middleware.
Scopes are supported! This was the missing piece of other repositories which catalyzed the creation of this library.
Run the following to install this library using Composer:
composer require api-skeletons/laravel-doctrine-apikey
Add Service Provider to app.php
'providers' => [
...
ApiSkeletons\Laravel\Doctrine\ApiKey\ServiceProvider::class,
],
Initialize the ApiKey service for your entity manager in App\Providers\AppServiceProvider
use ApiSkeletons\Laravel\Doctrine\ApiKey\Service\ApiKeyService;
public function boot()
{
app(ApiKeyService::class)->init(app('em'));
}
Add an API key through the console
$ php artisan apikey:generate yourapikeyname
Add the middleware to a protected route
Route::name('api.resource::fetch')
->get('resource', 'ResourceController::fetch')
->middleware('auth.apikey');
Begin making requests to your ApiKey protected resource using you key as a Bearer token in the Authorization header
Authorization: Bearer {key}