{"id":13609050,"url":"https://github.com/lonnieezell/myth-auth","last_synced_at":"2025-05-15T01:06:23.657Z","repository":{"id":37706299,"uuid":"111507969","full_name":"lonnieezell/myth-auth","owner":"lonnieezell","description":"One-stop Auth package for CodeIgniter 4","archived":false,"fork":false,"pushed_at":"2024-04-25T02:46:31.000Z","size":3368,"stargazers_count":643,"open_issues_count":20,"forks_count":204,"subscribers_count":31,"default_branch":"develop","last_synced_at":"2025-04-13T22:39:36.215Z","etag":null,"topics":["authentication","codeigniter4"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lonnieezell.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["lonnieezell","mgatner"],"patreon":"lonnieezell"}},"created_at":"2017-11-21T06:18:48.000Z","updated_at":"2025-04-05T09:21:26.000Z","dependencies_parsed_at":"2024-05-27T19:10:07.494Z","dependency_job_id":null,"html_url":"https://github.com/lonnieezell/myth-auth","commit_stats":{"total_commits":452,"total_committers":63,"mean_commits":7.174603174603175,"dds":0.7079646017699115,"last_synced_commit":"da3522738a3076d579af3c060a65eefd8b800aba"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lonnieezell%2Fmyth-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lonnieezell%2Fmyth-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lonnieezell%2Fmyth-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lonnieezell%2Fmyth-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lonnieezell","download_url":"https://codeload.github.com/lonnieezell/myth-auth/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254254040,"owners_count":22039792,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","codeigniter4"],"created_at":"2024-08-01T19:01:32.077Z","updated_at":"2025-05-15T01:06:22.116Z","avatar_url":"https://github.com/lonnieezell.png","language":"PHP","funding_links":["https://github.com/sponsors/lonnieezell","https://github.com/sponsors/mgatner","https://patreon.com/lonnieezell"],"categories":["auth","PHP"],"sub_categories":[],"readme":"# Myth:Auth\n\n[![](https://github.com/lonnieezell/myth-auth/workflows/PHPUnit/badge.svg)](https://github.com/lonnieezell/myth-auth/actions/workflows/phpunit.yml)\n[![](https://github.com/lonnieezell/myth-auth/workflows/PHPStan/badge.svg)](https://github.com/lonnieezell/myth-auth/actions/workflows/phpstan.yml)\n[![](https://github.com/lonnieezell/myth-auth/workflows/Deptrac/badge.svg)](https://github.com/lonnieezell/myth-auth/actions/workflows/deptrac.yml)\n[![Coverage Status](https://coveralls.io/repos/github/lonnieezell/myth-auth/badge.svg?branch=develop)](https://coveralls.io/github/lonnieezell/myth-auth?branch=develop)\n\nFlexible, Powerful, Secure auth package for CodeIgniter 4.\n\n## Project Notice\n\nAs of [June 2022](https://forum.codeigniter.com/showthread.php?tid=82003) CodeIgniter now has an official\nAuthentication library, [CodeIgniter Shield](https://www.codeigniter.com/user_guide/libraries/official_packages.html#shield).\nIf you are looking for an authentication solution for a new project then that is the recommended solution.\n\nThis project is now maintained by volunteers. If you interact with the project repository there may be delays\nin receiving response. Please direct support questions to [GitHub Discussions](https://github.com/lonnieezell/myth-auth/discussions)\nor to CodeIgniter's [Forums](https://forum.codeigniter.com/forumdisplay.php?fid=34) or [Slack Channel](https://codeigniterchat.slack.com/).\n\n## Requirements\n\n- PHP 7.4+, 8.0+\n- CodeIgniter 4.1+\n\n## Features\n\nThis is meant to be a one-stop shop for 99% of your web-based authentication needs with CI4. It includes\nthe following primary features: \n\n- Password-based authentication with remember-me functionality for web apps\n- Flat RBAC per NIST standards, described [here](https://csrc.nist.gov/Projects/Role-Based-Access-Control) and [here](https://pdfs.semanticscholar.org/aeb1/e9676e2d7694f268377fc22bdb510a13fab7.pdf).\n- All views necessary for login, registration and forgotten password flows.\n- Publish files to the main application via a CLI command for easy customization\n- Debug Toolbar integration\n- Email-based account verification\n\n## Installation\n\nInstallation is best done via Composer. Assuming Composer is installed globally, you may use\nthe following command: \n```shell\n    \u003e composer require myth/auth\n```\n\nThis will add the latest stable release of **Myth:Auth** as a module to your project.\n\n### Manual Installation\n\nShould you choose not to use Composer to install, you can clone or download this repo and\nthen enable it by editing **app/Config/Autoload.php** and adding the `Myth\\Auth`\nnamespace to the `$psr4` array. For example, if you copied it into **app/ThirdParty/**:\n```php\n    $psr4 = [\n        'Config'      =\u003e APPPATH . 'Config',\n        APP_NAMESPACE =\u003e APPPATH,\n        'App'         =\u003e APPPATH,\n        'Myth\\Auth'   =\u003e APPPATH . 'ThirdParty/myth-auth/src',\n    ];\n```\n\n### Upgrading\n\nBe sure to check the [Changes Docs](https://github.com/lonnieezell/myth-auth/blob/develop/docs/_changes.md)\nfor necessary steps to take after upgrading versions.\n\n## Configuration\n\nOnce installed you need to configure the framework to use the **Myth\\Auth** library.\nIn your application, perform the following setup: \n\n1. Edit **app/Config/Email.php** and verify that a **fromName** and **fromEmail** are set \n    as that is used when sending emails for password reset, etc. \n\n2. Edit **app/Config/Validation.php** and add the following value to the **ruleSets** array: \n    `\\Myth\\Auth\\Authentication\\Passwords\\ValidationRules::class`\n\n3. Ensure your database is setup correctly, then run the Auth migrations: \n```shell\n    \u003e php spark migrate -all  \n```\n\nNOTE: This library uses your application's cache settings to reduce database lookups. If you want\nto make use of this, simply make sure that your are using a cache engine other than `dummy` and \nit is properly setup. The `GroupModel` and `PermissionModel` will handle caching and invalidation\nin the background for you.\n\n## Overview\n\nWhen first installed, Myth:Auth is setup to provide all of the basic authentication services \nfor you, including new user registration, login/logout, and forgotten password flows.\n\n\"Remember Me\" functionality is turned off by default though it can be turned on \nby setting the `$allowRemembering` variable to be `true` in Config/Auth.php.\n\n### Routes\n\nRoutes are defined in Auth's **Config/Routes.php** file. This file is automatically located by CodeIgniter\nwhen it is processing the routes. If you would like to customize the routes, you should copy the file\nto the **app/Config** directory, update the namespace, and make your route changes there. You\nmay also use the `$reservedRoutes` property of `Config\\Auth` to redirect internal route names.\n\n### Views\n\nBasic views are provided that are based on [Bootstrap 4](https://getbootstrap.com/) for all features.\n\nYou can easily override the views used by editing **Config/Auth.php**, and changing the appropriate\nvalues within the `$views` variable: \n\n    public $views = [\n        'login'       =\u003e 'Myth\\Auth\\Views\\login',\n        'register'    =\u003e 'Myth\\Auth\\Views\\register',\n        'forgot'      =\u003e 'Myth\\Auth\\Views\\forgot',\n        'reset'       =\u003e 'Myth\\Auth\\Views\\reset',\n        'emailForgot' =\u003e 'Myth\\Auth\\Views\\emails\\forgot',\n    ];\n\nNOTE: If you're not familiar with how views can be namespaced in CodeIgniter, please refer to \n[the CodeIgniter User Guide](https://codeigniter.com/user_guide/general/modules.html) for section\non Code Module support. \n\n## Services\n\nThe following Services are provided by the package: \n\n**authentication** \n\nProvides access to any of the authentication packages that Myth:Auth knows about. By default\nit will return the \"Local Authentication\" library, which is the basic password-based system.\n```php\n    $authenticate = service('authentication');\n```\n    \nYou can specify the library to use as the first argument:\n```php\n    $authenticate = service('authentication', 'jwt');\n```\n\n**authorization**\n\nProvides access to any of the authorization libraries that Myth:Auth knows about. By default\nit will return the \"Flat\" authorization library, which is a Flat RBAC (role-based access control)\nas defined by NIST. It provides user-specific permissions as well as group (role) based permissions.\n```php\n    $authorize = service('authorization');\n```\n\n**passwords**\n\nProvides direct access to the Password validation system. This is an expandable system that currently\nsupports many of [NIST's latest Digital Identity guidelines](https://pages.nist.gov/800-63-3/). The \nvalidator comes with a dictionary of over 620,000 common/leaked passwords that can be checked against.\nA handful of variations on the user's email/username are automatically checked against. \n```php\n    $authenticate = service('passwords');\n```\n\nMost of the time you should not need to access this library directly, though, as a new Validation rule\nis provided that can be used with the Validation library, `strong_password`. In order to enable this, \nyou must first edit **app/Config/Validation.php** and add the new ruleset to the available rule sets:\n```php\n     public $ruleSets = [\n        \\CodeIgniter\\Validation\\Rules::class,\n        \\CodeIgniter\\Validation\\FormatRules::class,\n        \\CodeIgniter\\Validation\\FileRules::class,\n        \\CodeIgniter\\Validation\\CreditCardRules::class,\n        \\Myth\\Auth\\Authentication\\Passwords\\ValidationRules::class,\n    ];\n```\n\nNow you can use `strong_password` in any set of rules for validation:\n```php\n    $validation-\u003esetRules([\n        'username' =\u003e 'required',\n        'password' =\u003e 'required|strong_password'\n    ]);\n```\n\n## Helper Functions\n\nMyth:Auth comes with its own [Helper](https://codeigniter4.github.io/CodeIgniter4/general/helpers.html) \nthat includes the following helper functions to ease access to basic features. Be sure to\nload the helper before using these functions: `helper('auth');`\n\n**Hint**: Add `'auth'` to any controller's `$helper` property to have it loaded automatically,\nor the same in **app/Controllers/BaseController.php** to have it globally available. the\nauth filters all pre-load the helper so it is available on any filtered routes.\n\n**logged_in()**\n\n* Function: Checks to see if any user is logged in.\n* Parameters: None\n* Returns: `true` or `false`\n\n**user()**\n\n* Function: Returns the User instance for the current logged in user.\n* Parameters: None\n* Returns: The current User entity, or `null`\n\n**user_id()**\n\n* Function: Returns the User ID for the current logged in user.\n* Parameters: None\n* Returns: The current User's integer ID, or `null`\n\n**in_groups()**\n\n* Function: Ensures that the current user is in at least one of the passed in groups.\n* Parameters: Group IDs or names, as either a single item or an array of items.\n* Returns: `true` or `false`\n\n**has_permission()**\n\n* Function: Ensures that the current user has at least one of the passed in permissions.\n* Parameters: Permission ID or name.\n* Returns: `true` or `false`\n\n## Users\n\nMyth:Auth uses [CodeIgniter Entities](https://codeigniter4.github.io/CodeIgniter4/models/entities.html) \nfor it's User object, and your application must also use that class. This class\nprovides automatic password hashing as well as utility methods for banning/un-banning, password\nreset hash generation, and more. \n\nIt also provides a UserModel that should be used as it provides methods needed during the \npassword-reset flow, as well as basic validation rules. You are free to extend this class\nor modify it as needed.\n\nThe UserModel can automatically assign a role during user creation. Pass the group name to the \n`withGroup()` method prior to calling `insert()` or `save()` to create a new user and the user \nwill be automatically added to that group.\n```php\n    $user = $userModel\n                -\u003ewithGroup('guests')\n                -\u003einsert($data);\n```\n\nUser registration already handles this for you, and looks to the Auth config file's, `$defaultUserGroup` \nsetting for the name of the group to add the user to. Please, keep in mind that `$defaultUserGroup` variable is not set by default.\n\n### Toolbar\n\nMyth:Auth includes a toolbar collector to make it easy for developers to work with and troubleshoot\nthe authentication process. To enable the collector, edit **app/Config/Toolbar.php** and add it to\nthe list of active collectors:\n\n```php\n\tpublic $collectors = [\n\t\t\\CodeIgniter\\Debug\\Toolbar\\Collectors\\Timers::class,\n\t\t\\CodeIgniter\\Debug\\Toolbar\\Collectors\\Database::class,\n        ...\n\t\t\\Myth\\Auth\\Collectors\\Auth::class,\n\t];\n```\n\n## Restricting by Route\n\nIf you specify each of your routes within the `app/Config/Routes.php` file, you can restrict access\nto users by group/role or permission with [Controller Filters](https://codeigniter4.github.io/CodeIgniter4/incoming/filters.html).\n\nFirst, edit `application/Config/Filters.php` and add the following entries to the `aliases` property:\n\n```php\n    'login'      =\u003e \\Myth\\Auth\\Filters\\LoginFilter::class,\n    'role'       =\u003e \\Myth\\Auth\\Filters\\RoleFilter::class,\n    'permission' =\u003e \\Myth\\Auth\\Filters\\PermissionFilter::class,\n```\n\n**Global restrictions**\n\nThe role and permission filters require additional parameters, but `LoginFilter` can be used to\nrestrict portions of a site (or the entire site) to any authenticated user. If no logged in user is detected\nthen the filter will redirect users to the login form.\n\nRestrict routes based on their URI pattern by editing **app/Config/Filters.php** and adding them to the\n`$filters` array, e.g.:\n\n```php\npublic filters = [\n    'login' =\u003e ['before' =\u003e ['account/*']],\n];\n```\n\nOr restrict your entire site by adding the `LoginFilter` to the `$globals` array:\n```php\n    public $globals = [\n        'before' =\u003e [\n            'honeypot',\n            'login',\n    ...\n```\n\n**Restricting a single route**\n\nAny single route can be restricted by adding the `filter` option to the last parameter in any of the route definition\nmethods:\n\n```php\n$routes-\u003eget('admin/users', 'UserController::index', ['filter' =\u003e 'permission:manage-user'])\n$routes-\u003eget('admin/users', 'UserController::index', ['filter' =\u003e 'role:admin,superadmin'])\n``` \n\nThe filter can be either `role` or `permission`, which restricts the route by either group or permission. \nYou must add a comma-separated list of groups or permissions to check the logged in user against. \n\n**Restricting Route Groups**\n\nIn the same way, entire groups of routes can be restricted within the `group()` method:\n\n```php\n$routes-\u003egroup('admin', ['filter' =\u003e 'role:admin,superadmin'], function($routes) {\n    ...\n});\n```\n\n## Customization\n\nSee the [Extending](docs/extending.md) documentation.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flonnieezell%2Fmyth-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flonnieezell%2Fmyth-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flonnieezell%2Fmyth-auth/lists"}