{"id":15307570,"url":"https://github.com/samsonasik/mezzio-authentication-with-authorization","last_synced_at":"2025-04-15T00:31:32.869Z","repository":{"id":42474501,"uuid":"235338174","full_name":"samsonasik/mezzio-authentication-with-authorization","owner":"samsonasik","description":"mezzio authentication with ACL authorization  demo","archived":false,"fork":false,"pushed_at":"2021-11-19T21:43:57.000Z","size":827,"stargazers_count":12,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T12:38:41.173Z","etag":null,"topics":["acl","authentication","authorization","login","mezzio","php","remember-me","session"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/samsonasik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"custom":"https://samsonasik.wordpress.com/donate/"}},"created_at":"2020-01-21T12:32:28.000Z","updated_at":"2024-01-21T12:11:35.000Z","dependencies_parsed_at":"2022-09-13T15:02:56.413Z","dependency_job_id":null,"html_url":"https://github.com/samsonasik/mezzio-authentication-with-authorization","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samsonasik%2Fmezzio-authentication-with-authorization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samsonasik%2Fmezzio-authentication-with-authorization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samsonasik%2Fmezzio-authentication-with-authorization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samsonasik%2Fmezzio-authentication-with-authorization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samsonasik","download_url":"https://codeload.github.com/samsonasik/mezzio-authentication-with-authorization/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248984279,"owners_count":21193717,"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":["acl","authentication","authorization","login","mezzio","php","remember-me","session"],"created_at":"2024-10-01T08:10:41.578Z","updated_at":"2025-04-15T00:31:32.236Z","avatar_url":"https://github.com/samsonasik.png","language":"PHP","funding_links":["https://samsonasik.wordpress.com/donate/"],"categories":[],"sub_categories":[],"readme":"# Mezzio 3 with authentication with authorization\n\n![ci build pgsql](https://github.com/samsonasik/mezzio-authentication-with-authorization/workflows/ci%20build%20pgsql/badge.svg)\n![ci build mysql](https://github.com/samsonasik/mezzio-authentication-with-authorization/workflows/ci%20build%20mysql/badge.svg)\n[![Code Coverage](https://codecov.io/gh/samsonasik/mezzio-authentication-with-authorization/branch/master/graph/badge.svg)](https://codecov.io/gh/samsonasik/mezzio-authentication-with-authorization)\n[![Downloads](https://poser.pugx.org/samsonasik/mezzio-authentication-with-authorization/downloads)](https://packagist.org/packages/samsonasik/mezzio-authentication-with-authorization)\n\nIntroduction\n------------\n\nA Mezzio 3 Skeleton Application with Authentication and Authorization Example.\n\nFeatures\n--------\n\n- Authentication secured with csrf\n- Authentication using prg for usability\n- Authentication with remember me functionality\n- Authentication notification with Session Flash\n- Authorization with ACL\n- isGranted check in the Layout\n- getRole check in the Layout\n\nInstall\n-------\n\n```bash\n$ composer create-project samsonasik/mezzio-authentication-with-authorization -sdev\n$ cd mezzio-authentication-with-authorization\n$ cp config/autoload/local.php.dist config/autoload/local.php\n```\n\nConfiguration\n-------------\n\nConfigure your `config/autoload/local.php` with your local DB config with username and password field. There are examples of `dsn` for both `PostgreSQL` and `MySQL` that you can modify.\n\nFor PostgreSQL\n--------------\n\nThe following commands are example if you are using PostgreSQL (assumption using user \"postgres\" and create db named \"mezzio\"), you can create users table with insert username and bcrypt hashed password with pgcrypto extension into users table:\n\n```sql\n$ createdb -Upostgres mezzio\nPassword:\n\n$ psql -Upostgres mezzio\nPassword for user postgres:\n\npsql (12.1)\nType \"help\" for help.\n\nmezzio=# CREATE TABLE users(username character varying(255) PRIMARY KEY NOT NULL, password text NOT NULL, role character varying(255) NOT NULL DEFAULT 'user');\nCREATE TABLE\n\nmezzio=# CREATE EXTENSION pgcrypto;\nCREATE EXTENSION\n\nmezzio=# INSERT INTO users(username, password, role) VALUES('samsonasik', crypt('123456', gen_salt('bf')), 'user');\nINSERT 0 1\n\nmezzio=# INSERT INTO users(username, password, role) VALUES('admin', crypt('123456', gen_salt('bf')), 'admin');\nINSERT 0 1\n```\n\nand you will get the following data:\n\n![user data](https://user-images.githubusercontent.com/459648/73605160-567f0a80-45cd-11ea-9e1d-898df2827758.png)\n\nFor MySQL\n--------------\n\nThe following commands are example if you are using MySQL (assumption using user \"root\" and create db named \"mezzio\"), you can create users table with insert username and bcrypt hashed password:\n\n```sql\n$ mysql -u root -p -e 'create database mezzio'\nEnter password:\n\n$ mysql -u root\nEnter password:\n\nmysql\u003e use mezzio\nDatabase changed\n\nmysql\u003e CREATE TABLE users(username varchar(255) PRIMARY KEY NOT NULL, password text NOT NULL, role varchar(255) NOT NULL DEFAULT 'user');\nQuery OK, 0 rows affected (0.01 sec)\n\nmezzio=# INSERT INTO users(username, password, role) VALUES('samsonasik','$2a$06$Nt2zePoCfApfBGrfZbHZIudIwZpCNqorTjbKNZtPoLCVic8goZDsi', 'user');\nQuery OK, 1 row affected (0.01 sec)\n\nmezzio=# INSERT INTO users(username, password, role) VALUES('admin', '$2a$06$Y2TtankzyiK/OF1yZA4GsOJBhuoP7o99XbfufEeJ0OOJwjUcPB9LO', 'admin');\nQuery OK, 1 row affected (0.01 sec)\n```\n\nand you will get the following data:\n\n![user data](https://user-images.githubusercontent.com/459648/74274582-e3039880-4d44-11ea-9caa-e8dc8e81a19f.png)\n\nThe Authorization Config\n------------------------\n\nThe authorization configuration saved at `config/autoload/global.php` as ACL:\n\n```php\n\u003c?php\n\n// config/autoload/global.php\n\ndeclare(strict_types=1);\n\nreturn [\n    // ...\n    'mezzio-authorization-acl' =\u003e [\n        'roles'     =\u003e [\n            'guest' =\u003e [],\n            'user'  =\u003e ['guest'],\n            'admin' =\u003e ['user'],\n        ],\n        'resources' =\u003e [\n            'api.ping.view',\n            'home.view',\n            'admin.view',\n            'login.form',\n            'logout.access',\n        ],\n        'allow'     =\u003e [\n            'guest' =\u003e [\n                'login.form',\n                'api.ping.view',\n            ],\n            'user'  =\u003e [\n                'logout.access',\n                'home.view',\n            ],\n            'admin' =\u003e [\n                'admin.view',\n            ],\n        ],\n    ],\n    // ...\n];\n```\n\nRunning\n-------\n\n1. Clear browser cache\n2. Run the php -S command:\n\n```php\n$ php -S localhost:8080 -t public\n```\n\n3. Open browser: http://localhost:8080\n\n4. Login with username : samsonasik, password: 123456 OR username : admin, password : 123456. If you're a logged in user with \"user\" role, and open `/admin` page, it will show like the following (403 Forbidden), eg: see in [Firefox developer tools](https://developer.mozilla.org/en-US/docs/Tools/Network_Monitor) under \"Network\" monitor:\n\n![authorized-user-cannot-access-admin-page](https://user-images.githubusercontent.com/459648/73605169-73b3d900-45cd-11ea-9085-3c2bc5e9d966.png)\n\nTest\n----\n\nTests are located under `test` directory, you can run test with composer command:\n\n```bash\n$ composer test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamsonasik%2Fmezzio-authentication-with-authorization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamsonasik%2Fmezzio-authentication-with-authorization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamsonasik%2Fmezzio-authentication-with-authorization/lists"}