shiros / luna-web-authentication
Luna Module - Web Authentication
Package info
gitlab.com/shiros/luna/module/web-authentication
pkg:composer/shiros/luna-web-authentication
Requires
- php: >=8.5
- ext-openssl: *
- ext-sodium: *
- firebase/php-jwt: ^7.1
- shiros/luna: ^5.3
- shiros/luna-web: ^2.4
Requires (Dev)
- composer/composer: ^2.10
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.0
README
# Luna Module - Web Authentication A PHP Web Authentication module for the Luna Framework, focused on JWT, password hashing, and pluggable authentication middlewares. Robust, Flexible, and Developer-Friendly — securing your web applications with modern PHP.[[TOC]]
ℹ️ About the Project
This project is developed in PHP 8.2 and is part of the Luna Framework ecosystem.
The Luna Web Authentication Module provides JWT encoding/decoding, password utilities, middleware integration, and an extensible provider system to protect routes and handle authentication flows.
Detailed documentation is available in the Wiki: Luna Wiki.
Key Features
- JWT Support: Provides JWT support like encode, decode, and validate tokens
- Password Support: Provides password support. (Algorithm/options driven configuration)
- Middleware Integration: Provides middleware integration for routes.
- Dependency Injection: Seamless integration with Luna’s DI for service wiring.
- PSR-4 Autoloading: Clean and autoloaded code structure.
- PHP 8.2 Features: Implements modern PHP features for clean, predictable code.
🔧 Dependencies
It uses PHP 8.2+, ensuring compatibility with modern features.
This module depends on the following:
- Luna Framework: The Luna framework's core. (MIT License)
- firebase/php-jwt for JWT handling. (BSD-3-Clause License)
- PHP extensions:
- openssl (JWT signing/verification algorithms)
- sodium/libsodium (modern crypto support; recommended for JOSE/EdDSA)
- Development tools:
Refer to the composer.json file for additional details.
⚙️ Setup and Installation
To use the Luna Web Authentication module, follow the steps below:
Step 1: Install via Composer
Ensure Composer is installed, then execute the following in your root project folder:
composer require shiros/luna-web-authentication
Autoloading is handled by Composer (PSR‑4). When used within a Luna application, the module is auto‑discovered via
composer.json → luna.module:
{
"luna": {
"module": "Luna\\Web\\Authentication\\Module"
}
}
Step 2: Autoload the Module
The module supports PSR-4 autoloading. If you're using the Luna Framework, it’s automatically available via the Luna module declaration. Otherwise, make sure to include Composer’s autoloader:
require 'vendor/autoload.php';
🚀 Usage Example
Refer to the official documentation for advanced examples and further details.
📄 Testing
This project uses PHPUnit for testing, you can run the test suite as follows.
Step 1: Install development dependencies
Before running the test suite, ensure all project dependencies, including development dependencies, are installed. Use Composer to handle this:
composer install
This command will fetch all the required libraries and ensure your project setup is complete.
Step 2: Create the test environment file
The test suite reads its environment from the path configured as ENV_PATH in phpunit.xml (./env.test, extension
auto-detected). This file isn't committed, so create it locally by copying the committed template
env.php.dist:
cp env.php.dist env.test.php
The env.php.dist file contains %TOKEN%-style placeholders (e.g. %LUNA_ENV%) that are resolved from system
environment variables at runtime.
From there, you have two options:
Use system environment variables (recommended, matches what CI does) — export the tokens referenced by
env.test.phpbefore running the tests:export LUNA_ENV=testEdit the copy directly — replace the placeholder (s) in
env.test.phpwith a literal value, e.g.'Environment' => '%LUNA_ENV%'becomes'Environment' => 'test'. Sinceenv.test.phpis a local, untracked copy, this never risks committing the value.
The CI pipeline runs the exact same copy step, with LUNA_ENV (and any future token) declared as a CI/CD variable. This
keeps the pipeline script immutable — the only file to maintain when adding a new environment key (or secret)
is env.php.dist.
Step 3: Execute the Test Suite
Once dependencies are installed, you can execute the test suite using PHPUnit.
This ensures all the functionality of the framework is working as expected:
vendor/bin/phpunit --configuration phpunit.xml --colors=always
The test results will be displayed in your console. Colored output simplifies understanding the testing status:
- Green: Tests passed successfully.
- Red: Tests failed.
- Yellow: Warnings or skipped tests.
For more details on the tests, explore the /tests directory. It contains comprehensive unit tests covering various
parts of the framework.
📃 License
This project is licensed under the MIT License, allowing you to use and modify this project freely.
See the LICENSE file for more details.
👨💻 Authors and Contributors
This project was created and is maintained by Alexandre Caillot (Shiroe_sama), with contributions from the community.
Authors
Contributors
We thank the following contributors for making this project better: