graychen/yii2-basic-auth

basic auth for yii

v0.0.2 2018-06-22 01:44 UTC

This package is not auto-updated.

Last update: 2024-12-22 06:45:27 UTC


README

Total Downloads Build Status Scrutinizer Code Quality Code Coverage Build Status StyleCI

This is a basic module for app registration. It registers applications through the background and verifies the API in the way of basic authentication (这是一个app注册的基本模块,通过后台注册应用,以基本认证的方式对api进行验证)

Usage

Config Migration

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

Run Migration

$ yii migrate/up

Config backend module in components part

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

after that,you can website https://localhost/admin/app

Add behaviors in your Controller

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,
                    ]);
                }
            ]
        ];
    }