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,
    ],
];
相关推荐
Best-Wishes5 小时前
科来网络分析系统(技术交流版)使用说明书
开发语言·junit·php
行百里er6 小时前
Redis 完结篇——Redis 热点问题在 Spring Boot 项目中实战
redis·后端
高频因子挖掘机7 小时前
只取最近 60 个交易日,却每次拉全历史:量化脚本变慢的原因与改法
后端·github·api
爱上网的小舟7 小时前
星际战士2启动错误怎么办?5种游戏报错解决方法
开发语言·php
孟健8 小时前
从5000亿Token到83%字节匹配:AI逆向工程与重构的工程闭环实践
后端·架构·ai编程
码事漫谈9 小时前
丢得静悄悄,谈一谈 Agent 的记忆是怎么没的
后端
迪飞特科技9 小时前
智慧物业平台实战:Spring Boot 整合小程序实现报修巡检费用全流程
spring boot·后端·小程序
考虑考虑9 小时前
@JsonInclude注解使用
spring boot·后端·spring
IT_陈寒9 小时前
Vite的这个问题坑了我三天,原来如此解决!
前端·人工智能·后端
网易云信9 小时前
大模型能上岗做销售吗?我们让 12 款国产模型交了 420 份作业
前端·后端