Download the PHP package julienlinard/auth-php without Composer
On this page you can find all versions of the php package julienlinard/auth-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download julienlinard/auth-php
More information about julienlinard/auth-php
Files in julienlinard/auth-php
Package auth-php
Short Description Système d'authentification complet pour PHP avec gestion des utilisateurs, rôles, permissions et sécurité
License MIT
Homepage https://github.com/julien-lin/auth-php
Informations about the package auth-php
Auth PHP - Complete Authentication System
🇬🇧 Read in English
💝 Support the project
If this bundle is useful to you, consider becoming a sponsor to support the development and maintenance of this open source project.
A complete and modern authentication system for PHP 8+ with user management, roles, permissions, customizable guards and integration with JulienLinard packages.
Current Version: 1.1.0 | Tests: 64 tests, 133 assertions (100% passing) | Strict Types: ✅ Enabled
📋 Table of Contents
- Installation
- Quick Start
- Configuration
- Authentication
- Roles and Permissions
- Middlewares
- User Providers
- Guards
- Hashers
- Integration with Other Packages
- API Reference
- Complete Examples
- Tests
🚀 Installation
Requirements:
- PHP 8.0 or higher
julienlinard/core-php(for Session)julienlinard/doctrine-php(for DatabaseUserProvider)
⚡ Quick Start
Minimal Example
📖 Configuration
Complete Configuration
Minimal Configuration
🔐 Authentication
Login with Credentials
Login with "Remember Me"
Direct Login (without password verification)
Logout
Checks
👥 Roles and Permissions
Check a Role
Check a Permission
Implementation in User Entity
🛡️ Middlewares
AuthMiddleware
Protects a route by requiring authentication.
Parameters:
$redirectTo(optional, default:'/login'): Route to redirect to if user is not authenticated (for GET requests)$auth(optional): AuthManager instance (automatically retrieved from container if not provided)
RoleMiddleware
Protects a route by requiring a specific role.
Parameters:
$roles(required): Role(s) required (string or array)$redirectTo(optional, default:null): Route to redirect to if user doesn't have the role (for GET requests). Ifnull, returns JSON error$auth(optional): AuthManager instance (automatically retrieved from container if not provided)
PermissionMiddleware
Protects a route by requiring a specific permission.
Parameters:
$permissions(required): Permission(s) required (string or array)$redirectTo(optional, default:null): Route to redirect to if user doesn't have the permission (for GET requests). Ifnull, returns JSON error$auth(optional): AuthManager instance (automatically retrieved from container if not provided)
GuestMiddleware
Protects a route by requiring that no user is authenticated (for login/registration pages).
Parameters:
$redirectTo(optional, default:'/'): Route to redirect to if user is already authenticated (for GET requests)$auth(optional): AuthManager instance (automatically retrieved from container if not provided)
Usage with Route Groups
🔌 User Providers
DatabaseUserProvider (default)
Uses doctrine-php to retrieve users from the database.
Custom User Provider
Create your own provider by implementing UserProviderInterface.
🛡️ Guards
SessionGuard (default)
Uses PHP sessions to store authentication state.
Custom Guard
Create your own guard by implementing GuardInterface.
🔒 Hashers
PasswordHasher (default)
Uses native PHP hash functions.
Custom Hasher
Create your own hasher by implementing HasherInterface.
🔗 Integration with Other Packages
Integration with core-php
Integration with doctrine-php
Integration with php-router
📚 API Reference
AuthManager
__construct(array $config)
Creates a new AuthManager instance.
attempt(array $credentials, bool $remember = false): bool
Attempts to authenticate a user with credentials.
login(UserInterface $user, bool $remember = false): void
Authenticates a user directly without password verification.
logout(): void
Logs out the current user.
check(): bool
Checks if a user is authenticated.
guest(): bool
Checks if no user is authenticated.
user(): ?UserInterface
Returns the currently authenticated user.
id(): int|string|null
Returns the ID of the currently authenticated user.
hasRole(string $role): bool
Checks if the user has a specific role.
can(string $permission): bool
Checks if the user has a specific permission.
guard(): GuardInterface
Returns the current guard.
💡 Complete Examples
Example 1: Complete Application with Authentication
🧪 Tests
The library includes a comprehensive test suite with 64 tests and 133 assertions, ensuring reliability and quality.
Test Coverage
- ✅ AuthManager: 9 tests (creation, verification, roles, permissions)
- ✅ PasswordHasher: 12 tests (hash, verify, rehash, different algorithms)
- ✅ SessionGuard: 11 tests (attempt, login, logout, check, user, session)
- ✅ DatabaseUserProvider: 8 tests (findById, findByCredentials, findByField)
- ✅ Middlewares: 13 tests (AuthMiddleware, GuestMiddleware, RoleMiddleware, PermissionMiddleware)
- ✅ Roles and Permissions: 10 tests (Authenticatable trait)
Test Results: 100% passing (64/64 tests)
Code Quality
- ✅ Strict Types: All 16 source files use
declare(strict_types=1) - ✅ Type Safety: Enhanced type hints with PHP 8 union types and
mixed - ✅ PHP 8.5+ Compatible: Full support for PHP 8.5+ features
📝 License
MIT License - See the LICENSE file for more details.
🤝 Contributing
Contributions are welcome! Feel free to open an issue or a pull request.
📧 Support
For any questions or issues, please open an issue on GitHub.
💝 Support the project
If this bundle is useful to you, consider becoming a sponsor to support the development and maintenance of this open source project.
Developed with ❤️ by Julien Linard
All versions of auth-php with dependencies
julienlinard/core-php Version ^1.0
julienlinard/doctrine-php Version ^1.0