Download the PHP package rougin/authsum without Composer
On this page you can find all versions of the php package rougin/authsum. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rougin/authsum
More information about rougin/authsum
Files in rougin/authsum
Informations about the package authsum
Authsum
Authsum
is a simple authentication package written in PHP which allows to create simple and extensible authentication logic.
Installation
Install the Authsum
package via Composer:
Basic usage
Prior in using Authsum
, a data source must be defined first (e.g., BasicSource
):
Once the source is defined, use the Authsum
class to perform the validation logic:
Customization
Authsum
also provides simple extensibility utilities to be able to fit in from various use-cases.
Pass or fail from Authsum
The Authsum
class can also be extended to provide methods if the validation logic passed or failed:
Alternatively, the Authsum
class can also get the error or the result after validation using getError()
and getResult()
respectively:
[!NOTE] An
UnexpectedValueException
will be thrown if trying to access an empty output (e.g., trying to accessgetResult()
after the failed validation).
Changing fields to check
By default, the Authsum
class can check the email
as its username and password
for the password from the payload (e.g., $_POST
). If this is not the case, kindly update the specified fields using setUsernameField
or setPasswordField
:
[!NOTE] The specified fields will be used by the
Authsum
class if they are required by the specified source (e.g.,BasicSource
,PdoSource
).
Using sources
Sources in Authsum
are PHP classes that provide user data. They can be used for checking the specified username and password fields against its data source:
PdoSource
Besides from BasicSource
, another available source that can be used is PdoSource
which uses PDO to interact with a database:
The setTableName
method can also be used to specify its database table name:
[!NOTE] If the
setTableName
is not specified, it always refer to theusers
table.
When using PdoSource
, the value in the password
field will be assumed as a hash (e.g., $2y$10...
). If this is not the case, kindly add the withoutHash
method:
Doing this will make a strict comparison of the provided password
against the result from the database.
JwtSource
The JwtSource
class is a special class that checks a user's authentication using JSON Web Token:
From the example above, initializing JwtSource
requires a JwtParserInterface
for parsing the JSON web tokens from payload:
If JwtSource
is used as a source, the token
field must be updated also from the Authsum
class based on the query parameter or parsed body where the token exists:
[!NOTE] If
setTokenField
is not specified, its default value istoken
.
Then use the setUsernameField
to specify the field to be compared against the parsed data from the JSON web token:
Creating custom sources
To create a custom source, kindly use the SourceInterface
for its implementation:
If the custom source requires an username
field, kindly add the WithUsername
interface:
The WithPassword
interface can be also added if the custom source requires a password to be defined:
Some custom sources may require to use the provided payload instead of username
and password
fields (e.g., JwtSource
). With this, kindly use the WithPayload
interface:
Testing
If there is a need to check the source code of Authsum
for development purposes (e.g., creating fixes, new features, etc.), kindly clone this repository first to a local machine:
After cloning, use Composer
to install its required packages:
[!NOTE] Please see also the build.yml of
Authsum
to check any packages that needs to be installed based on the PHP version.
Once the required packages were installed, kindly check the following below on how to maintain the code quality and styling guide when interacting the source code of Authsum
:
Unit tests
Authsum
also contains unit tests that were written in PHPUnit:
When creating fixes or implementing new features, it is recommended to run the above command to always check if the updated code introduces errors during development.
Code quality
To retain the code quality of Authsum
, a static code analysis code tool named PHPStan is being used during development. To start, kindly install the specified package in the global environment of Composer
:
Once installed, PHPStan
can now be run using its namesake command:
[!NOTE] When running
phpstan
, it will use thephpstan.neon
file which is already provided byAuthsum
.
Coding style
Aside from code quality, Authsum
also uses a tool named PHP Coding Standards Fixer for maintaining an opinionated style guide. To use this tooling, it needs also to be installed in the Composer
's global environment first:
After its installation, kindly use the php-cs-fixer
command in the same Authsum
directory:
The phpstyle.php
file provided by Authsum
currently follows the PSR-12 standard as its baseline for the coding style and uses Allman as its indentation style.
[!NOTE] Installing both
PHPStan
andPHP Coding Standards Fixer
requires a minimum version of PHP at least7.4
.
Changelog
Please see CHANGELOG for more information what has changed recently.
License
The MIT License (MIT). Please see LICENSE for more information.