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,
    ],
];
相关推荐
忧郁的Mr.Li4 小时前
SpringBoot中实现多数据源配置
java·spring boot·后端
JSON_L4 小时前
Fastadmin中使用GatewayClient
php·fastadmin
青茶3604 小时前
php怎么实现订单接口状态轮询请求
前端·javascript·php
暮色妖娆丶4 小时前
SpringBoot 启动流程源码分析 ~ 它其实不复杂
spring boot·后端·spring
Coder_Boy_5 小时前
Deeplearning4j+ Spring Boot 电商用户复购预测案例中相关概念
java·人工智能·spring boot·后端·spring
Java后端的Ai之路5 小时前
【Spring全家桶】-一文弄懂Spring Cloud Gateway
java·后端·spring cloud·gateway
野犬寒鸦5 小时前
从零起步学习并发编程 || 第七章:ThreadLocal深层解析及常见问题解决方案
java·服务器·开发语言·jvm·后端·学习
Honmaple6 小时前
OpenClaw 实战经验总结
后端
golang学习记6 小时前
Go 嵌入结构体方法访问全解析:从基础到进阶陷阱
后端
NAGNIP6 小时前
程序员效率翻倍的快捷键大全!
前端·后端·程序员