Download the PHP package api-skeletons/laravel-doctrine-apikey without Composer

On this page you can find all versions of the php package api-skeletons/laravel-doctrine-apikey. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-doctrine-apikey

Laravel Doctrine ApiKey

Build Status Code Coverage PHP Version

This repository provides a driver for Doctrine which can be added to an existing entity manager.
The driver provides 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:

Quick Start

Add Service Provider to app.php

Add the route middleware to Http Kernel

Initialize the ApiKey service for your entity manager in App\Providers\AppServiceProvider

Add an API key through the console

Add the middleware to a protected route

Begin making requests to your ApiKey protected resource using your apikey as a Bearer token in the Authorization header

Schema

Screen Shot 2021-12-17 at 12 20 03 AM

Using Scopes

Scopes are permissions for ApiKeys. They are commonly used in OAuth2 and are less common in ApiKeys. Create a scope:

Security with scopes is applied with the same middleware used to authenticate ApiKeys. Replace {scopeName} with your scope's name and the middleware will ensure the passed ApiKey has that scope to continue.

Access to ApiKey through request attributes

The ApiKey entity which authenticates a request is assigned to the request attributes as 'apikey'.

Using foreign keys to ApiKey

Because an ApiKey can be regenerated, there may be no reason to assign multiple API keys to the same entity. For instance, if each Customer has a 1:1 with ApiKey then you can safely disable that key, regenerate it, and so on; never needing to assign a new ApiKey.

To dynamically create a 1:1 relationship between a Customer entity and API key, create an event subscriber:

Event Logging

Admin events are logged when an ApiKey is generated, activated, deactivated, add a scope, and remove a scope.

Access events are logged when the route middleware allows access to a resource.

Commands

Management of API keys is handled through the command line. However, full access to all data-creating functions is available through the Doctrine repositories: ApiKeyRepository and ScopeRepository.

Generate an ApiKey

Generate a Scope

Assign a Scope to an ApiKey

Deactivate an ApiKey

Activate an ApiKey

Unassign a Scope from an ApiKey

Regenerate an ApiKey (assign a new Bearer token)

Delete a Scope

Print ApiKey[s]

Print Scope[s]

Multiple object managers

The metadata included with this repository works fine across multiple object managers.
The commands included in this repository only work on the default ApiKeyService, so you will need an alternative method of maintaining data in the second object manager. In order to use multiple object managers you must do some configuration. Assuming you followed the Quick Start, above, follow these steps for a second object manager:

Create a new singleton of the ApiKeyService with a different name in App\Providers\AppServiceProvider

Initialize the ApiKey service for the second entity manager in App\Providers\AppServiceProvider

Copy the route middleware to a new class and use dependency injection for the ApiKeyService2

Inspired By

The repository https://github.com/ejarnutowski/laravel-api-key was the inispiration for this repository. It seemed a fine project but did not have unit tests or scopes.


All versions of laravel-doctrine-apikey with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
laravel-doctrine/orm Version ^2.0 || ^3.0
api-skeletons/laravel-api-problem Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package api-skeletons/laravel-doctrine-apikey contains the following files

Loading the files please wait ....