PHPackages                             zooxsmart/los-api-auth - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. zooxsmart/los-api-auth

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

zooxsmart/los-api-auth
======================

Auth Middleware for apis

1.0.2(2y ago)08.3k↓31.8%MITPHPPHP ^8.2

Since Sep 19Pushed 2y agoCompare

[ Source](https://github.com/zooxsmart/los-api-auth)[ Packagist](https://packagist.org/packages/zooxsmart/los-api-auth)[ GitHub Sponsors](https://github.com/Lansoweb)[ RSS](/packages/zooxsmart-los-api-auth/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (10)Versions (5)Used By (0)

Api Auth
========

[](#api-auth)

[![codecov](https://camo.githubusercontent.com/e195cce839092337f5a297d6e27194716bd4cac13718c0dcfbe353aefdd2731a/68747470733a2f2f636f6465636f762e696f2f67682f4c616e736f7765622f6170692d617574682f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d304949525a304759464e)](https://codecov.io/gh/Lansoweb/api-auth)[![GitHub license](https://camo.githubusercontent.com/52fb8a9cbdbbe47bd5e60f2b95c6f300f5dfd37a0ee4ab01b8791d22818d3b6b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4c616e736f7765622f6170692d61757468)](https://github.com/Lansoweb/api-auth/blob/1.0.x/LICENSE)[![GitHub Workflow Status](https://camo.githubusercontent.com/48e6328e2aee6b88413214fb58b4b4364a68e6bc063b51bf923aae4b30d13da0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f4c616e736f7765622f6170692d617574682f504850556e69742532307465737473)](https://camo.githubusercontent.com/48e6328e2aee6b88413214fb58b4b4364a68e6bc063b51bf923aae4b30d13da0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f4c616e736f7765622f6170692d617574682f504850556e69742532307465737473)[![GitHub release (latest by date)](https://camo.githubusercontent.com/626e1a59a301f0643311d0de1cc3b59d422f8f76d9ce22614fc20ae8ea8db976/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f4c616e736f7765622f6170692d61757468)](https://camo.githubusercontent.com/626e1a59a301f0643311d0de1cc3b59d422f8f76d9ce22614fc20ae8ea8db976/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f4c616e736f7765622f6170692d61757468)[![Packagist PHP Version Support](https://camo.githubusercontent.com/b1f7b7ca5b3677ca32fa1d3cc872c1a979ad806ae4e6781f1a1df23fa42b9112/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6c6f732f6170692d61757468)](https://camo.githubusercontent.com/b1f7b7ca5b3677ca32fa1d3cc872c1a979ad806ae4e6781f1a1df23fa42b9112/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6c6f732f6170692d61757468)

This library provides a PHP middleware for api authentication.

### Installation

[](#installation)

```
composer require los/api-auth
```

### Usage

[](#usage)

Using PSR-11 containers, use the provided factories and define factories for each requirement:

```
return [
    \Los\ApiAuth\ApiAuth::class => \Los\ApiAuth\ApiAuthFactory::class,
    \Los\ApiAuth\Strategy\Strategy::class => \Los\ApiAuth\Strategy\XApiKeyHeader::class,
    \Los\ApiAuth\Authenticator\Authenticator::class => \Los\ApiAuth\Authenticator\ArrayAuthenticatorFactory::class,
    \Los\ApiAuth\Output\Output::class => \Los\ApiAuth\Output\ProblemDetailsOutputFactory::class,
];
```

Then add the middleware to you pipeline:

```
$app->pipe(\Los\ApiAuth\ApiAuth::class);
```

If successful, the middleware will register a new Request attribute `Los\ApiAuth\Authenticator\Authenticator` with the identity found, so you can know which identity is authorized in the request.

If using [laminas](https://getlaminas.org), you can create a config/autoload/api-auth.global.php:

```
