PHPackages                             samsonasik/mezzio-authentication-with-authorization - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. samsonasik/mezzio-authentication-with-authorization

ActiveProject[Authentication &amp; Authorization](/categories/authentication)

samsonasik/mezzio-authentication-with-authorization
===================================================

Laminas skeleton with authenticaton and authorization example, featuring crsf, flash, prg

13743PHP

Since Sep 3Pushed 4y ago3 watchersCompare

[ Source](https://github.com/samsonasik/mezzio-authentication-with-authorization)[ Packagist](https://packagist.org/packages/samsonasik/mezzio-authentication-with-authorization)[ RSS](/packages/samsonasik-mezzio-authentication-with-authorization/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Mezzio 3 with authentication with authorization
===============================================

[](#mezzio-3-with-authentication-with-authorization)

[![ci build pgsql](https://github.com/samsonasik/mezzio-authentication-with-authorization/workflows/ci%20build%20pgsql/badge.svg)](https://github.com/samsonasik/mezzio-authentication-with-authorization/workflows/ci%20build%20pgsql/badge.svg)[![ci build mysql](https://github.com/samsonasik/mezzio-authentication-with-authorization/workflows/ci%20build%20mysql/badge.svg)](https://github.com/samsonasik/mezzio-authentication-with-authorization/workflows/ci%20build%20mysql/badge.svg)[![Code Coverage](https://camo.githubusercontent.com/843e8dad421c9f6140ac6c6f2a2fa922ba7231c36a3d9814b4ec03d10e798a60/68747470733a2f2f636f6465636f762e696f2f67682f73616d736f6e6173696b2f6d657a7a696f2d61757468656e7469636174696f6e2d776974682d617574686f72697a6174696f6e2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/samsonasik/mezzio-authentication-with-authorization)[![Downloads](https://camo.githubusercontent.com/dab946d20b8503dcc36a8cfaf7902736aa89a45dcb079165cbc68dceb7109a7d/68747470733a2f2f706f7365722e707567782e6f72672f73616d736f6e6173696b2f6d657a7a696f2d61757468656e7469636174696f6e2d776974682d617574686f72697a6174696f6e2f646f776e6c6f616473)](https://packagist.org/packages/samsonasik/mezzio-authentication-with-authorization)

Introduction
------------

[](#introduction)

A Mezzio 3 Skeleton Application with Authentication and Authorization Example.

Features
--------

[](#features)

- Authentication secured with csrf
- Authentication using prg for usability
- Authentication with remember me functionality
- Authentication notification with Session Flash
- Authorization with ACL
- isGranted check in the Layout
- getRole check in the Layout

Install
-------

[](#install)

```
$ composer create-project samsonasik/mezzio-authentication-with-authorization -sdev
$ cd mezzio-authentication-with-authorization
$ cp config/autoload/local.php.dist config/autoload/local.php
```

Configuration
-------------

[](#configuration)

Configure 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.

For PostgreSQL
--------------

[](#for-postgresql)

The 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:

```
$ createdb -Upostgres mezzio
Password:

$ psql -Upostgres mezzio
Password for user postgres:

psql (12.1)
Type "help" for help.

mezzio=# CREATE TABLE users(username character varying(255) PRIMARY KEY NOT NULL, password text NOT NULL, role character varying(255) NOT NULL DEFAULT 'user');
CREATE TABLE

mezzio=# CREATE EXTENSION pgcrypto;
CREATE EXTENSION

mezzio=# INSERT INTO users(username, password, role) VALUES('samsonasik', crypt('123456', gen_salt('bf')), 'user');
INSERT 0 1

mezzio=# INSERT INTO users(username, password, role) VALUES('admin', crypt('123456', gen_salt('bf')), 'admin');
INSERT 0 1
```

and you will get the following data:

[![user data](https://user-images.githubusercontent.com/459648/73605160-567f0a80-45cd-11ea-9e1d-898df2827758.png)](https://user-images.githubusercontent.com/459648/73605160-567f0a80-45cd-11ea-9e1d-898df2827758.png)

For MySQL
---------

[](#for-mysql)

The 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:

```
$ mysql -u root -p -e 'create database mezzio'
Enter password:

$ mysql -u root
Enter password:

mysql> use mezzio
Database changed

mysql> CREATE TABLE users(username varchar(255) PRIMARY KEY NOT NULL, password text NOT NULL, role varchar(255) NOT NULL DEFAULT 'user');
Query OK, 0 rows affected (0.01 sec)

mezzio=# INSERT INTO users(username, password, role) VALUES('samsonasik','$2a$06$Nt2zePoCfApfBGrfZbHZIudIwZpCNqorTjbKNZtPoLCVic8goZDsi', 'user');
Query OK, 1 row affected (0.01 sec)

mezzio=# INSERT INTO users(username, password, role) VALUES('admin', '$2a$06$Y2TtankzyiK/OF1yZA4GsOJBhuoP7o99XbfufEeJ0OOJwjUcPB9LO', 'admin');
Query OK, 1 row affected (0.01 sec)
```

and you will get the following data:

[![user data](https://user-images.githubusercontent.com/459648/74274582-e3039880-4d44-11ea-9caa-e8dc8e81a19f.png)](https://user-images.githubusercontent.com/459648/74274582-e3039880-4d44-11ea-9caa-e8dc8e81a19f.png)

The Authorization Config
------------------------

[](#the-authorization-config)

The authorization configuration saved at `config/autoload/global.php` as ACL:

```
