Download the PHP package kynx/mezzio-authentication-apikey without Composer

On this page you can find all versions of the php package kynx/mezzio-authentication-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 mezzio-authentication-apikey

kynx/mezzio-authentication-apikey

Continuous Integration

This package provides a 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.

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

Choose your prefix carefully. It can be used by tools like GitHub's Secret Scanner 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 documentation for the additional steps needed to set that up.

Installation

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:

Alternately, if your application already has a ConfigProvider class, add the configuration above to that.

Piping vs Routing

If your entire application needs to be protected by API keys, add the authentication middleware to your config/pipeline.php, before the DispatchMiddleware is piped:

If only some routes need protecting, add the middleware to individual route pipelines in config/routes.php:

Changing the API Key Header

By default this package expects to find the API key in an X-API-Key request header. To use a different header name, add it to the configuration:

Advanced Configuration

This package uses kynx/api-key-generator to parse and generate API keys. That provides a number of options for setting the lengths of the keys and the characters used - see that package's documentation for full details. The defaults should be fine for the majority of use cases, but if needed you can change them in your configuration:

Please note that it is not recommended to change the characters used! See the notes on the default configuration for the rationale.

Fallback configurations

If you have already issued keys to your users and make changes to the primary key configuration, existing keys will stop working. To continue supporting the old keys, add the old settings to the fallbacks configuration:

Working with keys

kynx/api-key-generator provides a KeyGenerator for generating well-formed API keys. Only keys generated by the same key generator as used when parsing the header will be able to authenticate.

Generating a key

This will output an API key to share with your users. Something like:

Storing a key

The generated key contains methods to extract the content you will need to persist in your user repository:

The identifier should be stored un-hashed and in a case sensitive manner. For instance, in MySQL / MariaDB you would store it in a VARBINARY column with a unique index.

The secret must be hashed before storage. Use PHP's password_hash() for this.

To support rolling over API keys, you should store the keys in a separate table with a foreign key linking them to the user record. That way a user can have multiple keys. An example for MySQL might be:


All versions of mezzio-authentication-apikey with dependencies

PHP Build Version
Package Version
Requires php Version ~8.2.0 || ~8.3.0 || ~8.4.0
kynx/api-key-generator Version ^2.2
mezzio/mezzio-authentication Version ^1.8
psr/container Version ^1.0 || ^2.0
psr/http-factory Version ^1.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 kynx/mezzio-authentication-apikey contains the following files

Loading the files please wait ....