CodeIgniter Shield
Shield is an authentication and authorization framework for CodeIgniter 4. While it does provide a base set of tools that are commonly used in websites, it is designed to be flexible and easily customizable.
The primary goals for Shield are:
- It must be very flexible and allow developers to extend/override almost any part of it.
- It must have security at its core. It is an auth lib after all.
- To cover many auth needs right out of the box, but be simple to add additional functionality to.
Authentication Methods
Shield provides two primary methods Session-based and Personal Access Codes of authentication out of the box.
It also provides JSON Web Tokens authentication.
Session-based
This is your typical email/username/password system you see everywhere. It includes a secure "remember me" functionality. This can be used for standard web applications, as well as for single page applications. Includes full controllers and basic views for all standard functionality, like registration, login, forgot password, etc.
Personal Access Codes
These are much like the access codes that GitHub uses, where they are unique to a single user, and a single user can have more than one. This can be used for API authentication of third-party users, and even for allowing access for a mobile application that you build.
JSON Web Tokens
JWT or JSON Web Token is a compact and self-contained way of securely transmitting information between parties as a JSON object. It is commonly used for authentication and authorization purposes in web applications.
Some Important Features
- Session-based authentication (traditional email/password with remember me)
- Stateless authentication using Personal Access Tokens
- Optional Email verification on account registration
- Optional Email-based Two Factor Authentication after login
- Magic Login Links when a user forgets their password
- Flexible groups-based access control (think roles, but more flexible)
- Users can be granted additional permissions
See the An Official Auth Library for more Info.
Getting Started
Prerequisites
Usage of Shield requires the following:
- A CodeIgniter 4.2.7+ based project
- Composer for package management
- PHP 7.4.3+
Installation
Installation is done through Composer.
composer require codeigniter4/shield
See the docs for more specific instructions on installation and usage recommendations.
Contributing
Shield does accept and encourage contributions from the community in any shape. It doesn't matter whether you can code, write documentation, or help find bugs, all contributions are welcome.
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
Acknowledgements
Every open-source project depends on it's contributors to be a success. The following users have contributed in one manner or another in making Shield:
Made with contrib.rocks.
The following articles/sites have been fundamental in shaping the security and best practices used within this library, in no particular order:
- Google Cloud: 13 best practices for user account, authentication, and password management, 2021 edition
- NIST Digital Identity Guidelines
- Implementing Secure User Authentication in PHP Applications with Long-Term Persistence (Login with "Remember Me" Cookies)
- Password Storage - OWASP Cheat Sheet Series