yii2-http-basic-auth Http basic auth for Yii2 project

  1. Installation
  2. Usage
  3. Resources

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require skeeks/yii2-http-basic-auth "*"

or add

"skeeks/yii2-http-basic-auth": "*"

Usage

//App config
'on beforeRequest' => function ($event) {
    \Yii::$app->httpBasicAuth->verify();
},

'components' =>
[
    'httpBasicAuth' =>
    [
        'class'             => 'skeeks\yii2\httpBasicAuth\HttpBasicAuthComponent',
        'login'             => 'login',
        'password'          => 'password',
        'usePasswordHash'   => false,                               //optionality
        'viewFail'          => '@app/views/http-basic-auth-fail'    //optionality
    ],

]
'on beforeRequest' => function ($event) {
    //For example in addition to close the admin panel http authorization
    if (\Yii::$app->admin->requestIsAdmin)
    {
        \Yii::$app->httpBasicAuth->verify();
    }
},

'components' =>
[
    'httpBasicAuth' =>
    [
        'class'             => 'skeeks\yii2\httpBasicAuth\HttpBasicAuthComponent',
        'login'             => 'login',
        'password'          => 'password',
    ],

]

Resources

0 1
2 followers
0 downloads
Yii Version: 2.0
License: GPL-3.0
Category: Security
Developed by: skeeks
Created on: Apr 17, 2016
Last updated: 2 years ago

Related Extensions