baka/auth
Composer 安装命令:
composer require baka/auth
包简介
Baka Component for user authentification
README 文档
README
MC Auth Library to avoid having to redo a user signup flow for apps.
Testing
codecept run
JWT
Add JWT to your configuration
'jwt' => [ 'secretKey' => getenv('JWT_SECURITY_HASH'), 'expirationTime' => '1 hour', #strtotime 'payload' => [ 'exp' => 1440, 'iss' => 'phalcon-jwt-auth', ], 'ignoreUri' => [ 'regex:auth', 'regex:webhook', 'regex:/users', ], ],
Database
We use phinx for migration , to update this project db structure just run
vendor/bin/phinx-migrations generate
To run this migration from your project just add the path of the db location to your phinx.php path
<?php
return [
'paths' => [
'migrations' => [
getenv('PHINX_CONFIG_DIR') . '/db/migrations',
'/home/baka/auth/db/migrations',
],
vendor/bin/phinx migrate -e (enviorment : development | production)
Using
Add this to your service.php
/** * UserData dependency injection for the system * * @return Session */ $di->set('userData', function () use ($config, $auth) { $data = $auth->data(); $session = new Baka\Auth\Models\Sessions(); $request = new Phalcon\Http\Request(); if (!empty($data) && !empty($data['sessionId'])) { //user if (!$user = Baka\Auth\Models\Users::getByEmail($data['email'])) { throw new Exception('User not found'); } return $session->check($user, $data['sessionId'], $request->getClientAddress(), 1); } else { throw new Exception('User not found'); } });
Generate migration files
$ phalcon migration --action=run --migrations=migrations --config=</path/to/config.php>
Import migration into project
$ phalcon migration --action=run --migrations=vendor/baka/auth/migrations/
Router
$router->post('/auth', [ '\Your\NameSpace\AuthController', 'login', ]); $router->post('/auth/signup', [ '\Your\NameSpace\AuthController', 'signup', ]); $router->post('/auth/logout', [ '\Your\NameSpace\AuthController', 'logout', ]); # get email for new password $router->post('/auth/recover', [ '\Your\NameSpace\AuthController', 'recover', ]); # update new password $router->put('/auth/{key}/reset', [ '\Your\NameSpace\AuthController', 'reset', ]); # active the account $router->put('/auth/{key}/activate', [ '\Your\NameSpace\AuthController', 'activate', ]);
Social logins
"hybridauth/hybridauth": "dev-3.0.0-Remake",
<?php 'social_config' => [ // required "callback" => getenv('SOCIAL_CONNECT_URL'), // required "providers" => [ "Facebook" => [ "enabled" => true, "callback" => getenv('SOCIAL_CONNECT_URL').'/Facebook', "keys" => ["id" => getenv('FB_ID'), "secret" => getenv('FB_SECRET')], //production ] ], ],
And configure the links and callback link (SOCIAL_CONNECT_URL) to http://site.com/users/social/{site} Example: http://site.com/users/social/Facebook
You need to add this to your registration process to idenfity social login
{% if socialConnect %}
<input type="hidden" name="socialConnect" value="1">
{% endif %}
baka/auth 适用场景与选型建议
baka/auth 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.9k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 10 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 baka/auth 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 baka/auth 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 7.9k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-28