4spacesdk/ci4authextension
Composer 安装命令:
composer require 4spacesdk/ci4authextension
包简介
Easy OAuth2 integration with CodeIgniter 4
README 文档
README
Installation
Step 1)
composer require 4spacesdk/ci4authextension
Step 2)
Create new file app/Config/AuthExtension.php and add this content
<?php namespace Config; use CodeIgniter\Config\BaseConfig; class AuthExtension extends BaseConfig { /* * Specify the database group */ public string $dbGroupName = 'default'; /* * If true, AuthExtension will extend routes with default endpoints * Check CI4AuthExtension/Hooks/PreController.php for details */ public bool $autoRoute = true; /* * OAuth Access token lifetime in seconds */ public int $oauthAccessTokenLifeTime = 15 * MINUTE; /* * OAuth Access token lifetime in seconds */ public int $oauthRefreshTokenLifeTime = 7 * DAY; /* * Path to login page */ public string $loginPage = '/login'; }
Step 3)
Add this line to your application/Config/Events.php file
Events::on('pre_system', [\AuthExtension\Hooks\PreController::class, 'execute']); Events::on('pre_command', [\AuthExtension\Hooks\PreController::class, 'execute']);
Step 4)
Add migration file and add this line to up(): \AuthExtension\Migration\Setup::migrateUp(); and this line to down(): \AuthExtension\Migration\Setup::migrateDown();.
Step 5)
Seed new users, ex:
$user = new User(); $user->first_name = 'Firstname'; $user->last_name = 'Lastname'; $user->username = 'some@email.com'; $user->password = password_hash('secret password', PASSWORD_BCRYPT); $user->save();
Step 6)
Add a controller and view for simple username/password login.
You can either use your own check login algorithm or use $loginResponse = AuthExtension::login($username, $password); which will return one of these constants and set user_id in session storage.
class LoginResponse { const Success = 'Success'; const RenewPassword = 'RenewPassword'; const WrongPassword = 'WrongPassword'; const UnknownUser = 'UnknownUser'; }
Authorize with session
$user = AuthExtension::checkSession();
$user is either FALSE or the authorized User.
Authorize with OAuth2
If you enable autoRoute in Config you can authorize by calling /check with access_token as query parameter or header.
Check AuthExtension\Hooks\PreController for more routes.
4spacesdk/ci4authextension 适用场景与选型建议
4spacesdk/ci4authextension 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.92k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2019 年 07 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 4spacesdk/ci4authextension 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 4spacesdk/ci4authextension 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.92k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-07-15