jusbrasil / tornado-auth-php
Tornado Web Authentication in PHP
Requires
- php: >=7.3
This package is auto-updated.
Last update: 2023-11-06 11:50:20 UTC
README
Tornado Auth PHP
Implementation of Tornado Web Authentication in PHP.
Getting Started
First, you need to have the composer
installed. After this, run the require
command of composer
to install the package as your project dependency.
composer require jusbrasil/tornado-auth-php
Usage
namespace
use Jusbrasil\TornadoAuthPhp\TornadoAuthPhpLib;
configure ( array[string] mixed $options ) : void
max_age_days
- Number of days that the signature is valid.user_cookie
- The name of the cookie.secret_key
- The secret key used to decrypt the signed value.
$auth = new TornadoAuthPhpLib([ 'max_age_days' => 2, // [optional] default: (int) 31 'user_cookie' => 'oreo', // [optional] default: (string) user 'secret_key' => 'shhhh', // [required] ]); // void
createSignedValue ( mixed $value ) : string
Sign the passed value.
$signedValue = $auth->createSignedValue(['cypher' => 'morpheus']); // string(80) "eyJjeXBoZXIiOiJtb3JwaGV1cyJ9|1564713616|ca4f8c77f23f120578e742199b12df21f6039ce3"
createSignedCookie( string $cookieName, mixed $value ) : string
Sign the passed value.
$signedCookie = $auth->createSignedCookie('oreo', ['cypher' => 'morpheus']); // string(80) "eyJjeXBoZXIiOiJtb3JwaGV1cyJ9|1564713616|07143659017c55c004108de1e8b3867a8a5a889d"
decodeSignedValue ( string $secret, string $name, string $value [, int $maxAgeDays ] ) : string
Decode the signed value into string.
$decodedSignedValue = $auth->decodeSignedValue('shhhh', 'oreo', $signedValue); // string(21) "{"cypher":"morpheus"}"
getSecureCookie ( string $cookieName, string $value [, int $maxAgeDays ] ) : object
$secureCookie = $auth->getSecureCookie('oreo', $signedValue); // class stdClass { // public $cypher => string(8) "morpheus" // }
getCurrentUser ( mixed $value [, int $maxAgeDays ] ) : object
$currentUser = $auth->getCurrentUser($signedValue); // class stdClass { // public $cypher => string(8) "morpheus" // }
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
Prerequisites
Installing
Clone the repository
git clone git@github.com:jusbrasil/tornado-auth-php.git
Set up the development environment
docker-compose up -d --build
Access the container
docker-compose exec app ash
Or, run directly the command that you want (e.g.)
docker-compose exec app php src/index.php
Versioning
We use SemVer for versioning. Given a version number MAJOR.MINOR.PATCH, increment the:
MAJOR
major changes or a defined group of features that belongs to the same scopeMINOR
a new feature or refactoring an existing featurePATCH
fixing a bug or improving something from the latest stable version
For the versions available, see the tags on this repository.
Built With
- PHP
v7.3.8
- Hypertext Preprocessor - Composer
v1.9.0
- Dependency Manager for PHP
License
This project is licensed under the MIT License - see the LICENSE file for details
Acknowledgments
- Based on tornado-auth-js