hyperf-ext/auth: The Hyperf Auth package.
安装
composer require hyperf-ext/auth
发布配置文件
php bin/hyperf.php vendor:publish hyperf-ext/auth
composer require hyperf-ext/hashing
php bin/hyperf.php vendor:publish hyperf-ext/hashing
composer require hyperf-ext/jwt
php bin/hyperf.php vendor:publish hyperf-ext/jwt
添加 Auth 守护 guard
php
<?php
declare(strict_types=1);
return [
'default' => [
'guard' => 'api', // 默认接口api守护
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => \HyperfExt\Auth\Guards\SessionGuard::class,
'provider' => 'users',
'options' => [],
],
// 接口api守护
'api' => [
'driver' => \HyperfExt\Auth\Guards\JwtGuard::class,
'provider' => 'api',
'options' => [],
],
// 管理端admin守护
'admin' => [
'driver' => \HyperfExt\Auth\Guards\JwtGuard::class,
'provider' => 'admin',
'options' => [],
],
],
'providers' => [
'api' => [
'driver' => \HyperfExt\Auth\UserProviders\ModelUserProvider::class,
'options' => [
'model' => \App\Model\User::class, // 用户模型
'hash_driver' => 'bcrypt',
],
],
'admin' => [
'driver' => \HyperfExt\Auth\UserProviders\ModelUserProvider::class,
'options' => [
'model' => \App\Model\Admin::class, // 管理员模型
'hash_driver' => 'bcrypt',
],
]
],
'passwords' => [
'users' => [
'driver' => \HyperfExt\Auth\Passwords\DatabaseTokenRepository::class,
'provider' => 'users',
'options' => [
'connection' => null,
'table' => 'password_resets',
'expire' => 3600,
'throttle' => 60,
'hash_driver' => null,
],
],
],
'password_timeout' => 10800,
'policies' => [
//Model::class => Policy::class,
],
];