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,
    ],
];
相关推荐
Dragon Wu1 天前
Spring Security Oauth2.1 授权码模式实现前后端分离的方案
java·spring boot·后端·spring cloud·springboot·springcloud
一个有梦有戏的人1 天前
Python3基础:进阶基础,筑牢编程底层能力
后端·python
爬山算法1 天前
Hibernate(88)如何在负载测试中使用Hibernate?
java·后端·hibernate
独断万古他化1 天前
【Spring 原理】Bean 的作用域与生命周期
java·后端·spring
我爱加班、、1 天前
Websocket能携带token过去后端吗
前端·后端·websocket
一 乐1 天前
校园二手交易|基于springboot + vue校园二手交易系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端
80530单词突击赢1 天前
SpringBoot整合SpringMVC全解析
java·spring boot·后端
hdsoft_huge1 天前
1panel面板中部署SpringBoot和Vue前后端分离系统 【图文教程】
vue.js·spring boot·后端
lekami_兰1 天前
RabbitMQ 延迟队列实现指南:两种方案手把手教你搞定
后端·rabbitmq·延迟队列
ThatITs1 天前
【无标题】
php