typo3 - 将 Azure AD 中的 TYPO3 fe_users 与 SAML 2 连接的最佳方式是什么?
问题描述
我需要在 TYPO3 Intranet 上实现 SSO,其中 fe_users 从 Azure AD 同步。该平台将在 V9 中。有没有我还没有找到的兼容扩展?如果不是,使用 SAML 2.0 实现自动身份验证的最佳方式是什么?在此先感谢,雷切尔
解决方案
感谢@Rakel(和其他人),我终于设法解决了我的 SAML 身份验证要求。我仍然使用了一种稍微不同且更直接的方法,然后在她的解决方案中进行了描述。
我使用身份验证服务来实现 SAML 登录过程。为了处理 SAML 登录本身,我使用了SimpleSamlPHP库,我真的可以推荐它。它非常简单,并且提供的用于测试 SAML 配置的前端对于在不处理 TYPO3 的情况下测试身份提供者 (Idp) 配置非常方便。
有关详细信息,请查看:https ://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Authentication/Index.html
首先,您需要创建一个扩展 TYPO3\CMS\Core\Authentication\AuthenticationService的类。此类必须实现方法"getUser"和"authUser"。
namespace Vendor\Extension\Service;
use SimpleSAML\Auth\Simple;
use TYPO3\CMS\Core\Authentication\AuthenticationService;
class SamlAuth extends AuthenticationService
{
public function getUser() {
// Create new Simple Auth with SimpleSamlPHP
$as = new Simple($config['sp']);
// Require authentication, this redirects you to the Idp and then comes back
$as->requireAuth();
// Get the attributes provides by your Idp
$attributes = $as->getAttributes();
// Please consult the API for details on fetchUserRecord
// Also the SAML attributes may vary depending on your Idp implementation
$user = $this->fetchUserRecord($attributes['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name'];
}
public function authUser(array $user): int {
return is_array($user) ? 200 : 0;
}
}
然后你需要在你的扩展“ext_localconf.php”中注册服务。
...
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addService(
'my_extension',
'auth',
Vendor\Extension\Service\SamlAuth::class,
[
'title' => 'Saml Authentication for Frontend Users',
'description' => 'Authenticates FeUsers via Saml',
'subtype' => 'authUserFE,getUserFE',
'available' => true,
'priority' => 80,
'quality' => 80,
'os' => '',
'exec' => '',
'className' => Vendor\Extension\Service\SamlAuth::class
]
);
...
请注意:
- 这只是我最终代码的过度简化版本。只是为了让你开始这个想法。
- 您还需要正确配置 SimpleSamlPHP。有关详细信息,请查看他们的文档。
方法“getUser”应该返回一个数组,其中包含要登录的 FeUser 及其所有参数。
方法“authUser”仅返回 200 或 0。查看此链接以了解返回的数字:https ://docs.typo3.org/m/typo3/reference-services/7.6/en- us/Authentication/Index.html#authentication-service-chain 返回“200”后,创建 FeUser 对象并登录用户。无需自己摆弄 $GLOBALS['TSFE']。这是一个巨大的好处,因为它使您的代码更短且更易于阅读。
尽管如此,我通过阅读此处和 Slacks TYPO3 频道的所有文档和回复中学到了很多东西。感谢所有帮助过我的人。非常感激。
推荐阅读
- python - 如何从一些 python 脚本中调用函数,这些函数的名称可以在另一个 python 脚本中更改?
- python - 可以直接将 xpath 复制并粘贴到漂亮的汤解析器中,还是必须对其进行修改?
- php - Issue in using multiple databases in laravel 5.2
- javascript - 如何使用leaflet.js(附截图)实现以下地图功能?
- bash - 如何在 Linux 中循环访问变量值?
- rxjs - Rxjs:执行代码并在 Observable 完成时发出值
- javascript - 在 Javascript 中更新数组元素
- python - 如何根据条件解释过滤行?
- bash - 在 bash 文件中使用带有 shell 扩展的 grep 和 awk,引用转义问题
- python - 会话未提交 - 结帐 12b - 烧瓶 Web 开发