cfs/authenticator
Composer 安装命令:
composer require cfs/authenticator
包简介
This package extends auraphp/Aura.Auth (https://github.com/auraphp/Aura.Auth) by adding a custom LDAP adapter for the NRCan's LDAP / Active Directory setup.
README 文档
README
Cfs Authenticator
This package extends auraphp/Aura.Auth (https://github.com/auraphp/Aura.Auth) by adding a custom LDAP adapter for the NRCan's LDAP / Active Directory setup.
Demo Code:
<?php
require_once './vendor/autoload.php';
function ebr($var) {
echo $var.'<br>';
}
function eprebr($var) {
if( is_array($var) ) {
$var = print_r($var, true);
}
echo "<pre>$var</pre>";
}
function dumpAuthinfo($auth) {
ebr($auth->getFirstActive());
ebr($auth->getLastActive());
ebr($auth->getStatus());
ebr($auth->getUserName());
eprebr($auth->getUserData());
}
//session_save_path('/var/www/html/rotimi/cfs-authenticator/ignore/');
$auth_factory = new \Aura\Auth\AuthFactory($_COOKIE);
$auth = $auth_factory->newInstance();
$server = 'ldap.server.org.ca';
$dnformat = 'ou=Company Name,dc=Department Name,cn=users';
$cfs_ldap_adapter_specific_params = array(
'filter' => '\w',
'basedn' => 'DC=yada,DC=yada,DC=yada,DC=yada',
'bindpw' => 'Pa$$w0rd',
'limit' => array('dn'),
'searchfilter' => 'somefilter',
'successful_login_callback' => function($login_timestamp_string) {
echo $login_timestamp_string.'<br>';
}
);
$custom_adapter = new \Cfs\Authenticator\Adapter\CfsLdapAdapter(
new \Aura\Auth\Phpfunc(),
$server,
$dnformat,
array(),
$cfs_ldap_adapter_specific_params
);
$login_service = $auth_factory->newLoginService($custom_adapter);
$logout_service = $auth_factory->newLogoutService($custom_adapter);
$resume_service = $auth_factory->newResumeService($custom_adapter);
////////////////////////////////////////////////////////////////////
// LOGIN SERVICE DEMO
////////////////////////////////////////////////////////////////////
try {
$login_service->login($auth, array(
'username' => 'a_username',
'password' => 'a_password'
));
ebr( "You are now logged into a new session.");
dumpAuthinfo($auth);
} catch (\Aura\Auth\Exception\UsernameMissing $e) {
ebr("The 'username' field is missing or empty.");
throw new \Exception();
} catch (\Aura\Auth\Exception\PasswordMissing $e) {
ebr("The 'password' field is missing or empty.");
throw new \Exception();
} catch (\Aura\Auth\Exception\UsernameNotFound $e) {
ebr("The username you entered was not found.");
throw new \Exception();
} catch (\Aura\Auth\Exception\MultipleMatches $e) {
ebr("There is more than one account with that username.");
throw new \Exception();
} catch (\Aura\Auth\Exception\PasswordIncorrect $e) {
ebr("The password you entered was incorrect.");
throw new \Exception();
} catch (\Aura\Auth\Exception\ConnectionFailed $e) {
ebr("Cound not connect to IMAP or LDAP server.");
ebr("This could be because the username or password was wrong,");
ebr("or because the the connect operation itself failed in some way. ");
ebr($e->getMessage());
throw new \Exception();
} catch (\Aura\Auth\Exception\BindFailed $e) {
ebr("Cound not bind to LDAP server.");
ebr("This could be because the username or password was wrong,");
ebr("or because the the bind operation itself failed in some way. ");
ebr($e->getMessage());
throw new \Exception();
} catch (\Exception $e) {
echo "Invalid login details. Please try again.";
}
////////////////////////////////////////////////////////////////////
// RESUME SERVICE DEMO
////////////////////////////////////////////////////////////////////
sleep(3);//sleep for 3 seconds
$resume_service->resume($auth);
ebr('');//print line break
switch (true) {
case $auth->isAnon():
echo "You are not logged in.";
break;
case $auth->isIdle():
echo "Your session was idle for too long. Please log in again.";
break;
case $auth->isExpired():
echo "Your session has expired. Please log in again.";
break;
case $auth->isValid():
echo "You are still logged in.";
break;
default:
echo "You have an unknown status.";
break;
}
ebr('');//print line break
dumpAuthinfo($auth);
////////////////////////////////////////////////////////////////////
// LOGOUT SERVICE DEMO
////////////////////////////////////////////////////////////////////
$logout_service->logout($auth);
ebr('');//print line break
if ($auth->isAnon()) {
echo "You are now logged out.";
} else {
echo "Something went wrong; you are still logged in.";
}
ebr('');//print line break
dumpAuthinfo($auth);
?>
See https://github.com/auraphp/Aura.Auth/blob/2.x/README.md for more examples on how to use this package.
cfs/authenticator 适用场景与选型建议
cfs/authenticator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 47 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 09 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Authentication」 「auth」 「authenticate」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cfs/authenticator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cfs/authenticator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cfs/authenticator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A simple Cake3 plugin to authenticate users with Cookies.
Laravel Multiauth package
CakePHP plugin that performs Remember-me authentication with the new cookie algorithm of version 3.5 or later
Automatically logs-in users if they are already authenticated by a remote source. (e.g. environment variable REMOTE_USER)
GraphQL authentication for your headless Craft CMS applications.
Google Authentication in Laravel
统计信息
- 总下载量: 47
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-2-Clause
- 更新时间: 2015-09-10