graychen / yii2-basic-auth
basic auth for yii
Installs: 1 390
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- ramsey/uuid: ^3.7
- yiisoft/yii2: *
Requires (Dev)
- phpunit/phpunit: ^7.2
This package is not auto-updated.
Last update: 2024-12-22 06:45:27 UTC
README
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, ]); } ] ]; }