hyperf auth模块

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,
    ],
];
相关推荐
GetcharZp3 小时前
GitHub 49K+ Star!C++ 开发者必知的 JSON 神级库:从零到精通全指北
后端
xujinwei_gingko3 小时前
SpringBoot整合WebSocket
spring boot·后端·websocket
智码看视界3 小时前
现代Web开发基础:全栈工程师的起航点
前端·后端·c5全栈
程序员cxuan3 小时前
Claude Fable 5 来了
人工智能·后端·程序员
JS菌3 小时前
手写一个 AI Agent 全栈项目:从沙箱执行到子智能体的完整实现
前端·人工智能·后端
wang09074 小时前
自己动手写一个spring之IOC_2
java·后端·spring
ltl4 小时前
推理退化:为什么大模型会输出乱码、死循环和无意义文本
后端
ltl4 小时前
架构视图与文档:C4 模型从入门到实战
后端
IT_陈寒7 小时前
Redis持久化这个坑,我爬了一整天才出来
前端·人工智能·后端
无风听海7 小时前
多租户系统中的 OIDC:Discovery 端点与联合登录的深度实践
后端·python·flask