PHP code example of graychen / yii2-basic-auth

1. Go to this page and download the library: Download graychen/yii2-basic-auth library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

graychen / yii2-basic-auth example snippets



'controllerMap' => [
    'migrate' => [
        'class' => 'yii\console\controllers\MigrateController',
        'migrationPath' => [
            '@graychen/yii2/basic/auth/migrations'
        ],
    ],
],


use graychen\yii2\basic\auth\models\App;
use graychen\yii2\basic\auth\filters\HttpBasicAuth;

    public function behaviors()
    {
        return [
            'authenticator' => [
                'class' => HttpBasicAuth::className(),
                'auth' => function ($username, $password) {
                    return App::findOne([
                        'app_key' => $username,
                        'app_secret' => $password,
                    ]);
                }
            ]
        ];
    }
 php

'auth' => [
    'class' => 'graychen\yii2\basic\auth\Module',
]