yii2-basic-auth
, (*1)
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进行验证), (*2)
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
``` php, (*3)
'auth' => [
'class' => 'graychen\yii2\basic\auth\Module',
], (*4)
after that,you can website `https://localhost/admin/app`
## Add behaviors in your Controller
```php
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,
]);
}
]
];
}