yii2-nginx-auth

yii/

Basic yii app with module yii2-nginx-auth installed

nginx/

Nginx server installed and configured with ngx_http_auth_request_module

installation/

Through Composer From console:

composer require macfly/yii2-nginx-auth

or add to "require" section to composer.json

"macfly/yii2-nginx-auth": "*"

config/

Configure config/web.php as follows

  'modules' => [
     ................
    'nginx'  => [
      'class' => 'macfly\nginxauth\Module',
    ],
    ................
  ],

To set the token on cookie config/web.php as follows

  'user' => [
     ................
     'on afterLogin' => ['macfly\nginxauth\events\NginxAuthEvent', 'setTokenOnCookie'],
     'on afterLogout' => ['macfly\nginxauth\events\NginxAuthEvent', 'unsetTokenOnCookie'],
     ................
   ],

src/

Source of yii2-nginx-auth module

You can run a test env with :

git clone https://github.com/Marty-Macfly/yii2-nginx-auth.git
cd yii2-nginx-auth/yii/
composer update
cd ..
docker-compose build
docker-compose up