codzo / middleware-authentication
Slim 4 Middleware for authentication
Installs: 44
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/codzo/middleware-authentication
Requires
- codzo/config: dev-master
- slim/psr7: ^1.2
Requires (Dev)
- codzo/phpcodesniffer-git-hook: dev-master
- phpunit/phpunit: ^9.2
This package is auto-updated.
Last update: 2025-11-29 03:17:59 UTC
README
Dependency
- Package
codzo/config
Settings
Require following settings exposured to codzo/config
-
authentication.validator.classnameThe classname of selected validator. If appointing multiple validators, using a comma to separate class names. The first validator successfully authenticated the use will provide an authentication identifier to app and end the process.
Provide full class name with namespaces.
Default value:
Codzo\Middleware\Authentication\Validator\SessionValidator. -
authentication.redirect.urlThe redirect url when authentication failed.
Default value:
/login.
See validators for more setting options.
How to authenticate
This middleware will call validators to authenticate.
A validator implements IAuthenticationValidator providing following functions:
-
isAuthenticated(Request $request=null) : boolcheck if authenticated. If not, redirect to `/Login'
-
getAuthenticationIdentifer() : stringget the identifier. See validators for specific data returned.
Validator
Built-in validators:
SessionValidator
Validate the data stored in session for authentication.
Settings:
-
authentication.sessionvalidator.session.varnameThe name of the session data. This is the key name of
$_SESSIONvariable.Example:
With setting as of
LOGIN_UUID,$_SESSION ['LOGIN__UUID']will be checked and returned. -
authentication.sessionvalidator.session.valueThe pattern of the expected identifier. If session data matches this pattern, current use will be considered as authenticated.
Example:
.*to match any string.