Skip to content

API-Skeletons/laravel-doctrine-apikey

Repository files navigation

Laravel Doctrine ApiKey

Build Status Code Coverage PHP Version Total Downloads License

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.

Installation

Run the following to install this library using Composer:

composer require api-skeletons/laravel-doctrine-apikey

Quick Start

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}

About

API keys with scopes for Laravel Doctrine

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages