xin / auth
基于ThinkPHP8的用户身份验证和登录库,为应用程序提供安全的用户认证服务
Installs: 12
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
pkg:composer/xin/auth
Requires
- php: >=7.1.9
- firebase/php-jwt: ^6.11
- xin/capsule: ^1.0
- xin/support: ^1.0
README
介绍
应用程序为其用户提供了一种通过应用程序进行身份验证和登录的方法
安装教程
composer require xin/auth
使用说明
配置文件
<?php return [ /* |-------------------------------------------------------------------------- | Authentication Defaults |-------------------------------------------------------------------------- | | This option controls the default authentication "guard" and password | reset options for your application. You may change these defaults | as required, but they're a perfect start for most applications. | */ 'defaults' => [ 'guard' => 'user', ], /* |-------------------------------------------------------------------------- | Authentication Guards |-------------------------------------------------------------------------- | | Next, you may define every authentication guard for your application. | Of course, a great default configuration has been defined for you | here which uses session storage and the Eloquent user provider. | | All authentication drivers have a user provider. This defines how the | users are actually retrieved out of your database or other storage | mechanisms used by this application to persist your user's data. | | Supported: "session", "token", "token_session" | */ 'guards' => [ 'api' => [ 'driver' => 'token_session', 'provider' => 'user', ], 'user' => [ 'driver' => 'session', 'provider' => 'user', 'auth_url' => '/index/login/login', ], 'admin' => [ 'driver' => 'session', 'provider' => 'admin', 'administrator_id' => 1, 'auth_url' => '/admin/login/login', ], ], /* |-------------------------------------------------------------------------- | User Providers |-------------------------------------------------------------------------- | | All authentication drivers have a user provider. This defines how the | users are actually retrieved out of your database or other storage | mechanisms used by this application to persist your user's data. | | If you have multiple user tables or models you may configure multiple | sources which represent each model / table. These sources may then | be assigned to any extra authentication guards you have defined. | | Supported: "database", "model" | */ 'providers' => [ 'user' => [ 'driver' => 'model', 'model' => \app\common\model\User::class, ], 'admin' => [ 'driver' => 'model', 'model' => \app\admin\model\Admin::class, ], ], ];
实例化认证器
<?php $authManager = new \Xin\Auth\AuthManager($config); $authManager->loginUsingId(1); $authManager->login(User::find(1)); $authManager->loginUsingCredential(['username'=>'admin']); $authManager->check(); $authManager->guest(); $authManager->getUser(); $authManager->getUserId(); $authManager->user(); $authManager->isAdministrator(); $authManager->temporaryUser(); $authManager->extend('api',function ($config){ return new class() implements \Xin\Auth\Auth\Guard{ } });