Download the PHP package dotkernel/dot-authentication-service without Composer
On this page you can find all versions of the php package dotkernel/dot-authentication-service. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dotkernel/dot-authentication-service
More information about dotkernel/dot-authentication-service
Files in dotkernel/dot-authentication-service
Package dot-authentication-service
Short Description DotKernel authentication service component based on laminas-authentication
License MIT
Informations about the package dot-authentication-service
[!IMPORTANT] dot-authentication-service is a wrapper on top of laminas/laminas-authentication
[!CAUTION]
Security-Only Maintenance Mode
This package is considered feature-complete, and is now in security-only maintenance mode.
dot-authentication-service
Concrete authentication service implementation of \Dot\Authentication\AuthenticationInterface
built using laminas-authentication authentication and storage adapters. We advise you to have a quick look at how laminas authentication works, by visiting the documentation
Installation
Run the following command in your project directory
Add the ConfigProvider
class to your configuration aggregate, to register the default services.
Usage
You'll usually inject the authentication service into your classes and use its methods, as described by its interface at dot-authentication
When creating the authentication service, you'll have to provide an authentication AdapterInterface and a StorageInterface.
We already provide some default implementations of authentication adapters and storage adapters, with the possibility to write your custom ones.
We also provide a convenient factory class that configures an authentication service based on configuration.
Just merge the package's ConfigProvider
output to your application config in order to register all the required dependencies.
Authentication adapters
Used by the authentication service to check the credentials against some backend. Can be easily exchanged with various implementations depending on the authentication type or backend type.
An \Dot\Authentication\Adapter\AdapterInterface
is provided which must be implemented by all adapters. Also, adapters should be registered in the \Dot\Authentication\Adapter\AdapterPluginManager
service. More on this in the writing custom adapters section.
The AdapterInterface defines the following methods
-
called internally by the authentication service, just before the authentication operation, in order to give the adapter a chance to prepare itself, by extracting the credentials from the request, in its specific manner.
- checks the credentials extracted from the previous step, against some backend. Should return an
\Dot\Authentication\AuthenticationResult
This method is optional, it depends on the authentication type if a challenge response is required. It should return a ResponseInterface with status code 401 and a WWW-Authenticate header to indicate authentication is required.
HttpAdapter
This adapter provides HTTP basic and digest authentication. It is built around the laminas-authentication http adapter class. It actually wraps the laminas authentication http adapter, which can be configured by sending in the $config parameter as described by the laminas-authentication official documentation. We'll describe later how to configure an authentication service with such an adapter.
When authenticating, this adapter extracts the credentials from the request's Authorization
header.
CallbackCheckAdapter
Use to authenticate request against a MySQL backend. It is called so, because it accepts a callback as one of its parameters, which is called to check the password according to specific needs(md5, bcrypt etc.) It also wraps a laminas-authentication adapter with the same name, so much of its initialization is linked to that adapter. We'll describe later how to configure such an adapter.
This adapter requires that before calling the authentication service's authenticate method, you should manually extract the credentials from your request(POST) and initialize a DbCredentials
class with it.
It does not make assumptions on where the credentials should be in the request. It searches for a specific attribute instead, which you should add before authenticating.
After extracting the credentials into a DbCredentials
class, set this as a $request attribute at key DbCredentials::class
.
Identity prototype and hydrator
Both these adapters require an identity prototype object and an optional hydrator class(ClassMethods by default)
When successfully authenticating, it will hydrate the prototype with the user data and return it inside the AuthenticationResult
.
Storage adapters
Used by the authentication service to store the authenticated identity in some kind of persistent storage.
All storage adapters must implement the \Dot\Authentication\Storage\StorageInterface
interface.
This interface extends the \Laminas\Authentication\Storage\StorageInterface
. No additional interface methods are defined for now.
Also, storage adapters should be registered in the \Dot\Authentication\Storage\StoragePluginManager
.
SessionStorage
It extends the Laminas\Authentication\Storage\Session
class, providing the same functionality, with the only difference that on each write call, it will regenerate the session id.
This is to prevent session fixation attacks, we renew the session id when user sign in.
You can find more details on this storage adapter in laminas-authentication official documentation. We'll also give you an example in the following documentation on how to configure such an adapter.
NonPersistenStorage
It extends the Laminas\Authentication\Storage\NonPersistent
class. As its name suggests, it does not store the identity persistently. It will be lost after script finishes running.
Useful for API implementations, where authentication is stateless.
Configuring an AuthenticationService
First of all, make sure you merge this package's ConfigProvider
output to your application's config. This will add all necessary dependencies to your application, including the convenient factories.
Create a separate config file in your config/autoload
directory, call it authentication.global.php for example.
authentication.global.php
To define a http basic adapter you can define a configuration as below:
All versions of dot-authentication-service with dependencies
psr/http-message Version ^1.0 || 2.0
laminas/laminas-servicemanager Version ^3.11.2
laminas/laminas-hydrator Version ^4.3.1
dotkernel/dot-authentication Version ^2.1
laminas/laminas-authentication Version 2.16.0
laminas/laminas-db Version ^2.15.0
laminas/laminas-session Version ^2.12.1
laminas/laminas-psr7bridge Version ^1.6.0