# php-auth **Repository Path**: liuxiaojinla/php-auth ## Basic Information - **Project Name**: php-auth - **Description**: 应用程序为其用户提供了一种通过应用程序进行身份验证和登录的方法 - **Primary Language**: PHP - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-05-08 - **Last Updated**: 2025-03-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Auth | 用户认证 #### 介绍 应用程序为其用户提供了一种通过应用程序进行身份验证和登录的方法 #### 安装教程 `composer require xin/auth` #### 使用说明 **配置文件** ```php [ '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 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{ } }); ``` #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request #### 特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md