PHPackages                             kynx/mezzio-authentication-apikey - 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. kynx/mezzio-authentication-apikey

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

kynx/mezzio-authentication-apikey
=================================

Authenticate users with an API key in Mezzio applications

1.3.2(2mo ago)0930[1 PRs](https://github.com/kynx/mezzo-authentication-apikey/pulls)BSD-3-ClausePHPPHP ~8.3.0 || ~8.4.0 || ~8.5.0CI passing

Since Jul 24Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/kynx/mezzo-authentication-apikey)[ Packagist](https://packagist.org/packages/kynx/mezzio-authentication-apikey)[ RSS](/packages/kynx-mezzio-authentication-apikey/feed)WikiDiscussions 1.3.x Synced 1mo ago

READMEChangelog (9)Dependencies (8)Versions (16)Used By (0)

kynx/mezzio-authentication-apikey
=================================

[](#kynxmezzio-authentication-apikey)

[![Continuous Integration](https://github.com/kynx/mezzo-authentication-apikey/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/kynx/mezzo-authentication-apikey/actions/workflows/continuous-integration.yml)

This package provides a [Mezzio Authentication](https://docs.mezzio.dev/mezzio-authentication/) adapter for logging in users with a well-structured API key.

For an overview of using authentication middleware in your Mezzio application, see the `mezzio/mezzio-authentication`[Introduction](https://docs.mezzio.dev/mezzio-authentication/v1/intro/).

To use this package to authenticate users you will need two things:

- A [User Repository](https://docs.mezzio.dev/mezzio-authentication/v1/user-repository/) that handles checking the user credentials against your persistent storage
- Your API key prefix. This string is prepended to the keys you generate to make them easy to identify

Choose your prefix carefully. It can be used by tools like [GitHub's Secret Scanner](https://docs.github.com/en/code-security/secret-scanning/about-secret-scanning) to find leaked keys. It should also provide enough information to help users and support identify the correct key to use. In the examples here we use `myco_sandbox` to show both the origin (`myco`) and the environment (`sandbox`) the key is used with. If you have ever integrated with Stripe, this pattern will be familiar.

Mezzio Authentication provides two user repositories out-the-box: `Htpasswd` and `PdoDatabase`. In the examples here we will use `PdoDatabase`. See the [PDO Configuration](https://docs.mezzio.dev/mezzio-authentication/v1/user-repository/#pdo-configuration) documentation for the additional steps needed to set that up.

Installation
------------

[](#installation)

```
composer require kynx/mezzio-authentication-apikey

```

Configuration
-------------

[](#configuration)

The configuration either can be stored in a file under the `/config/autoload/` folder or in your application or module's `ConfigProvider`.

To use an autoloaded configuration, ceate a `config/autoload/api.global.php` and add the following:

```
