Download the PHP package rafaelwendel/ci4auth without Composer

On this page you can find all versions of the php package rafaelwendel/ci4auth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package ci4auth

CI4Auth

Latest Version on Packagist PHP Version Require CodeIgniter 4 Support

CI4Auth is a lightweight, secure, and highly flexible authentication and authorization library specifically designed for the CodeIgniter 4 framework. It helps you seamlessly manage user logins, sessions, and role-based access control (RBAC) on your routes with minimal setup.


Features


Requirements


Installation

1. Install via Composer

Install the package using Composer inside your CodeIgniter 4 project root:

2. Publish the Configuration

Run the Spark command to publish the default configuration template file to your application's config directory:

This will copy the configuration template to app/Config/AuthConfig.php.


Configuration (AuthConfig.php)

Open the newly published app/Config/AuthConfig.php file. You can override any default properties by uncommenting them.

Here is a summary of the configuration properties:

Property Type Default Value Description
$authModel string 'App\Models\UserModel' The fully qualified class name of the User Model.
$findUserMethod string 'findUser' The method in the User Model used to search for the user (by email, username, etc.).
$passwordField string 'password' The database table column or object property that holds the hashed password.
$sessionAuthCheckKey string 'islogged' The session key used to check if the user is authenticated.
$enableRoles bool false Set to true to enable role-based access control (RBAC).
$roleKey string '' The session key representing the user's role (e.g. 'role', 'profile'). Required if $enableRoles is true.
$sessionData array See template A key-value map of data to be saved to the session on successful login. Use 'user.field' format to map fields from the user record.
$destroySessionOnLogout bool false If true, calls $session->destroy() on logout; if false, only removes $sessionData keys.
$notAuthenticatedRedirect string 'login' The route or URL path to redirect unauthenticated users.
$notAuthorizedRedirect string 'login' The route or URL path to redirect users with insufficient role permissions.

Example Mapping configuration:


Usage Guide

1. Setting Up Your User Model

Your User Model (e.g., App\Models\UserModel) must contain the method specified in $findUserMethod (default findUser). This method must return the user record as an object or an associative array matching the credentials identity (e.g., email or username).

2. User Authentication (Login)

In your Login Controller, check the user's credentials using the AuthService (which is auto-registered as a service).

3. User Logout

To log out the user, call the logout() method. It automatically removes the keys defined in $sessionData (or destroys the session if configured) and sets a localized flash message with the key logout_message.


Authorization & Route Protection

You can protect your application routes using the auto-discovered AuthFilter (aliased as 'auth').

Protecting Routes (No Roles)

To protect a group of routes so that only authenticated users can access them, apply the 'auth' filter in your app/Config/Routes.php file:

Protecting Routes with Role Authorization

If $enableRoles is set to true in your configuration, you can pass authorized roles to the filter by appending them as arguments (separated by commas):

When a user tries to access a restricted route without the appropriate role, they are redirected to the route defined by $notAuthorizedRedirect with an error message stored in the error flashdata key.


Localization & Custom Messages

CI4Auth comes with preloaded language files for Portuguese (Brazil) and English.

If you wish to customize these messages (for example, formatting flash alerts), you can override them by creating a file named Auth.php inside your own application directories:

Return an array containing only the keys you wish to override:


License

This library is open-source software licensed under the MIT License.


All versions of ci4auth with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rafaelwendel/ci4auth contains the following files

Loading the files please wait ...